-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(NODE-3528): add support for snappy v7 #2947
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#! /usr/bin/env bash | ||
|
||
export PATH="/opt/mongodbtoolchain/v2/bin:$PATH" | ||
NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts" | ||
export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm" | ||
|
||
if [[ "$OS" == "Windows_NT" ]]; then | ||
NVM_HOME=$(cygpath -w "$NVM_DIR") | ||
export NVM_HOME | ||
NVM_SYMLINK=$(cygpath -w "$NODE_ARTIFACTS_PATH/bin") | ||
export NVM_SYMLINK | ||
NVM_ARTIFACTS_PATH=$(cygpath -w "$NODE_ARTIFACTS_PATH/bin") | ||
export NVM_ARTIFACTS_PATH | ||
PATH=$(cygpath $NVM_SYMLINK):$(cygpath $NVM_HOME):$PATH | ||
export PATH | ||
echo "updated path on windows PATH=$PATH" | ||
else | ||
[ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#! /usr/bin/env bash | ||
|
||
source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" | ||
export MONGODB_URI="${MONGODB_URI}" | ||
|
||
npm i --no-save snappy@6 | ||
|
||
npx mocha test/unit/snappy.test.js | ||
|
||
npm i --no-save snappy@7 | ||
|
||
npx mocha test/unit/snappy.test.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
'use strict'; | ||
|
||
const parsePackageVersion = require('../../utils').parsePackageVersion; | ||
const MongoError = require('../error').MongoError; | ||
|
||
const require_optional = require('optional-require')(require); | ||
|
||
function debugOptions(debugFields, options) { | ||
|
@@ -16,7 +19,15 @@ function retrieveBSON() { | |
BSON.native = false; | ||
|
||
const optionalBSON = require_optional('bson-ext'); | ||
const bsonExtVersion = parsePackageVersion( | ||
require_optional('bson-ext/package.json') || { version: '0.0.0' } | ||
); | ||
if (optionalBSON) { | ||
if (bsonExtVersion.major >= 4) { | ||
throw new MongoError( | ||
'bson-ext version 4 and above does not work with the 3.x version of the mongodb driver' | ||
); | ||
} | ||
optionalBSON.native = true; | ||
return optionalBSON; | ||
} | ||
|
@@ -31,21 +42,43 @@ function noSnappyWarning() { | |
); | ||
} | ||
|
||
const PKG_VERSION = Symbol('kPkgVersion'); | ||
|
||
// Facilitate loading Snappy optionally | ||
function retrieveSnappy() { | ||
let snappy = require_optional('snappy'); | ||
const snappy = require_optional('snappy'); | ||
if (!snappy) { | ||
snappy = { | ||
return { | ||
compress: noSnappyWarning, | ||
uncompress: noSnappyWarning, | ||
compressSync: noSnappyWarning, | ||
uncompressSync: noSnappyWarning | ||
}; | ||
} | ||
|
||
const snappyPkg = require_optional('snappy/package.json') || { version: '0.0.0' }; | ||
const version = parsePackageVersion(snappyPkg); | ||
snappy[PKG_VERSION] = version; | ||
if (version.major >= 7) { | ||
const compressOriginal = snappy.compress; | ||
const uncompressOriginal = snappy.uncompress; | ||
snappy.compress = (data, callback) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Slightly different approach taken, just wrap the functions here, the actual usage site needs no changes now. |
||
compressOriginal(data) | ||
.then(res => callback(undefined, res)) | ||
.catch(error => callback(error)); | ||
}; | ||
snappy.uncompress = (data, callback) => { | ||
uncompressOriginal(data) | ||
.then(res => callback(undefined, res)) | ||
.catch(error => callback(error)); | ||
}; | ||
} | ||
|
||
return snappy; | ||
} | ||
|
||
module.exports = { | ||
PKG_VERSION, | ||
debugOptions, | ||
retrieveBSON, | ||
retrieveSnappy | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ported over the CI changes, I actually took a stab at bringing in the bson-ext CI here too, but it started having too much overhead for this PR, but this sets us up to have easier one-off targets going forward.