harperdb 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -11
- package/bin/BinObjects.jsc +0 -0
- package/bin/harperdb.jsc +0 -0
- package/bin/install.jsc +0 -0
- package/bin/register.jsc +0 -0
- package/bin/run.jsc +0 -0
- package/bin/stop.jsc +0 -0
- package/bin/upgrade.jsc +0 -0
- package/bin/utility.jsc +0 -0
- package/bin/version.jsc +0 -0
- package/coverage/lcov.info +6624 -6141
- package/data_layer/CreateAttributeObject.jsc +0 -0
- package/data_layer/CreateTableObject.jsc +0 -0
- package/data_layer/DataLayerObjects.jsc +0 -0
- package/data_layer/DeleteBeforeObject.jsc +0 -0
- package/data_layer/DeleteObject.jsc +0 -0
- package/data_layer/DropAttributeObject.jsc +0 -0
- package/data_layer/InsertObject.jsc +0 -0
- package/data_layer/ReadTransactionLogObject.jsc +0 -0
- package/data_layer/SQLSearch.jsc +0 -0
- package/data_layer/SearchByConditionsObject.jsc +0 -0
- package/data_layer/SearchByHashObject.jsc +0 -0
- package/data_layer/SearchObject.jsc +0 -0
- package/data_layer/SqlSearchObject.jsc +0 -0
- package/data_layer/UpdateObject.jsc +0 -0
- package/data_layer/UpsertObject.jsc +0 -0
- package/data_layer/bulkLoad.jsc +0 -0
- package/data_layer/data_objects/BulkLoadObjects.jsc +0 -0
- package/data_layer/data_objects/UpsertObject.jsc +0 -0
- package/data_layer/delete.jsc +0 -0
- package/data_layer/export.jsc +0 -0
- package/data_layer/harperBridge/BridgeMethods.jsc +0 -0
- package/data_layer/harperBridge/bridgeUtility/checkForNewAttr.jsc +0 -0
- package/data_layer/harperBridge/bridgeUtility/convertOperationToTransaction.jsc +0 -0
- package/data_layer/harperBridge/bridgeUtility/evaluateTableGetAttributes.jsc +0 -0
- package/data_layer/harperBridge/bridgeUtility/insertUpdateReturnObj.jsc +0 -0
- package/data_layer/harperBridge/bridgeUtility/insertUpdateValidate.jsc +0 -0
- package/data_layer/harperBridge/harperBridge.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/LMDBBridge.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/DeleteTransactionsBeforeResults.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateAttribute.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateRecords.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateSchema.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateTable.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteRecords.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteRecordsBefore.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteTransactionLogsBefore.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropAttribute.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropSchema.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropTable.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetDataByHash.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetDataByValue.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbReadTransactionLog.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByConditions.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByHash.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByValue.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpdateRecords.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpsertRecords.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/LMDBCreateAttributeObject.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/LMDBDeleteTransactionObject.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/LMDBInsertTransactionObject.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/LMDBTransactionObject.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/LMDBUpdateTransactionObject.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/LMDBUpsertTransactionObject.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/TableSizeObject.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/ThreadSearchObject.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/initializeHashSearch.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/initializePaths.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbCheckForNewAttributes.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbCreateTransactionsEnvironment.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbDropAllAttributes.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbGetTableSize.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbProcessRows.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbSearch.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbThreadSearch.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbWriteTransaction.jsc +0 -0
- package/data_layer/hdbInfoController.jsc +0 -0
- package/data_layer/insert.jsc +0 -0
- package/data_layer/readTransactionLog.jsc +0 -0
- package/data_layer/schema.jsc +0 -0
- package/data_layer/schemaDescribe.jsc +0 -0
- package/data_layer/search.jsc +0 -0
- package/data_layer/update.jsc +0 -0
- package/events/ClusterStatusEmitter.jsc +0 -0
- package/events/SioServerStoppedEvent.jsc +0 -0
- package/events/SocketClusterStatusEmitter.jsc +0 -0
- package/license/LICENSE +91 -1
- package/node_modules/@msgpackr-extract/msgpackr-extract-linux-x64/README.md +1 -0
- package/node_modules/{node-addon-api/src/nothing.c → @msgpackr-extract/msgpackr-extract-linux-x64/index.js} +0 -0
- package/node_modules/@msgpackr-extract/msgpackr-extract-linux-x64/node.abi93.glibc.node +0 -0
- package/node_modules/@msgpackr-extract/msgpackr-extract-linux-x64/node.abi93.musl.node +0 -0
- package/node_modules/@msgpackr-extract/msgpackr-extract-linux-x64/node.napi.glibc.node +0 -0
- package/node_modules/@msgpackr-extract/msgpackr-extract-linux-x64/node.napi.musl.node +0 -0
- package/node_modules/@msgpackr-extract/msgpackr-extract-linux-x64/package.json +53 -0
- package/node_modules/{msgpackr-extract → lmdb-store}/.github/workflows/prebuild.yml +9 -10
- package/node_modules/lmdb-store/.idea/lmdb-store.iml +12 -0
- package/node_modules/lmdb-store/.idea/misc.xml +6 -0
- package/node_modules/lmdb-store/.idea/modules.xml +8 -0
- package/node_modules/lmdb-store/.idea/workspace.xml +4 -0
- package/node_modules/lmdb-store/README.md +393 -388
- package/node_modules/lmdb-store/benchmark/index.js +162 -162
- package/node_modules/lmdb-store/binding.gyp +79 -88
- package/node_modules/lmdb-store/caching.js +113 -113
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/COPYRIGHT +20 -20
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/Doxyfile +1631 -1631
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/LICENSE +47 -47
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/chacha8.c +183 -183
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/chacha8.h +14 -14
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/crypto.c +121 -121
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/intro.doc +192 -192
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb.c +12125 -12125
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_copy.1 +74 -74
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_copy.c +106 -106
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_drop.1 +53 -53
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_drop.c +154 -154
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_dump.1 +94 -94
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_dump.c +333 -333
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_load.1 +97 -97
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_load.c +530 -530
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_stat.1 +83 -83
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_stat.c +276 -276
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/midl.c +452 -452
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/midl.h +208 -208
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/module.c +101 -101
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/module.h +16 -16
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest.c +178 -178
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest2.c +124 -124
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest3.c +133 -133
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest4.c +168 -168
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest5.c +135 -135
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest6.c +141 -141
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest_enc.c +190 -190
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest_enc2.c +189 -189
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest_remap.c +177 -177
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/sample-bdb.txt +73 -73
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/sample-mdb.txt +62 -62
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/tooltag +27 -27
- package/node_modules/lmdb-store/dependencies/lz4/LICENSE +11 -11
- package/node_modules/lmdb-store/dependencies/lz4/lib/README.md +137 -137
- package/node_modules/lmdb-store/dependencies/lz4/lib/dll/example/README.md +69 -69
- package/node_modules/lmdb-store/dependencies/lz4/lib/lz4frame.c +1899 -1899
- package/node_modules/lmdb-store/dependencies/lz4/lib/xxhash.c +1030 -1030
- package/node_modules/lmdb-store/dependencies/lz4/lib/xxhash.h +328 -328
- package/node_modules/lmdb-store/dist/index.cjs +2591 -0
- package/node_modules/lmdb-store/dist/index.cjs.map +1 -0
- package/node_modules/lmdb-store/index.d.ts +323 -323
- package/node_modules/lmdb-store/index.js +1274 -1274
- package/node_modules/lmdb-store/index.mjs +3 -3
- package/node_modules/lmdb-store/package.json +16 -11
- package/node_modules/lmdb-store/prebuilds/darwin-arm64/electron.abi98.node +0 -0
- package/node_modules/lmdb-store/prebuilds/darwin-arm64/node.abi83.node +0 -0
- package/node_modules/lmdb-store/prebuilds/darwin-arm64/node.abi93.node +0 -0
- package/node_modules/lmdb-store/prebuilds/darwin-x64/electron.abi98.node +0 -0
- package/node_modules/lmdb-store/prebuilds/darwin-x64/node.abi83.node +0 -0
- package/node_modules/lmdb-store/prebuilds/darwin-x64/node.abi93.node +0 -0
- package/node_modules/lmdb-store/prebuilds/linux-arm64/electron.abi98.node +0 -0
- package/node_modules/lmdb-store/prebuilds/linux-arm64/node.abi83.node +0 -0
- package/node_modules/lmdb-store/prebuilds/linux-arm64/node.abi93.node +0 -0
- package/node_modules/lmdb-store/prebuilds/linux-x64/electron.abi98.node +0 -0
- package/node_modules/lmdb-store/prebuilds/linux-x64/node.abi83.musl.node +0 -0
- package/node_modules/lmdb-store/prebuilds/linux-x64/node.abi83.node +0 -0
- package/node_modules/lmdb-store/prebuilds/linux-x64/node.abi93.musl.node +0 -0
- package/node_modules/lmdb-store/prebuilds/linux-x64/node.abi93.node +0 -0
- package/node_modules/lmdb-store/prebuilds/win32-x64/electron.abi98.node +0 -0
- package/node_modules/lmdb-store/prebuilds/win32-x64/node.abi83.node +0 -0
- package/node_modules/lmdb-store/prebuilds/win32-x64/node.abi93.node +0 -0
- package/node_modules/lmdb-store/src/compression.cpp +181 -181
- package/node_modules/lmdb-store/src/cursor.cpp +407 -407
- package/node_modules/lmdb-store/src/dbi.cpp +354 -354
- package/node_modules/lmdb-store/src/env.cpp +1134 -1134
- package/node_modules/lmdb-store/src/misc.cpp +528 -528
- package/node_modules/lmdb-store/src/node-lmdb.cpp +44 -44
- package/node_modules/lmdb-store/src/node-lmdb.h +965 -965
- package/node_modules/lmdb-store/src/ordered-binary.cpp +337 -337
- package/node_modules/lmdb-store/src/txn.cpp +513 -513
- package/node_modules/lmdb-store/src/v8-fast-api-calls.h +419 -419
- package/node_modules/lmdb-store/src/windows.c +30 -30
- package/node_modules/lmdb-store/test/index.test.js +584 -584
- package/node_modules/lmdb-store/test/node-lmdb.test.js +1525 -1525
- package/node_modules/lmdb-store/test/threads.js +100 -100
- package/node_modules/lmdb-store/util/ArrayLikeIterable.js +136 -136
- package/node_modules/lmdb-store/util/WeakValueMap.js +40 -40
- package/node_modules/lmdb-store/util/upgrade-lmdb.js +46 -46
- package/node_modules/lmdb-store/util/when.js +8 -8
- package/node_modules/microtime/.github/workflows/release.yml +76 -0
- package/node_modules/microtime/.github/workflows/test.yml +46 -0
- package/node_modules/microtime/README.md +0 -2
- package/node_modules/microtime/binding.gyp +28 -10
- package/node_modules/microtime/package.json +25 -20
- package/node_modules/microtime/prebuilds/darwin-x64+arm64/electron.napi.node +0 -0
- package/node_modules/microtime/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
- package/node_modules/microtime/prebuilds/linux-arm/node.napi.armv7.node +0 -0
- package/node_modules/microtime/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
- package/node_modules/microtime/prebuilds/linux-x64/electron.napi.node +0 -0
- package/node_modules/microtime/prebuilds/linux-x64/node.napi.node +0 -0
- package/node_modules/microtime/prebuilds/win32-ia32/electron.napi.node +0 -0
- package/node_modules/microtime/prebuilds/win32-ia32/node.napi.node +0 -0
- package/node_modules/microtime/prebuilds/win32-x64/electron.napi.node +0 -0
- package/node_modules/microtime/prebuilds/win32-x64/node.napi.node +0 -0
- package/node_modules/msgpackr/dist/index.js +1929 -1917
- package/node_modules/msgpackr/dist/index.min.js +67 -68
- package/node_modules/msgpackr/dist/node.cjs +1994 -1980
- package/node_modules/msgpackr/dist/test.js +683 -1235
- package/node_modules/msgpackr/index.d.ts +23 -12
- package/node_modules/msgpackr/node-index.js +23 -21
- package/node_modules/msgpackr/pack.js +935 -931
- package/node_modules/msgpackr/package.json +24 -12
- package/node_modules/msgpackr/unpack.d.ts +52 -50
- package/node_modules/msgpackr/unpack.js +1061 -1053
- package/node_modules/msgpackr-extract/bin/download-prebuilds.js +11 -0
- package/node_modules/msgpackr-extract/binding.gyp +22 -5
- package/node_modules/msgpackr-extract/index.js +1 -1
- package/node_modules/msgpackr-extract/package.json +46 -21
- package/node_modules/msgpackr-extract/src/.vs/ProjectSettings.json +3 -0
- package/node_modules/msgpackr-extract/src/.vs/VSWorkspaceState.json +7 -0
- package/node_modules/msgpackr-extract/src/.vs/slnx.sqlite +0 -0
- package/node_modules/msgpackr-extract/src/.vs/src/v16/.suo +0 -0
- package/node_modules/msgpackr-extract/src/.vs/src/v16/Browse.VC.db +0 -0
- package/node_modules/msgpackr-extract/{prebuilds/darwin-x64/node.abi72.node → src/.vs/src/v16/Browse.VC.db-shm} +0 -0
- package/node_modules/msgpackr-extract/src/.vs/src/v16/Browse.VC.db-wal +0 -0
- package/node_modules/msgpackr-extract/src/extract.cpp +272 -269
- package/node_modules/nan/package.json +0 -1
- package/node_modules/node-addon-api/README.md +146 -53
- package/node_modules/node-addon-api/common.gypi +21 -0
- package/node_modules/node-addon-api/except.gypi +25 -0
- package/node_modules/node-addon-api/index.js +7 -41
- package/node_modules/node-addon-api/napi-inl.deprecated.h +8 -8
- package/node_modules/node-addon-api/napi-inl.h +2795 -633
- package/node_modules/node-addon-api/napi.h +1547 -597
- package/node_modules/node-addon-api/node_api.gyp +9 -0
- package/node_modules/node-addon-api/noexcept.gypi +26 -0
- package/node_modules/node-addon-api/nothing.c +0 -0
- package/node_modules/node-addon-api/package-support.json +21 -0
- package/node_modules/node-addon-api/package.json +203 -13
- package/node_modules/node-addon-api/tools/README.md +12 -6
- package/node_modules/node-addon-api/tools/clang-format.js +71 -0
- package/node_modules/node-addon-api/tools/conversion.js +4 -8
- package/node_modules/node-addon-api/tools/eslint-format.js +71 -0
- package/node_modules/node-gyp-build/README.md +17 -14
- package/node_modules/node-gyp-build/bin.js +28 -15
- package/node_modules/node-gyp-build/index.js +145 -34
- package/node_modules/node-gyp-build/package.json +18 -15
- package/node_modules/{lmdb-store/node_modules/node-gyp-build → node-gyp-build-optional-packages}/LICENSE +0 -0
- package/node_modules/{lmdb-store/node_modules/node-gyp-build → node-gyp-build-optional-packages}/README.md +0 -0
- package/node_modules/{lmdb-store/node_modules/node-gyp-build → node-gyp-build-optional-packages}/bin.js +1 -1
- package/node_modules/{lmdb-store/node_modules/node-gyp-build → node-gyp-build-optional-packages}/build-test.js +0 -0
- package/node_modules/{lmdb-store/node_modules/node-gyp-build → node-gyp-build-optional-packages}/index.js +17 -11
- package/node_modules/{lmdb-store/node_modules/node-gyp-build → node-gyp-build-optional-packages}/optional.js +0 -0
- package/node_modules/{msgpackr-extract/node_modules/node-gyp-build → node-gyp-build-optional-packages}/package.json +17 -17
- package/package.json +12 -11
- package/security/JWTObjects.jsc +0 -0
- package/security/auth.jsc +0 -0
- package/security/cryptoHash.jsc +0 -0
- package/security/data_objects/PermissionAttributeResponseObject.jsc +0 -0
- package/security/data_objects/PermissionResponseObject.jsc +0 -0
- package/security/data_objects/PermissionTableResponseObject.jsc +0 -0
- package/security/permissionsTranslator.jsc +0 -0
- package/security/role.jsc +0 -0
- package/security/tokenAuthentication.jsc +0 -0
- package/security/user.jsc +0 -0
- package/server/ClusteringOriginObject.jsc +0 -0
- package/server/JobObject.jsc +0 -0
- package/server/clustering/ClusterStatusObject.jsc +0 -0
- package/server/clustering/NodeObject.jsc +0 -0
- package/server/clustering/clusterUtilities.jsc +0 -0
- package/server/configuration.jsc +0 -0
- package/server/customFunctions/customFunctionsServer.jsc +0 -0
- package/server/customFunctions/helpers/getCORSOptions.jsc +0 -0
- package/server/customFunctions/helpers/getHeaderTimeoutConfig.jsc +0 -0
- package/server/customFunctions/helpers/getServerOptions.jsc +0 -0
- package/server/customFunctions/operations.jsc +0 -0
- package/server/customFunctions/operationsValidation.jsc +0 -0
- package/server/harperdb/hdbServer.jsc +0 -0
- package/server/ipc/IPCClient.jsc +0 -0
- package/server/ipc/hdbIpcServer.jsc +0 -0
- package/server/ipc/serverHandlers.jsc +0 -0
- package/server/ipc/utility/IPCEventObject.jsc +0 -0
- package/server/ipc/utility/ipcUtils.jsc +0 -0
- package/server/jobRunner.jsc +0 -0
- package/server/jobThread.jsc +0 -0
- package/server/jobs.jsc +0 -0
- package/server/serverHelpers/OperationFunctionObject.jsc +0 -0
- package/server/serverHelpers/requestTimePlugin.jsc +0 -0
- package/server/serverHelpers/serverHandlers.jsc +0 -0
- package/server/serverHelpers/serverUtilities.jsc +0 -0
- package/server/socketcluster/Server.jsc +0 -0
- package/server/socketcluster/broker.jsc +0 -0
- package/server/socketcluster/connector/HDBSocketConnector.jsc +0 -0
- package/server/socketcluster/connector/InterNodeSocketConnector.jsc +0 -0
- package/server/socketcluster/connector/SocketConnector.jsc +0 -0
- package/server/socketcluster/connector/spawnSCConnection.jsc +0 -0
- package/server/socketcluster/decisionMatrix/CoreDecisionMatrix.jsc +0 -0
- package/server/socketcluster/decisionMatrix/DecisionMatrixIF.jsc +0 -0
- package/server/socketcluster/decisionMatrix/rules/AssignToHdbChildWorkerRule.jsc +0 -0
- package/server/socketcluster/decisionMatrix/rules/CallRoomMsgHandlerRule.jsc +0 -0
- package/server/socketcluster/decisionMatrix/rules/CleanDataObjectRule.jsc +0 -0
- package/server/socketcluster/decisionMatrix/rules/CommandCollection.jsc +0 -0
- package/server/socketcluster/decisionMatrix/rules/DummyRule.jsc +0 -0
- package/server/socketcluster/decisionMatrix/rules/RulesIF.jsc +0 -0
- package/server/socketcluster/decisionMatrix/rules/StripHdbHeaderRule.jsc +0 -0
- package/server/socketcluster/decisionMatrix/rules/TestRule.jsc +0 -0
- package/server/socketcluster/handlers/NodeConnectionsHandler.jsc +0 -0
- package/server/socketcluster/handlers/SCServer.jsc +0 -0
- package/server/socketcluster/handlers/ServerSocket.jsc +0 -0
- package/server/socketcluster/interNodeConnectionLauncher.jsc +0 -0
- package/server/socketcluster/messageQueue/MessageQueueIF.jsc +0 -0
- package/server/socketcluster/middleware/AuthMiddleware.jsc +0 -0
- package/server/socketcluster/middleware/ConnectionNameCheckMiddleware.jsc +0 -0
- package/server/socketcluster/middleware/GenericMiddleware.jsc +0 -0
- package/server/socketcluster/middleware/MessagePrepMiddleware.jsc +0 -0
- package/server/socketcluster/middleware/MiddlewareFactory.jsc +0 -0
- package/server/socketcluster/middleware/MiddlewareIF.jsc +0 -0
- package/server/socketcluster/middleware/OriginatorCheckMiddleware.jsc +0 -0
- package/server/socketcluster/middleware/RequestDataValidMiddleware.jsc +0 -0
- package/server/socketcluster/middleware/StampOriginatorMiddleware.jsc +0 -0
- package/server/socketcluster/middleware/StampRequestMiddleware.jsc +0 -0
- package/server/socketcluster/observer/EventableIF.jsc +0 -0
- package/server/socketcluster/room/AddUserRoom.jsc +0 -0
- package/server/socketcluster/room/AlterUserRoom.jsc +0 -0
- package/server/socketcluster/room/CoreRoom.jsc +0 -0
- package/server/socketcluster/room/CreateAttributeRoom.jsc +0 -0
- package/server/socketcluster/room/CreateSchemaRoom.jsc +0 -0
- package/server/socketcluster/room/CreateTableRoom.jsc +0 -0
- package/server/socketcluster/room/DropUserRoom.jsc +0 -0
- package/server/socketcluster/room/HDBNodeRoom.jsc +0 -0
- package/server/socketcluster/room/RoomIF.jsc +0 -0
- package/server/socketcluster/room/RoomMessageObjects.jsc +0 -0
- package/server/socketcluster/room/UsersRoom.jsc +0 -0
- package/server/socketcluster/room/WatchHDBWorkersRoom.jsc +0 -0
- package/server/socketcluster/room/WorkerRoom.jsc +0 -0
- package/server/socketcluster/room/roomFactory.jsc +0 -0
- package/server/socketcluster/socketClusterObjects.jsc +0 -0
- package/server/socketcluster/types.jsc +0 -0
- package/server/socketcluster/util/clusterData.jsc +0 -0
- package/server/socketcluster/util/socketClusterUtils.jsc +0 -0
- package/server/socketcluster/worker/ClusterWorker.jsc +0 -0
- package/server/socketcluster/worker/WorkerIF.jsc +0 -0
- package/server/socketcluster/worker/WorkerObjects.jsc +0 -0
- package/server/transactToClusteringUtilities.jsc +0 -0
- package/sqlTranslator/SelectValidator.jsc +0 -0
- package/sqlTranslator/alasqlFunctionImporter.jsc +0 -0
- package/sqlTranslator/conditionPatterns.jsc +0 -0
- package/sqlTranslator/deleteTranslator.jsc +0 -0
- package/sqlTranslator/index.jsc +0 -0
- package/sqlTranslator/sql_statement_bucket.jsc +0 -0
- package/upgrade/EnvironmentVariable.jsc +0 -0
- package/upgrade/UpgradeDirective.jsc +0 -0
- package/upgrade/UpgradeObjects.jsc +0 -0
- package/upgrade/directives/3-0-0.jsc +0 -0
- package/upgrade/directives/3-1-0.jsc +0 -0
- package/upgrade/directives/directivesController.jsc +0 -0
- package/upgrade/directives/upgrade_scripts/3_0_0_reindex_script.jsc +0 -0
- package/upgrade/directivesManager.jsc +0 -0
- package/upgrade/lmdb/nodeLMDB/DBIDefinition.jsc +0 -0
- package/upgrade/lmdb/nodeLMDB/OpenDBIObject.jsc +0 -0
- package/upgrade/lmdb/nodeLMDB/OpenEnvironmentObject.jsc +0 -0
- package/upgrade/lmdb/nodeLMDB/commonErrors.jsc +0 -0
- package/upgrade/lmdb/nodeLMDB/commonUtility.jsc +0 -0
- package/upgrade/lmdb/nodeLMDB/environmentUtility.jsc +0 -0
- package/upgrade/lmdb/nodeLMDB/terms.jsc +0 -0
- package/upgrade/upgradePrompt.jsc +0 -0
- package/upgrade/upgradeUtilities.jsc +0 -0
- package/utility/AWS/AWSConnector.jsc +0 -0
- package/utility/OperationFunctionCaller.jsc +0 -0
- package/utility/common_utils.jsc +0 -0
- package/utility/environment/SystemInformationObject.jsc +0 -0
- package/utility/environment/SystemInformationOperation.jsc +0 -0
- package/utility/environment/environmentManager.jsc +0 -0
- package/utility/environment/systemInformation.jsc +0 -0
- package/utility/errors/commonErrors.jsc +0 -0
- package/utility/errors/hdbError.jsc +0 -0
- package/utility/functions/date/dateFunctions.jsc +0 -0
- package/utility/functions/geo.jsc +0 -0
- package/utility/functions/math/avg.jsc +0 -0
- package/utility/functions/math/count.jsc +0 -0
- package/utility/functions/sql/alaSQLExtension.jsc +0 -0
- package/utility/functions/string/compare.jsc +0 -0
- package/utility/globalSchema.jsc +0 -0
- package/utility/hdbTerms.jsc +0 -0
- package/utility/install/checkJWTTokensExist.jsc +0 -0
- package/utility/install/installer.jsc +0 -0
- package/utility/install_user_permission.jsc +0 -0
- package/utility/lmdb/DBIDefinition.jsc +0 -0
- package/utility/lmdb/DeleteRecordsResponseObject.jsc +0 -0
- package/utility/lmdb/InsertRecordsResponseObject.jsc +0 -0
- package/utility/lmdb/OpenDBIObject.jsc +0 -0
- package/utility/lmdb/OpenEnvironmentObject.jsc +0 -0
- package/utility/lmdb/UpdateRecordsResponseObject.jsc +0 -0
- package/utility/lmdb/UpsertRecordsResponseObject.jsc +0 -0
- package/utility/lmdb/cleanLMDBMap.jsc +0 -0
- package/utility/lmdb/commonUtility.jsc +0 -0
- package/utility/lmdb/deleteUtility.jsc +0 -0
- package/utility/lmdb/environmentUtility.jsc +0 -0
- package/utility/lmdb/searchCursorFunctions.jsc +0 -0
- package/utility/lmdb/searchUtility.jsc +0 -0
- package/utility/lmdb/terms.jsc +0 -0
- package/utility/lmdb/writeUtility.jsc +0 -0
- package/utility/logging/harper_logger.jsc +0 -0
- package/utility/mount_hdb.jsc +0 -0
- package/utility/npmUtilities.jsc +0 -0
- package/utility/operation_authorization.jsc +0 -0
- package/utility/password.jsc +0 -0
- package/utility/pm2/servicesConfig.jsc +0 -0
- package/utility/pm2/utilityFunctions.jsc +0 -0
- package/utility/psList.jsc +0 -0
- package/utility/registration/hdb_license.jsc +0 -0
- package/utility/registration/licenseObjects.jsc +0 -0
- package/utility/registration/registrationHandler.jsc +0 -0
- package/utility/scripts/restartHdb.jsc +0 -0
- package/utility/signalling.jsc +0 -0
- package/utility/system_info.jsc +0 -0
- package/validation/bulkDeleteValidator.jsc +0 -0
- package/validation/check_permissions.jsc +0 -0
- package/validation/clustering/configureValidator.jsc +0 -0
- package/validation/common_validators.jsc +0 -0
- package/validation/conditionalDeleteValidator.jsc +0 -0
- package/validation/deleteValidator.jsc +0 -0
- package/validation/fileLoadValidator.jsc +0 -0
- package/validation/insertValidator.jsc +0 -0
- package/validation/nodeSubscriptionValidator.jsc +0 -0
- package/validation/nodeValidator.jsc +0 -0
- package/validation/readLogValidator.jsc +0 -0
- package/validation/registration/license_key_object.jsc +0 -0
- package/validation/role_validation.jsc +0 -0
- package/validation/schemaMetadataValidator.jsc +0 -0
- package/validation/schema_validator.jsc +0 -0
- package/validation/searchValidator.jsc +0 -0
- package/validation/user_validation.jsc +0 -0
- package/validation/validationWrapper.jsc +0 -0
- package/node_modules/lmdb-store/build/Makefile +0 -324
- package/node_modules/lmdb-store/build/Release/.deps/Release/lmdb-store.node.d +0 -1
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/dependencies/lmdb/libraries/liblmdb/chacha8.o.d +0 -6
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb.o.d +0 -8
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/dependencies/lmdb/libraries/liblmdb/midl.o.d +0 -8
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/dependencies/lz4/lib/lz4.o.d +0 -5
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/compression.o.d +0 -72
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/cursor.o.d +0 -73
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/dbi.o.d +0 -73
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/env.o.d +0 -73
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/misc.o.d +0 -73
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/node-lmdb.o.d +0 -73
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/ordered-binary.o.d +0 -73
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/txn.o.d +0 -73
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/windows.o.d +0 -3
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store.node.d +0 -1
- package/node_modules/lmdb-store/build/Release/lmdb-store.node +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/dependencies/lmdb/libraries/liblmdb/chacha8.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/dependencies/lmdb/libraries/liblmdb/midl.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/dependencies/lz4/lib/lz4.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/compression.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/cursor.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/dbi.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/env.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/misc.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/node-lmdb.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/ordered-binary.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/txn.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/windows.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store.node +0 -0
- package/node_modules/lmdb-store/build/binding.Makefile +0 -6
- package/node_modules/lmdb-store/build/config.gypi +0 -426
- package/node_modules/lmdb-store/build/lmdb-store.target.mk +0 -206
- package/node_modules/lmdb-store/node_modules/node-gyp-build/package.json +0 -60
- package/node_modules/lmdb-store/prebuilds/darwin-x64/electron.abi87.node +0 -0
- package/node_modules/lmdb-store/prebuilds/darwin-x64/node.abi72.node +0 -0
- package/node_modules/lmdb-store/prebuilds/darwin-x64/node.abi88.node +0 -0
- package/node_modules/lmdb-store/prebuilds/win32-x64/electron.abi87.node +0 -0
- package/node_modules/lmdb-store/prebuilds/win32-x64/node.abi72.node +0 -0
- package/node_modules/lmdb-store/prebuilds/win32-x64/node.abi88.node +0 -0
- package/node_modules/microtime/prebuilds/darwin-x64/electron-napi.node +0 -0
- package/node_modules/microtime/prebuilds/darwin-x64/node-napi.node +0 -0
- package/node_modules/microtime/prebuilds/linux-arm/electron-napi.node +0 -0
- package/node_modules/microtime/prebuilds/linux-arm/node-napi.node +0 -0
- package/node_modules/microtime/prebuilds/linux-x64/electron-napi.node +0 -0
- package/node_modules/microtime/prebuilds/linux-x64/node-napi.node +0 -0
- package/node_modules/microtime/prebuilds/win32-x64/electron-napi.node +0 -0
- package/node_modules/microtime/prebuilds/win32-x64/node-napi.node +0 -0
- package/node_modules/msgpackr-extract/.circleci/config.yml +0 -19
- package/node_modules/msgpackr-extract/.travis.yml +0 -30
- package/node_modules/msgpackr-extract/node_modules/node-gyp-build/LICENSE +0 -21
- package/node_modules/msgpackr-extract/node_modules/node-gyp-build/README.md +0 -58
- package/node_modules/msgpackr-extract/node_modules/node-gyp-build/bin.js +0 -77
- package/node_modules/msgpackr-extract/node_modules/node-gyp-build/build-test.js +0 -19
- package/node_modules/msgpackr-extract/node_modules/node-gyp-build/index.js +0 -202
- package/node_modules/msgpackr-extract/node_modules/node-gyp-build/optional.js +0 -7
- package/node_modules/msgpackr-extract/prebuilds/darwin-arm64/electron.abi98.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/darwin-arm64/node.abi102.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/darwin-arm64/node.abi83.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/darwin-arm64/node.abi93.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/darwin-x64/electron.abi98.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/darwin-x64/node.abi102.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/darwin-x64/node.abi83.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/darwin-x64/node.abi88.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/darwin-x64/node.abi93.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-arm64/electron.abi98.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-arm64/node.abi102.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-arm64/node.abi83.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-arm64/node.abi93.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-x64/electron.abi98.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi102.musl.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi102.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi72.musl.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi72.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi83.musl.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi83.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi88.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi93.musl.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi93.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/win32-x64/electron.abi98.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/win32-x64/node.abi102.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/win32-x64/node.abi72.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/win32-x64/node.abi83.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/win32-x64/node.abi88.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/win32-x64/node.abi93.node +0 -0
- package/node_modules/node-addon-api/.editorconfig +0 -8
- package/node_modules/node-addon-api/.travis.yml +0 -65
- package/node_modules/node-addon-api/CHANGELOG.md +0 -325
- package/node_modules/node-addon-api/CODE_OF_CONDUCT.md +0 -4
- package/node_modules/node-addon-api/CONTRIBUTING.md +0 -66
- package/node_modules/node-addon-api/appveyor.yml +0 -48
- package/node_modules/node-addon-api/doc/Doxyfile +0 -2450
- package/node_modules/node-addon-api/doc/array_buffer.md +0 -129
- package/node_modules/node-addon-api/doc/async_context.md +0 -76
- package/node_modules/node-addon-api/doc/async_operations.md +0 -31
- package/node_modules/node-addon-api/doc/async_worker.md +0 -397
- package/node_modules/node-addon-api/doc/basic_types.md +0 -415
- package/node_modules/node-addon-api/doc/bigint.md +0 -92
- package/node_modules/node-addon-api/doc/boolean.md +0 -64
- package/node_modules/node-addon-api/doc/buffer.md +0 -140
- package/node_modules/node-addon-api/doc/callback_scope.md +0 -54
- package/node_modules/node-addon-api/doc/callbackinfo.md +0 -97
- package/node_modules/node-addon-api/doc/checker-tool.md +0 -32
- package/node_modules/node-addon-api/doc/class_property_descriptor.md +0 -118
- package/node_modules/node-addon-api/doc/cmake-js.md +0 -19
- package/node_modules/node-addon-api/doc/conversion-tool.md +0 -28
- package/node_modules/node-addon-api/doc/creating_a_release.md +0 -62
- package/node_modules/node-addon-api/doc/dataview.md +0 -244
- package/node_modules/node-addon-api/doc/env.md +0 -63
- package/node_modules/node-addon-api/doc/error.md +0 -115
- package/node_modules/node-addon-api/doc/error_handling.md +0 -186
- package/node_modules/node-addon-api/doc/escapable_handle_scope.md +0 -82
- package/node_modules/node-addon-api/doc/external.md +0 -59
- package/node_modules/node-addon-api/doc/function.md +0 -294
- package/node_modules/node-addon-api/doc/function_reference.md +0 -238
- package/node_modules/node-addon-api/doc/generator.md +0 -13
- package/node_modules/node-addon-api/doc/handle_scope.md +0 -65
- package/node_modules/node-addon-api/doc/memory_management.md +0 -27
- package/node_modules/node-addon-api/doc/node-gyp.md +0 -82
- package/node_modules/node-addon-api/doc/number.md +0 -163
- package/node_modules/node-addon-api/doc/object.md +0 -202
- package/node_modules/node-addon-api/doc/object_lifetime_management.md +0 -83
- package/node_modules/node-addon-api/doc/object_reference.md +0 -117
- package/node_modules/node-addon-api/doc/object_wrap.md +0 -546
- package/node_modules/node-addon-api/doc/prebuild_tools.md +0 -16
- package/node_modules/node-addon-api/doc/promises.md +0 -74
- package/node_modules/node-addon-api/doc/property_descriptor.md +0 -231
- package/node_modules/node-addon-api/doc/range_error.md +0 -59
- package/node_modules/node-addon-api/doc/reference.md +0 -111
- package/node_modules/node-addon-api/doc/setup.md +0 -82
- package/node_modules/node-addon-api/doc/string.md +0 -89
- package/node_modules/node-addon-api/doc/symbol.md +0 -44
- package/node_modules/node-addon-api/doc/threadsafe_function.md +0 -303
- package/node_modules/node-addon-api/doc/type_error.md +0 -59
- package/node_modules/node-addon-api/doc/typed_array.md +0 -74
- package/node_modules/node-addon-api/doc/typed_array_of.md +0 -133
- package/node_modules/node-addon-api/doc/value.md +0 -269
- package/node_modules/node-addon-api/doc/version_management.md +0 -43
- package/node_modules/node-addon-api/doc/working_with_javascript_values.md +0 -14
- package/node_modules/node-addon-api/external-napi/node_api.h +0 -7
- package/node_modules/node-addon-api/src/node_api.cc +0 -3655
- package/node_modules/node-addon-api/src/node_api.gyp +0 -21
- package/node_modules/node-addon-api/src/node_api.h +0 -588
- package/node_modules/node-addon-api/src/node_api_types.h +0 -115
- package/node_modules/node-addon-api/src/node_internals.cc +0 -142
- package/node_modules/node-addon-api/src/node_internals.h +0 -157
- package/node_modules/node-addon-api/src/util-inl.h +0 -38
- package/node_modules/node-addon-api/src/util.h +0 -7
|
@@ -1,1134 +1,1134 @@
|
|
|
1
|
-
|
|
2
|
-
// This file is part of node-lmdb, the Node.js binding for lmdb
|
|
3
|
-
// Copyright (c) 2013-2017 Timur Kristóf
|
|
4
|
-
// Copyright (c) 2021 Kristopher Tate
|
|
5
|
-
// Licensed to you under the terms of the MIT license
|
|
6
|
-
//
|
|
7
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
9
|
-
// in the Software without restriction, including without limitation the rights
|
|
10
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
// furnished to do so, subject to the following conditions:
|
|
13
|
-
|
|
14
|
-
// The above copyright notice and this permission notice shall be included in
|
|
15
|
-
// all copies or substantial portions of the Software.
|
|
16
|
-
|
|
17
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
-
// THE SOFTWARE.
|
|
24
|
-
|
|
25
|
-
#include "node-lmdb.h"
|
|
26
|
-
|
|
27
|
-
using namespace v8;
|
|
28
|
-
using namespace node;
|
|
29
|
-
|
|
30
|
-
#define IGNORE_NOTFOUND (1)
|
|
31
|
-
thread_local Nan::Persistent<Function>* EnvWrap::txnCtor;
|
|
32
|
-
thread_local Nan::Persistent<Function>* EnvWrap::dbiCtor;
|
|
33
|
-
//Nan::Persistent<Function> EnvWrap::txnCtor;
|
|
34
|
-
//Nan::Persistent<Function> EnvWrap::dbiCtor;
|
|
35
|
-
uv_mutex_t* EnvWrap::envsLock = EnvWrap::initMutex();
|
|
36
|
-
std::vector<env_path_t> EnvWrap::envs;
|
|
37
|
-
|
|
38
|
-
uv_mutex_t* EnvWrap::initMutex() {
|
|
39
|
-
uv_mutex_t* mutex = new uv_mutex_t;
|
|
40
|
-
uv_mutex_init(mutex);
|
|
41
|
-
return mutex;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
EnvWrap::EnvWrap() {
|
|
45
|
-
this->env = nullptr;
|
|
46
|
-
this->currentWriteTxn = nullptr;
|
|
47
|
-
this->currentBatchTxn = nullptr;
|
|
48
|
-
this->currentReadTxn = nullptr;
|
|
49
|
-
this->readTxnRenewed = false;
|
|
50
|
-
this->winMemoryPriority = 5;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
EnvWrap::~EnvWrap() {
|
|
54
|
-
// Close if not closed already
|
|
55
|
-
if (this->env) {
|
|
56
|
-
this->cleanupStrayTxns();
|
|
57
|
-
mdb_env_close(env);
|
|
58
|
-
}
|
|
59
|
-
if (this->compression)
|
|
60
|
-
this->compression->Unref();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
void EnvWrap::cleanupStrayTxns() {
|
|
64
|
-
if (this->currentWriteTxn) {
|
|
65
|
-
mdb_txn_abort(this->currentWriteTxn->txn);
|
|
66
|
-
this->currentWriteTxn->removeFromEnvWrap();
|
|
67
|
-
}
|
|
68
|
-
while (this->readTxns.size()) {
|
|
69
|
-
TxnWrap *tw = *this->readTxns.begin();
|
|
70
|
-
mdb_txn_abort(tw->txn);
|
|
71
|
-
tw->removeFromEnvWrap();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
NAN_METHOD(EnvWrap::ctor) {
|
|
76
|
-
Nan::HandleScope scope;
|
|
77
|
-
|
|
78
|
-
int rc;
|
|
79
|
-
|
|
80
|
-
EnvWrap* ew = new EnvWrap();
|
|
81
|
-
rc = mdb_env_create(&(ew->env));
|
|
82
|
-
|
|
83
|
-
if (rc != 0) {
|
|
84
|
-
mdb_env_close(ew->env);
|
|
85
|
-
return throwLmdbError(rc);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
ew->Wrap(info.This());
|
|
89
|
-
ew->Ref();
|
|
90
|
-
|
|
91
|
-
return info.GetReturnValue().Set(info.This());
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
template<class T>
|
|
95
|
-
int applyUint32Setting(int (*f)(MDB_env *, T), MDB_env* e, Local<Object> options, T dflt, const char* keyName) {
|
|
96
|
-
int rc;
|
|
97
|
-
const Local<Value> value = options->Get(Nan::GetCurrentContext(), Nan::New<String>(keyName).ToLocalChecked()).ToLocalChecked();
|
|
98
|
-
if (value->IsUint32()) {
|
|
99
|
-
rc = f(e, value->Uint32Value(Nan::GetCurrentContext()).FromJust());
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
rc = f(e, dflt);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return rc;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
class SyncWorker : public Nan::AsyncWorker {
|
|
109
|
-
public:
|
|
110
|
-
SyncWorker(MDB_env* env, Nan::Callback *callback)
|
|
111
|
-
: Nan::AsyncWorker(callback), env(env) {}
|
|
112
|
-
|
|
113
|
-
void Execute() {
|
|
114
|
-
int rc = mdb_env_sync(env, 1);
|
|
115
|
-
if (rc != 0) {
|
|
116
|
-
SetErrorMessage(mdb_strerror(rc));
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
void HandleOKCallback() {
|
|
121
|
-
Nan::HandleScope scope;
|
|
122
|
-
Local<v8::Value> argv[] = {
|
|
123
|
-
Nan::Null()
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
callback->Call(1, argv, async_resource);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
private:
|
|
130
|
-
MDB_env* env;
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
class CopyWorker : public Nan::AsyncWorker {
|
|
134
|
-
public:
|
|
135
|
-
CopyWorker(MDB_env* env, char* inPath, int flags, Nan::Callback *callback)
|
|
136
|
-
: Nan::AsyncWorker(callback), env(env), path(strdup(inPath)), flags(flags) {
|
|
137
|
-
}
|
|
138
|
-
~CopyWorker() {
|
|
139
|
-
free(path);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
void Execute() {
|
|
143
|
-
int rc = mdb_env_copy2(env, path, flags);
|
|
144
|
-
if (rc != 0) {
|
|
145
|
-
fprintf(stderr, "Error on copy code: %u\n", rc);
|
|
146
|
-
SetErrorMessage("Error on copy");
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
void HandleOKCallback() {
|
|
151
|
-
Nan::HandleScope scope;
|
|
152
|
-
Local<v8::Value> argv[] = {
|
|
153
|
-
Nan::Null()
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
callback->Call(1, argv, async_resource);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
private:
|
|
160
|
-
MDB_env* env;
|
|
161
|
-
char* path;
|
|
162
|
-
int flags;
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
const int CHANGE_DB = 8;
|
|
166
|
-
const int RESET_CONDITION = 9;
|
|
167
|
-
const int USER_TRANSACTION_CALLBACK = 12;
|
|
168
|
-
const int CONDITION = 1;
|
|
169
|
-
const int WRITE_WITH_VALUE = 2;
|
|
170
|
-
const int DELETE_OPERATION = 4;
|
|
171
|
-
|
|
172
|
-
const int FAILED_CONDITION = 1;
|
|
173
|
-
const int SUCCESSFUL_OPERATION = 0;
|
|
174
|
-
const int BAD_KEY = 3;
|
|
175
|
-
const int NOT_FOUND = 2;
|
|
176
|
-
|
|
177
|
-
BatchWorkerBase::BatchWorkerBase(Nan::Callback *callback, EnvWrap* envForTxn) : Nan::AsyncProgressWorker(callback, "lmdb:batch"),
|
|
178
|
-
envForTxn(envForTxn) {
|
|
179
|
-
currentTxnWrap = nullptr;
|
|
180
|
-
}
|
|
181
|
-
BatchWorkerBase::~BatchWorkerBase() {
|
|
182
|
-
uv_mutex_destroy(userCallbackLock);
|
|
183
|
-
uv_cond_destroy(userCallbackCond);
|
|
184
|
-
}
|
|
185
|
-
void BatchWorkerBase::ContinueBatch(int rc, bool hasStarted) {
|
|
186
|
-
if (hasStarted) {
|
|
187
|
-
finishedProgress = true;
|
|
188
|
-
currentTxnWrap = envForTxn->currentWriteTxn;
|
|
189
|
-
}
|
|
190
|
-
envForTxn->currentWriteTxn = nullptr;
|
|
191
|
-
uv_mutex_lock(userCallbackLock);
|
|
192
|
-
interruptionStatus = rc;
|
|
193
|
-
uv_cond_signal(userCallbackCond);
|
|
194
|
-
uv_mutex_unlock(userCallbackLock);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
class BatchWorker : public BatchWorkerBase {
|
|
198
|
-
public:
|
|
199
|
-
BatchWorker(MDB_env* env, action_t *actions, int actionCount, int putFlags, KeySpace* keySpace, EnvWrap* envForTxn, uint8_t* results, Nan::Callback *callback)
|
|
200
|
-
: BatchWorkerBase(callback, envForTxn),
|
|
201
|
-
env(env),
|
|
202
|
-
actionCount(actionCount),
|
|
203
|
-
results(results),
|
|
204
|
-
actions(actions),
|
|
205
|
-
putFlags(putFlags),
|
|
206
|
-
keySpace(keySpace) {
|
|
207
|
-
interruptionStatus = 0;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
~BatchWorker() {
|
|
211
|
-
delete[] actions;
|
|
212
|
-
delete keySpace;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
void Execute(const ExecutionProgress& executionProgress) {
|
|
216
|
-
MDB_txn *txn;
|
|
217
|
-
// we do compression in this thread to offload from main thread, but do it before transaction to minimize time that the transaction is open
|
|
218
|
-
DbiWrap* dw;
|
|
219
|
-
|
|
220
|
-
for (int i = 0; i < actionCount; i++) {
|
|
221
|
-
action_t* action = &actions[i];
|
|
222
|
-
int actionType = action->actionType;
|
|
223
|
-
if (actionType == CHANGE_DB)
|
|
224
|
-
dw = action->dw;
|
|
225
|
-
else if (actionType & WRITE_WITH_VALUE) {
|
|
226
|
-
Compression* compression = dw->compression;
|
|
227
|
-
if (compression) {
|
|
228
|
-
action->freeValue = compression->compress(&action->data, action->freeValue);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
int rc = mdb_txn_begin(env, nullptr, 0, &txn);
|
|
234
|
-
if (rc != 0) {
|
|
235
|
-
return SetErrorMessage(mdb_strerror(rc));
|
|
236
|
-
}
|
|
237
|
-
if (envForTxn) {
|
|
238
|
-
envForTxn->currentBatchTxn = txn;
|
|
239
|
-
userCallbackLock = new uv_mutex_t;
|
|
240
|
-
userCallbackCond = new uv_cond_t;
|
|
241
|
-
uv_mutex_init(userCallbackLock);
|
|
242
|
-
uv_cond_init(userCallbackCond);
|
|
243
|
-
}
|
|
244
|
-
int validatedDepth = 0;
|
|
245
|
-
int conditionDepth = 0;
|
|
246
|
-
lowerMemPriority(envForTxn);
|
|
247
|
-
for (int i = 0; i < actionCount;) {
|
|
248
|
-
action_t* action = &actions[i];
|
|
249
|
-
int actionType = action->actionType;
|
|
250
|
-
if (actionType >= 8) {
|
|
251
|
-
if (actionType == CHANGE_DB) {
|
|
252
|
-
// reset target db
|
|
253
|
-
dw = action->dw;
|
|
254
|
-
} else if (actionType == RESET_CONDITION) {
|
|
255
|
-
// reset last condition
|
|
256
|
-
conditionDepth--;
|
|
257
|
-
if (validatedDepth > conditionDepth)
|
|
258
|
-
validatedDepth--;
|
|
259
|
-
} else/* if (actionType == USER_TRANSACTION_CALLBACK) */{
|
|
260
|
-
uv_mutex_lock(userCallbackLock);
|
|
261
|
-
finishedProgress = false;
|
|
262
|
-
executionProgress.Send(reinterpret_cast<const char*>(&i), sizeof(int));
|
|
263
|
-
waitForCallback:
|
|
264
|
-
if (interruptionStatus == 0)
|
|
265
|
-
uv_cond_wait(userCallbackCond, userCallbackLock);
|
|
266
|
-
if (interruptionStatus != 0 && !finishedProgress) {
|
|
267
|
-
if (interruptionStatus == INTERRUPT_BATCH) { // interrupted by JS code that wants to run a synchronous transaction
|
|
268
|
-
rc = mdb_txn_commit(txn);
|
|
269
|
-
if (rc == 0) {
|
|
270
|
-
// wait again until the sync transaction is completed
|
|
271
|
-
uv_cond_wait(userCallbackCond, userCallbackLock);
|
|
272
|
-
// now restart our transaction
|
|
273
|
-
rc = mdb_txn_begin(env, nullptr, 0, &txn);
|
|
274
|
-
envForTxn->currentBatchTxn = txn;
|
|
275
|
-
interruptionStatus = 0;
|
|
276
|
-
uv_cond_signal(userCallbackCond);
|
|
277
|
-
goto waitForCallback;
|
|
278
|
-
}
|
|
279
|
-
if (rc != 0) {
|
|
280
|
-
uv_mutex_unlock(userCallbackLock);
|
|
281
|
-
return SetErrorMessage(mdb_strerror(rc));
|
|
282
|
-
}
|
|
283
|
-
} else {
|
|
284
|
-
uv_mutex_unlock(userCallbackLock);
|
|
285
|
-
rc = interruptionStatus;
|
|
286
|
-
goto done;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
uv_mutex_unlock(userCallbackLock);
|
|
290
|
-
}
|
|
291
|
-
results[i++] = SUCCESSFUL_OPERATION;
|
|
292
|
-
continue;
|
|
293
|
-
}
|
|
294
|
-
bool validated;
|
|
295
|
-
if (validatedDepth < conditionDepth) {
|
|
296
|
-
// we are in an invalidated branch, just need to track depth
|
|
297
|
-
results[i] = FAILED_CONDITION;
|
|
298
|
-
validated = false;
|
|
299
|
-
} else if (actionType & CONDITION) { // has precondition
|
|
300
|
-
MDB_val value;
|
|
301
|
-
// TODO: Use a cursor
|
|
302
|
-
rc = mdb_get(txn, dw->dbi, &action->key, &value);
|
|
303
|
-
if (rc == MDB_BAD_VALSIZE) {
|
|
304
|
-
results[i] = BAD_KEY;
|
|
305
|
-
validated = false;
|
|
306
|
-
} else {
|
|
307
|
-
if (action->ifVersion == NO_EXIST_VERSION) {
|
|
308
|
-
validated = rc;
|
|
309
|
-
}
|
|
310
|
-
else {
|
|
311
|
-
if (rc)
|
|
312
|
-
validated = false;
|
|
313
|
-
else
|
|
314
|
-
validated = action->ifVersion == *((double*)value.mv_data);
|
|
315
|
-
}
|
|
316
|
-
results[i] = validated ? SUCCESSFUL_OPERATION : FAILED_CONDITION;
|
|
317
|
-
}
|
|
318
|
-
rc = 0;
|
|
319
|
-
} else {
|
|
320
|
-
validated = true;
|
|
321
|
-
results[i] = SUCCESSFUL_OPERATION;
|
|
322
|
-
}
|
|
323
|
-
if (actionType & (WRITE_WITH_VALUE | DELETE_OPERATION)) { // has write operation to perform
|
|
324
|
-
if (validated) {
|
|
325
|
-
if (actionType & DELETE_OPERATION) {
|
|
326
|
-
rc = mdb_del(txn, dw->dbi, &action->key, (actionType & WRITE_WITH_VALUE) ? &action->data : nullptr);
|
|
327
|
-
if (rc == MDB_NOTFOUND) {
|
|
328
|
-
rc = 0; // ignore not_found errors
|
|
329
|
-
results[i] = NOT_FOUND;
|
|
330
|
-
}
|
|
331
|
-
} else {
|
|
332
|
-
if (dw->hasVersions)
|
|
333
|
-
rc = putWithVersion(txn, dw->dbi, &action->key, &action->data, putFlags, action->version);
|
|
334
|
-
else
|
|
335
|
-
rc = mdb_put(txn, dw->dbi, &action->key, &action->data, putFlags);
|
|
336
|
-
}
|
|
337
|
-
if (rc != 0) {
|
|
338
|
-
if (rc == MDB_BAD_VALSIZE) {
|
|
339
|
-
results[i] = BAD_KEY;
|
|
340
|
-
rc = 0;
|
|
341
|
-
} else {
|
|
342
|
-
goto done;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
if (action->freeValue) {
|
|
347
|
-
action->freeValue(action->data);
|
|
348
|
-
}
|
|
349
|
-
} else {
|
|
350
|
-
// starting condition branch
|
|
351
|
-
conditionDepth++;
|
|
352
|
-
if (validated)
|
|
353
|
-
validatedDepth++;
|
|
354
|
-
}
|
|
355
|
-
i++;
|
|
356
|
-
}
|
|
357
|
-
done:
|
|
358
|
-
if (envForTxn) {
|
|
359
|
-
envForTxn->currentBatchTxn = nullptr;
|
|
360
|
-
if (currentTxnWrap) {
|
|
361
|
-
// if a transaction was wrapped, need to do clean up
|
|
362
|
-
currentTxnWrap->removeFromEnvWrap();
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
if (rc)
|
|
366
|
-
mdb_txn_abort(txn);
|
|
367
|
-
else
|
|
368
|
-
rc = mdb_txn_commit(txn);
|
|
369
|
-
restoreMemPriority(envForTxn);
|
|
370
|
-
if (rc != 0) {
|
|
371
|
-
if ((putFlags & 1) > 0) // sync mode
|
|
372
|
-
return Nan::ThrowError(mdb_strerror(rc));
|
|
373
|
-
else {
|
|
374
|
-
return SetErrorMessage(mdb_strerror(rc));
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
void HandleProgressCallback(const char* data, size_t count) {
|
|
380
|
-
Nan::HandleScope scope;
|
|
381
|
-
if (interruptionStatus != 0) {
|
|
382
|
-
uv_mutex_lock(userCallbackLock);
|
|
383
|
-
if (interruptionStatus != 0)
|
|
384
|
-
uv_cond_wait(userCallbackCond, userCallbackLock);
|
|
385
|
-
// aquire the lock so that we can ensure that if it is restarting the transaction, it finishes doing that
|
|
386
|
-
uv_mutex_unlock(userCallbackLock);
|
|
387
|
-
}
|
|
388
|
-
v8::Local<v8::Value> argv[] = {
|
|
389
|
-
Nan::True()
|
|
390
|
-
};
|
|
391
|
-
envForTxn->currentWriteTxn = currentTxnWrap;
|
|
392
|
-
bool immediateContinue = callback->Call(1, argv, async_resource).ToLocalChecked()->IsTrue();
|
|
393
|
-
if (immediateContinue)
|
|
394
|
-
ContinueBatch(0, true);
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
void HandleOKCallback() {
|
|
398
|
-
Nan::HandleScope scope;
|
|
399
|
-
Local<v8::Value> argv[] = {
|
|
400
|
-
Nan::Null(),
|
|
401
|
-
};
|
|
402
|
-
|
|
403
|
-
callback->Call(1, argv, async_resource);
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
private:
|
|
407
|
-
MDB_env* env;
|
|
408
|
-
int actionCount;
|
|
409
|
-
uint8_t* results;
|
|
410
|
-
int resultIndex = 0;
|
|
411
|
-
action_t* actions;
|
|
412
|
-
int putFlags;
|
|
413
|
-
KeySpace* keySpace;
|
|
414
|
-
friend class DbiWrap;
|
|
415
|
-
};
|
|
416
|
-
|
|
417
|
-
MDB_txn* EnvWrap::getReadTxn() {
|
|
418
|
-
MDB_txn* txn = currentWriteTxn ? currentWriteTxn->txn : nullptr;
|
|
419
|
-
if (txn)
|
|
420
|
-
return txn;
|
|
421
|
-
txn = currentReadTxn;
|
|
422
|
-
if (readTxnRenewed)
|
|
423
|
-
return txn;
|
|
424
|
-
if (txn)
|
|
425
|
-
mdb_txn_renew(txn);
|
|
426
|
-
else {
|
|
427
|
-
mdb_txn_begin(env, nullptr, MDB_RDONLY, &txn);
|
|
428
|
-
currentReadTxn = txn;
|
|
429
|
-
}
|
|
430
|
-
readTxnRenewed = true;
|
|
431
|
-
Local<v8::Value> argv[] = {
|
|
432
|
-
Nan::Null()
|
|
433
|
-
};
|
|
434
|
-
|
|
435
|
-
(new Nan::Callback(onReadTxnRenew.Get(Isolate::GetCurrent())))->Call(1, argv);
|
|
436
|
-
return txn;
|
|
437
|
-
}
|
|
438
|
-
static int encfunc(const MDB_val* src, MDB_val* dst, const MDB_val* key, int encdec)
|
|
439
|
-
{
|
|
440
|
-
chacha8(src->mv_data, src->mv_size, (uint8_t*) key[0].mv_data, (uint8_t*) key[1].mv_data, (char*)dst->mv_data);
|
|
441
|
-
return 0;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
NAN_METHOD(EnvWrap::open) {
|
|
445
|
-
Nan::HandleScope scope;
|
|
446
|
-
|
|
447
|
-
int rc;
|
|
448
|
-
int flags = 0;
|
|
449
|
-
|
|
450
|
-
// Get the wrapper
|
|
451
|
-
EnvWrap *ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
452
|
-
|
|
453
|
-
if (!ew->env) {
|
|
454
|
-
return Nan::ThrowError("The environment is already closed.");
|
|
455
|
-
}
|
|
456
|
-
Local<Object> options = Local<Object>::Cast(info[0]);
|
|
457
|
-
ew->compression = nullptr;
|
|
458
|
-
Local<Value> compressionOption = options->Get(Nan::GetCurrentContext(), Nan::New<String>("compression").ToLocalChecked()).ToLocalChecked();
|
|
459
|
-
if (compressionOption->IsObject()) {
|
|
460
|
-
ew->compression = Nan::ObjectWrap::Unwrap<Compression>(Nan::To<Object>(compressionOption).ToLocalChecked());
|
|
461
|
-
ew->compression->Ref();
|
|
462
|
-
}
|
|
463
|
-
Local<Value> syncInstructionsValue = options->Get(Nan::GetCurrentContext(), Nan::New<String>("syncInstructions").ToLocalChecked()).ToLocalChecked();
|
|
464
|
-
if (syncInstructionsValue->IsArrayBufferView())
|
|
465
|
-
ew->syncInstructions = node::Buffer::Data(syncInstructionsValue);
|
|
466
|
-
|
|
467
|
-
Local<Value> onReadTxnRenew = options->Get(Nan::GetCurrentContext(), Nan::New<String>("onReadTxnRenew").ToLocalChecked()).ToLocalChecked();
|
|
468
|
-
ew->onReadTxnRenew.Reset(Local<Function>::Cast(onReadTxnRenew));
|
|
469
|
-
Local<Value> winMemoryPriorityLocal = options->Get(Nan::GetCurrentContext(), Nan::New<String>("winMemoryPriority").ToLocalChecked()).ToLocalChecked();
|
|
470
|
-
if (winMemoryPriorityLocal->IsNumber())
|
|
471
|
-
ew->winMemoryPriority = winMemoryPriorityLocal->IntegerValue(Nan::GetCurrentContext()).FromJust();
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
Local<String> path = Local<String>::Cast(options->Get(Nan::GetCurrentContext(), Nan::New<String>("path").ToLocalChecked()).ToLocalChecked());
|
|
475
|
-
Nan::Utf8String charPath(path);
|
|
476
|
-
uv_mutex_lock(envsLock);
|
|
477
|
-
for (env_path_t envPath : envs) {
|
|
478
|
-
char* existingPath = envPath.path;
|
|
479
|
-
if (!strcmp(existingPath, *charPath)) {
|
|
480
|
-
envPath.count++;
|
|
481
|
-
mdb_env_close(ew->env);
|
|
482
|
-
ew->env = envPath.env;
|
|
483
|
-
uv_mutex_unlock(envsLock);
|
|
484
|
-
return;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
// Parse the maxDbs option
|
|
489
|
-
rc = applyUint32Setting<unsigned>(&mdb_env_set_maxdbs, ew->env, options, 1, "maxDbs");
|
|
490
|
-
if (rc != 0) {
|
|
491
|
-
uv_mutex_unlock(envsLock);
|
|
492
|
-
return throwLmdbError(rc);
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
// Parse the mapSize option
|
|
496
|
-
Local<Value> mapSizeOption = options->Get(Nan::GetCurrentContext(), Nan::New<String>("mapSize").ToLocalChecked()).ToLocalChecked();
|
|
497
|
-
if (mapSizeOption->IsNumber()) {
|
|
498
|
-
mdb_size_t mapSizeSizeT = mapSizeOption->IntegerValue(Nan::GetCurrentContext()).FromJust();
|
|
499
|
-
rc = mdb_env_set_mapsize(ew->env, mapSizeSizeT);
|
|
500
|
-
if (rc != 0) {
|
|
501
|
-
uv_mutex_unlock(envsLock);
|
|
502
|
-
return throwLmdbError(rc);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
Local<Value> encryptionKey = options->Get(Nan::GetCurrentContext(), Nan::New<String>("encryptionKey").ToLocalChecked()).ToLocalChecked();
|
|
507
|
-
if (!encryptionKey->IsUndefined()) {
|
|
508
|
-
MDB_val enckey;
|
|
509
|
-
KeySpace* keySpace = new KeySpace(false);
|
|
510
|
-
rc = valueToMDBKey(encryptionKey, enckey, *keySpace);
|
|
511
|
-
if (!rc)
|
|
512
|
-
return Nan::ThrowError("Bad encryption key");
|
|
513
|
-
if (enckey.mv_size != 32) {
|
|
514
|
-
return Nan::ThrowError("Encryption key must be 32 bytes long");
|
|
515
|
-
}
|
|
516
|
-
rc = mdb_env_set_encrypt(ew->env, encfunc, &enckey, 0);
|
|
517
|
-
if (rc != 0) {
|
|
518
|
-
return throwLmdbError(rc);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
// Parse the maxReaders option
|
|
523
|
-
// NOTE: mdb.c defines DEFAULT_READERS as 126
|
|
524
|
-
rc = applyUint32Setting<unsigned>(&mdb_env_set_maxreaders, ew->env, options, 126, "maxReaders");
|
|
525
|
-
if (rc != 0) {
|
|
526
|
-
return throwLmdbError(rc);
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
// Parse the pageSize option
|
|
530
|
-
// default is 4096
|
|
531
|
-
rc = applyUint32Setting<int>(&mdb_env_set_pagesize, ew->env, options, 4096, "pageSize");
|
|
532
|
-
if (rc != 0) {
|
|
533
|
-
return throwLmdbError(rc);
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
// NOTE: MDB_FIXEDMAP is not exposed here since it is "highly experimental" + it is irrelevant for this use case
|
|
537
|
-
// NOTE: MDB_NOTLS is not exposed here because it is irrelevant for this use case, as node will run all this on a single thread anyway
|
|
538
|
-
setFlagFromValue(&flags, MDB_NOSUBDIR, "noSubdir", false, options);
|
|
539
|
-
setFlagFromValue(&flags, MDB_RDONLY, "readOnly", false, options);
|
|
540
|
-
setFlagFromValue(&flags, MDB_WRITEMAP, "useWritemap", false, options);
|
|
541
|
-
setFlagFromValue(&flags, MDB_PREVSNAPSHOT, "usePreviousSnapshot", false, options);
|
|
542
|
-
setFlagFromValue(&flags, MDB_NOMEMINIT , "noMemInit", false, options);
|
|
543
|
-
setFlagFromValue(&flags, MDB_NORDAHEAD , "noReadAhead", false, options);
|
|
544
|
-
setFlagFromValue(&flags, MDB_NOMETASYNC, "noMetaSync", false, options);
|
|
545
|
-
setFlagFromValue(&flags, MDB_NOSYNC, "noSync", false, options);
|
|
546
|
-
setFlagFromValue(&flags, MDB_MAPASYNC, "mapAsync", false, options);
|
|
547
|
-
setFlagFromValue(&flags, MDB_NOLOCK, "unsafeNoLock", false, options);
|
|
548
|
-
setFlagFromValue(&flags, MDB_REMAP_CHUNKS, "remapChunks", false, options);
|
|
549
|
-
|
|
550
|
-
if (flags & MDB_NOLOCK) {
|
|
551
|
-
fprintf(stderr, "You chose to use MDB_NOLOCK which is not officially supported by node-lmdb. You have been warned!\n");
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
// Set MDB_NOTLS to enable multiple read-only transactions on the same thread (in this case, the nodejs main thread)
|
|
555
|
-
flags |= MDB_NOTLS;
|
|
556
|
-
#ifdef _WIN32
|
|
557
|
-
if ((flags & MDB_WRITEMAP) && !(flags & MDB_NOSYNC) && !(flags & MDB_REMAP_CHUNKS)) {
|
|
558
|
-
fprintf(stderr, "Writemaps are currently disabled on Windows doing to issues with syncing\n");
|
|
559
|
-
flags &= ~MDB_WRITEMAP;
|
|
560
|
-
}
|
|
561
|
-
#endif
|
|
562
|
-
lowerMemPriority(ew);
|
|
563
|
-
// TODO: make file attributes configurable
|
|
564
|
-
#if NODE_VERSION_AT_LEAST(12,0,0)
|
|
565
|
-
rc = mdb_env_open(ew->env, *String::Utf8Value(Isolate::GetCurrent(), path), flags, 0664);
|
|
566
|
-
#else
|
|
567
|
-
rc = mdb_env_open(ew->env, *String::Utf8Value(path), flags, 0664);
|
|
568
|
-
#endif
|
|
569
|
-
restoreMemPriority(ew);
|
|
570
|
-
|
|
571
|
-
if (rc != 0) {
|
|
572
|
-
mdb_env_close(ew->env);
|
|
573
|
-
uv_mutex_unlock(envsLock);
|
|
574
|
-
ew->env = nullptr;
|
|
575
|
-
return throwLmdbError(rc);
|
|
576
|
-
}
|
|
577
|
-
env_path_t envPath;
|
|
578
|
-
envPath.path = strdup(*charPath);
|
|
579
|
-
envPath.env = ew->env;
|
|
580
|
-
envPath.count = 1;
|
|
581
|
-
envs.push_back(envPath);
|
|
582
|
-
uv_mutex_unlock(envsLock);
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
NAN_METHOD(EnvWrap::resize) {
|
|
586
|
-
Nan::HandleScope scope;
|
|
587
|
-
|
|
588
|
-
// Get the wrapper
|
|
589
|
-
EnvWrap *ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
590
|
-
|
|
591
|
-
if (!ew->env) {
|
|
592
|
-
return Nan::ThrowError("The environment is already closed.");
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
// Check that the correct number/type of arguments was given.
|
|
596
|
-
if (info.Length() != 1 || !info[0]->IsNumber()) {
|
|
597
|
-
return Nan::ThrowError("Call env.resize() with exactly one argument which is a number.");
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
// Since this function may only be called if no transactions are active in this process, check this condition.
|
|
601
|
-
if (ew->currentWriteTxn/* || ew->readTxns.size()*/) {
|
|
602
|
-
return Nan::ThrowError("Only call env.resize() when there are no active transactions. Please close all transactions before calling env.resize().");
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
mdb_size_t mapSizeSizeT = info[0]->IntegerValue(Nan::GetCurrentContext()).FromJust();
|
|
606
|
-
lowerMemPriority(ew);
|
|
607
|
-
int rc = mdb_env_set_mapsize(ew->env, mapSizeSizeT);
|
|
608
|
-
restoreMemPriority(ew);
|
|
609
|
-
if (rc == EINVAL) {
|
|
610
|
-
//fprintf(stderr, "Resize failed, will try to get transaction and try again");
|
|
611
|
-
MDB_txn *txn;
|
|
612
|
-
rc = mdb_txn_begin(ew->env, nullptr, 0, &txn);
|
|
613
|
-
if (rc != 0)
|
|
614
|
-
return throwLmdbError(rc);
|
|
615
|
-
rc = mdb_txn_commit(txn);
|
|
616
|
-
if (rc != 0)
|
|
617
|
-
return throwLmdbError(rc);
|
|
618
|
-
rc = mdb_env_set_mapsize(ew->env, mapSizeSizeT);
|
|
619
|
-
}
|
|
620
|
-
if (rc != 0) {
|
|
621
|
-
return throwLmdbError(rc);
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
NAN_METHOD(EnvWrap::close) {
|
|
626
|
-
EnvWrap *ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
627
|
-
ew->Unref();
|
|
628
|
-
|
|
629
|
-
if (!ew->env) {
|
|
630
|
-
return Nan::ThrowError("The environment is already closed.");
|
|
631
|
-
}
|
|
632
|
-
ew->cleanupStrayTxns();
|
|
633
|
-
|
|
634
|
-
uv_mutex_lock(envsLock);
|
|
635
|
-
for (auto envPath = envs.begin(); envPath != envs.end(); ) {
|
|
636
|
-
if (envPath->env == ew->env) {
|
|
637
|
-
envPath->count--;
|
|
638
|
-
if (envPath->count <= 0) {
|
|
639
|
-
// last thread using it, we can really close it now
|
|
640
|
-
envs.erase(envPath);
|
|
641
|
-
mdb_env_close(ew->env);
|
|
642
|
-
}
|
|
643
|
-
break;
|
|
644
|
-
}
|
|
645
|
-
++envPath;
|
|
646
|
-
}
|
|
647
|
-
uv_mutex_unlock(envsLock);
|
|
648
|
-
|
|
649
|
-
ew->env = nullptr;
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
NAN_METHOD(EnvWrap::stat) {
|
|
653
|
-
Nan::HandleScope scope;
|
|
654
|
-
|
|
655
|
-
// Get the wrapper
|
|
656
|
-
EnvWrap *ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
657
|
-
if (!ew->env) {
|
|
658
|
-
return Nan::ThrowError("The environment is already closed.");
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
int rc;
|
|
662
|
-
MDB_stat stat;
|
|
663
|
-
|
|
664
|
-
rc = mdb_env_stat(ew->env, &stat);
|
|
665
|
-
if (rc != 0) {
|
|
666
|
-
return throwLmdbError(rc);
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
Local<Context> context = Nan::GetCurrentContext();
|
|
670
|
-
Local<Object> obj = Nan::New<Object>();
|
|
671
|
-
(void)obj->Set(context, Nan::New<String>("pageSize").ToLocalChecked(), Nan::New<Number>(stat.ms_psize));
|
|
672
|
-
(void)obj->Set(context, Nan::New<String>("treeDepth").ToLocalChecked(), Nan::New<Number>(stat.ms_depth));
|
|
673
|
-
(void)obj->Set(context, Nan::New<String>("treeBranchPageCount").ToLocalChecked(), Nan::New<Number>(stat.ms_branch_pages));
|
|
674
|
-
(void)obj->Set(context, Nan::New<String>("treeLeafPageCount").ToLocalChecked(), Nan::New<Number>(stat.ms_leaf_pages));
|
|
675
|
-
(void)obj->Set(context, Nan::New<String>("entryCount").ToLocalChecked(), Nan::New<Number>(stat.ms_entries));
|
|
676
|
-
(void)obj->Set(context, Nan::New<String>("overflowPages").ToLocalChecked(), Nan::New<Number>(stat.ms_overflow_pages));
|
|
677
|
-
|
|
678
|
-
info.GetReturnValue().Set(obj);
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
NAN_METHOD(EnvWrap::freeStat) {
|
|
682
|
-
Nan::HandleScope scope;
|
|
683
|
-
|
|
684
|
-
// Get the wrapper
|
|
685
|
-
EnvWrap *ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
686
|
-
if (!ew->env) {
|
|
687
|
-
return Nan::ThrowError("The environment is already closed.");
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
if (info.Length() != 1) {
|
|
691
|
-
return Nan::ThrowError("env.freeStat should be called with a single argument which is a txn.");
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
TxnWrap *txn = Nan::ObjectWrap::Unwrap<TxnWrap>(Local<Object>::Cast(info[0]));
|
|
695
|
-
|
|
696
|
-
int rc;
|
|
697
|
-
MDB_stat stat;
|
|
698
|
-
|
|
699
|
-
rc = mdb_stat(txn->txn, 0, &stat);
|
|
700
|
-
if (rc != 0) {
|
|
701
|
-
return throwLmdbError(rc);
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
Local<Context> context = Nan::GetCurrentContext();
|
|
705
|
-
Local<Object> obj = Nan::New<Object>();
|
|
706
|
-
(void)obj->Set(context, Nan::New<String>("pageSize").ToLocalChecked(), Nan::New<Number>(stat.ms_psize));
|
|
707
|
-
(void)obj->Set(context, Nan::New<String>("treeDepth").ToLocalChecked(), Nan::New<Number>(stat.ms_depth));
|
|
708
|
-
(void)obj->Set(context, Nan::New<String>("treeBranchPageCount").ToLocalChecked(), Nan::New<Number>(stat.ms_branch_pages));
|
|
709
|
-
(void)obj->Set(context, Nan::New<String>("treeLeafPageCount").ToLocalChecked(), Nan::New<Number>(stat.ms_leaf_pages));
|
|
710
|
-
(void)obj->Set(context, Nan::New<String>("entryCount").ToLocalChecked(), Nan::New<Number>(stat.ms_entries));
|
|
711
|
-
(void)obj->Set(context, Nan::New<String>("overflowPages").ToLocalChecked(), Nan::New<Number>(stat.ms_overflow_pages));
|
|
712
|
-
|
|
713
|
-
info.GetReturnValue().Set(obj);
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
NAN_METHOD(EnvWrap::info) {
|
|
717
|
-
Nan::HandleScope scope;
|
|
718
|
-
|
|
719
|
-
// Get the wrapper
|
|
720
|
-
EnvWrap *ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
721
|
-
if (!ew->env) {
|
|
722
|
-
return Nan::ThrowError("The environment is already closed.");
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
int rc;
|
|
726
|
-
MDB_envinfo envinfo;
|
|
727
|
-
|
|
728
|
-
rc = mdb_env_info(ew->env, &envinfo);
|
|
729
|
-
if (rc != 0) {
|
|
730
|
-
return throwLmdbError(rc);
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
Local<Context> context = Nan::GetCurrentContext();
|
|
734
|
-
Local<Object> obj = Nan::New<Object>();
|
|
735
|
-
(void)obj->Set(context, Nan::New<String>("mapAddress").ToLocalChecked(), Nan::New<Number>((uint64_t) envinfo.me_mapaddr));
|
|
736
|
-
(void)obj->Set(context, Nan::New<String>("mapSize").ToLocalChecked(), Nan::New<Number>(envinfo.me_mapsize));
|
|
737
|
-
(void)obj->Set(context, Nan::New<String>("lastPageNumber").ToLocalChecked(), Nan::New<Number>(envinfo.me_last_pgno));
|
|
738
|
-
(void)obj->Set(context, Nan::New<String>("lastTxnId").ToLocalChecked(), Nan::New<Number>(envinfo.me_last_txnid));
|
|
739
|
-
(void)obj->Set(context, Nan::New<String>("maxReaders").ToLocalChecked(), Nan::New<Number>(envinfo.me_maxreaders));
|
|
740
|
-
(void)obj->Set(context, Nan::New<String>("numReaders").ToLocalChecked(), Nan::New<Number>(envinfo.me_numreaders));
|
|
741
|
-
|
|
742
|
-
info.GetReturnValue().Set(obj);
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
NAN_METHOD(EnvWrap::readerCheck) {
|
|
746
|
-
Nan::HandleScope scope;
|
|
747
|
-
|
|
748
|
-
// Get the wrapper
|
|
749
|
-
EnvWrap *ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
750
|
-
if (!ew->env) {
|
|
751
|
-
return Nan::ThrowError("The environment is already closed.");
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
int rc, dead;
|
|
755
|
-
rc = mdb_reader_check(ew->env, &dead);
|
|
756
|
-
if (rc != 0) {
|
|
757
|
-
return throwLmdbError(rc);
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
info.GetReturnValue().Set(Nan::New<Number>(dead));
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
Local<Array> readerStrings;
|
|
764
|
-
MDB_msg_func* printReaders = ([](const char* message, void* ctx) -> int {
|
|
765
|
-
readerStrings->Set(Nan::GetCurrentContext(), readerStrings->Length(), Nan::New<String>(message).ToLocalChecked());
|
|
766
|
-
return 0;
|
|
767
|
-
});
|
|
768
|
-
|
|
769
|
-
NAN_METHOD(EnvWrap::readerList) {
|
|
770
|
-
Nan::HandleScope scope;
|
|
771
|
-
|
|
772
|
-
// Get the wrapper
|
|
773
|
-
EnvWrap* ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
774
|
-
if (!ew->env) {
|
|
775
|
-
return Nan::ThrowError("The environment is already closed.");
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
readerStrings = Nan::New<Array>(0);
|
|
779
|
-
int rc;
|
|
780
|
-
rc = mdb_reader_list(ew->env, printReaders, nullptr);
|
|
781
|
-
if (rc != 0) {
|
|
782
|
-
return throwLmdbError(rc);
|
|
783
|
-
}
|
|
784
|
-
info.GetReturnValue().Set(readerStrings);
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
NAN_METHOD(EnvWrap::copy) {
|
|
789
|
-
Nan::HandleScope scope;
|
|
790
|
-
|
|
791
|
-
// Get the wrapper
|
|
792
|
-
EnvWrap *ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
793
|
-
|
|
794
|
-
if (!ew->env) {
|
|
795
|
-
return Nan::ThrowError("The environment is already closed.");
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
// Check that the correct number/type of arguments was given.
|
|
799
|
-
if (!info[0]->IsString()) {
|
|
800
|
-
return Nan::ThrowError("Call env.copy(path, compact?, callback) with a file path.");
|
|
801
|
-
}
|
|
802
|
-
if (!info[info.Length() - 1]->IsFunction()) {
|
|
803
|
-
return Nan::ThrowError("Call env.copy(path, compact?, callback) with a file path.");
|
|
804
|
-
}
|
|
805
|
-
Nan::Utf8String path(info[0].As<String>());
|
|
806
|
-
|
|
807
|
-
int flags = 0;
|
|
808
|
-
if (info.Length() > 1 && info[1]->IsTrue()) {
|
|
809
|
-
flags = MDB_CP_COMPACT;
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
Nan::Callback* callback = new Nan::Callback(
|
|
813
|
-
Local<v8::Function>::Cast(info[info.Length() > 2 ? 2 : 1])
|
|
814
|
-
);
|
|
815
|
-
|
|
816
|
-
CopyWorker* worker = new CopyWorker(
|
|
817
|
-
ew->env, *path, flags, callback
|
|
818
|
-
);
|
|
819
|
-
|
|
820
|
-
Nan::AsyncQueueWorker(worker);
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
NAN_METHOD(EnvWrap::detachBuffer) {
|
|
824
|
-
Nan::HandleScope scope;
|
|
825
|
-
#if NODE_VERSION_AT_LEAST(12,0,0)
|
|
826
|
-
Local<v8::ArrayBuffer>::Cast(info[0])->Detach();
|
|
827
|
-
#endif
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
NAN_METHOD(EnvWrap::beginTxn) {
|
|
831
|
-
Nan::HandleScope scope;
|
|
832
|
-
|
|
833
|
-
Nan::MaybeLocal<Object> maybeInstance;
|
|
834
|
-
|
|
835
|
-
if (info.Length() > 1) {
|
|
836
|
-
const int argc = 3;
|
|
837
|
-
|
|
838
|
-
Local<Value> argv[argc] = { info.This(), info[0], info[1] };
|
|
839
|
-
maybeInstance = Nan::NewInstance(Nan::New(*txnCtor), argc, argv);
|
|
840
|
-
|
|
841
|
-
} else {
|
|
842
|
-
const int argc = 2;
|
|
843
|
-
|
|
844
|
-
Local<Value> argv[argc] = { info.This(), info[0] };
|
|
845
|
-
maybeInstance = Nan::NewInstance(Nan::New(*txnCtor), argc, argv);
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
// Check if txn could be created
|
|
849
|
-
if ((maybeInstance.IsEmpty())) {
|
|
850
|
-
// The maybeInstance is empty because the txnCtor called Nan::ThrowError.
|
|
851
|
-
// No need to call that here again, the user will get the error thrown there.
|
|
852
|
-
return;
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
Local<Object> instance = maybeInstance.ToLocalChecked();
|
|
856
|
-
info.GetReturnValue().Set(instance);
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
NAN_METHOD(EnvWrap::openDbi) {
|
|
860
|
-
Nan::HandleScope scope;
|
|
861
|
-
|
|
862
|
-
const unsigned argc = 2;
|
|
863
|
-
Local<Value> argv[argc] = { info.This(), info[0] };
|
|
864
|
-
Nan::MaybeLocal<Object> maybeInstance = Nan::NewInstance(Nan::New(*dbiCtor), argc, argv);
|
|
865
|
-
|
|
866
|
-
// Check if database could be opened
|
|
867
|
-
if ((maybeInstance.IsEmpty())) {
|
|
868
|
-
// The maybeInstance is empty because the dbiCtor called Nan::ThrowError.
|
|
869
|
-
// No need to call that here again, the user will get the error thrown there.
|
|
870
|
-
return;
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
Local<Object> instance = maybeInstance.ToLocalChecked();
|
|
874
|
-
info.GetReturnValue().Set(instance);
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
NAN_METHOD(EnvWrap::sync) {
|
|
878
|
-
Nan::HandleScope scope;
|
|
879
|
-
|
|
880
|
-
EnvWrap *ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
881
|
-
|
|
882
|
-
if (!ew->env) {
|
|
883
|
-
return Nan::ThrowError("The environment is already closed.");
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
Nan::Callback* callback = new Nan::Callback(
|
|
887
|
-
Local<v8::Function>::Cast(info[0])
|
|
888
|
-
);
|
|
889
|
-
|
|
890
|
-
SyncWorker* worker = new SyncWorker(
|
|
891
|
-
ew->env, callback
|
|
892
|
-
);
|
|
893
|
-
|
|
894
|
-
Nan::AsyncQueueWorker(worker);
|
|
895
|
-
return;
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
NAN_METHOD(EnvWrap::batchWrite) {
|
|
900
|
-
Nan::HandleScope scope;
|
|
901
|
-
|
|
902
|
-
EnvWrap *ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
903
|
-
Local<Context> context = Nan::GetCurrentContext();
|
|
904
|
-
|
|
905
|
-
if (!ew->env) {
|
|
906
|
-
return Nan::ThrowError("The environment is already closed.");
|
|
907
|
-
}
|
|
908
|
-
Local<v8::Array> array = Local<v8::Array>::Cast(info[0]);
|
|
909
|
-
|
|
910
|
-
int length = array->Length();
|
|
911
|
-
action_t* actions = new action_t[length];
|
|
912
|
-
|
|
913
|
-
int putFlags = 0;
|
|
914
|
-
KeySpace* keySpace = new KeySpace(false);
|
|
915
|
-
Nan::Callback* callback;
|
|
916
|
-
uint8_t* results = (uint8_t*) node::Buffer::Data(Local<Object>::Cast(info[1]));
|
|
917
|
-
Local<Value> options = info[2];
|
|
918
|
-
|
|
919
|
-
if (!info[2]->IsNull() && !info[2]->IsUndefined() && info[2]->IsObject() && !info[2]->IsFunction()) {
|
|
920
|
-
Local<Object> optionsObject = Local<Object>::Cast(options);
|
|
921
|
-
setFlagFromValue(&putFlags, MDB_NODUPDATA, "noDupData", false, optionsObject);
|
|
922
|
-
setFlagFromValue(&putFlags, MDB_NOOVERWRITE, "noOverwrite", false, optionsObject);
|
|
923
|
-
setFlagFromValue(&putFlags, MDB_APPEND, "append", false, optionsObject);
|
|
924
|
-
setFlagFromValue(&putFlags, MDB_APPENDDUP, "appendDup", false, optionsObject);
|
|
925
|
-
callback = new Nan::Callback(
|
|
926
|
-
Local<v8::Function>::Cast(info[3])
|
|
927
|
-
);
|
|
928
|
-
} else {
|
|
929
|
-
if (info.Length() > 2 || info[0]->IsFunction())
|
|
930
|
-
callback = new Nan::Callback(
|
|
931
|
-
Local<v8::Function>::Cast(info[2])
|
|
932
|
-
);
|
|
933
|
-
else {
|
|
934
|
-
// sync mode
|
|
935
|
-
putFlags &= 1;
|
|
936
|
-
callback = nullptr;
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
BatchWorker* worker = new BatchWorker(
|
|
941
|
-
ew->env, actions, length, putFlags, keySpace, ew, results, callback
|
|
942
|
-
);
|
|
943
|
-
ew->batchWorker = worker;
|
|
944
|
-
bool keyIsValid = false;
|
|
945
|
-
NodeLmdbKeyType keyType;
|
|
946
|
-
DbiWrap* dw;
|
|
947
|
-
|
|
948
|
-
for (unsigned int i = 0; i < array->Length(); i++) {
|
|
949
|
-
//Local<Value> element = array->Get(context, i).ToLocalChecked(); // checked/enforce in js
|
|
950
|
-
//if (!element->IsObject())
|
|
951
|
-
// continue;
|
|
952
|
-
action_t* action = &actions[i];
|
|
953
|
-
Local<Value> operationValue = array->Get(context, i).ToLocalChecked();
|
|
954
|
-
|
|
955
|
-
bool isArray = operationValue->IsArray();
|
|
956
|
-
if (!isArray) {
|
|
957
|
-
// change target db
|
|
958
|
-
if (operationValue->IsObject()) {
|
|
959
|
-
action->actionType = CHANGE_DB;
|
|
960
|
-
dw = action->dw = Nan::ObjectWrap::Unwrap<DbiWrap>(Local<Object>::Cast(operationValue));
|
|
961
|
-
} else if (operationValue->IsTrue()) {
|
|
962
|
-
action->actionType = USER_TRANSACTION_CALLBACK;
|
|
963
|
-
} else { // else false
|
|
964
|
-
// reset condition
|
|
965
|
-
action->actionType = RESET_CONDITION;
|
|
966
|
-
}
|
|
967
|
-
continue;
|
|
968
|
-
// if we did not coordinate to always reference the object on the JS side, we would need this (but it is expensive):
|
|
969
|
-
// worker->SaveToPersistent(persistedIndex++, currentDb);
|
|
970
|
-
}
|
|
971
|
-
Local<Object> operation = Local<Object>::Cast(operationValue);
|
|
972
|
-
Local<v8::Value> key = operation->Get(context, 0).ToLocalChecked();
|
|
973
|
-
|
|
974
|
-
keyType = dw->keyType;
|
|
975
|
-
if (keyType == NodeLmdbKeyType::DefaultKey) {
|
|
976
|
-
keyIsValid = valueToMDBKey(key, action->key, *keySpace);
|
|
977
|
-
}
|
|
978
|
-
else {
|
|
979
|
-
argToKey(key, action->key, keyType, keyIsValid);
|
|
980
|
-
if (!keyIsValid) {
|
|
981
|
-
// argToKey already threw an error
|
|
982
|
-
delete worker;
|
|
983
|
-
return;
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
// if we did not coordinate to always reference the object on the JS side, we would need this (but it is expensive):
|
|
987
|
-
//if (!action->freeKey)
|
|
988
|
-
// worker->SaveToPersistent(persistedIndex++, key);
|
|
989
|
-
Local<v8::Value> value = operation->Get(context, 1).ToLocalChecked();
|
|
990
|
-
|
|
991
|
-
if (dw->hasVersions) {
|
|
992
|
-
if (value->IsNumber()) {
|
|
993
|
-
action->actionType = CONDITION; // checking version action type
|
|
994
|
-
action->ifVersion = Nan::To<v8::Number>(value).ToLocalChecked()->Value();
|
|
995
|
-
continue;
|
|
996
|
-
}
|
|
997
|
-
action->actionType = CONDITION | WRITE_WITH_VALUE; // conditional save value
|
|
998
|
-
// TODO: Check length before continuing?
|
|
999
|
-
double version = 0;
|
|
1000
|
-
Local<v8::Value> versionValue = operation->Get(context, 2).ToLocalChecked();
|
|
1001
|
-
if (versionValue->IsNumber())
|
|
1002
|
-
version = Nan::To<v8::Number>(versionValue).ToLocalChecked()->Value();
|
|
1003
|
-
action->version = version;
|
|
1004
|
-
|
|
1005
|
-
versionValue = operation->Get(context, 3).ToLocalChecked();
|
|
1006
|
-
if (versionValue->IsNumber())
|
|
1007
|
-
version = Nan::To<v8::Number>(versionValue).ToLocalChecked()->Value();
|
|
1008
|
-
else if (versionValue->IsNull())
|
|
1009
|
-
version = NO_EXIST_VERSION;
|
|
1010
|
-
else
|
|
1011
|
-
action->actionType = WRITE_WITH_VALUE;
|
|
1012
|
-
action->ifVersion = version;
|
|
1013
|
-
} else {
|
|
1014
|
-
Local<v8::Value> deleteValue = operation->Get(context, 2).ToLocalChecked();
|
|
1015
|
-
if (deleteValue->IsTrue()) // useful for dupsort so we can specify a specfic value to delete
|
|
1016
|
-
action->actionType = DELETE_OPERATION | WRITE_WITH_VALUE;
|
|
1017
|
-
else
|
|
1018
|
-
action->actionType = WRITE_WITH_VALUE;
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1021
|
-
if (value->IsNull() || value->IsUndefined()) {
|
|
1022
|
-
// standard delete (no regard for value)
|
|
1023
|
-
action->actionType = DELETE_OPERATION | (action->actionType & CONDITION); // only DELETE_OPERATION, no WRITE_WITH_VALUE
|
|
1024
|
-
action->freeValue = nullptr;
|
|
1025
|
-
} else if (value->IsArrayBufferView()) {
|
|
1026
|
-
int size = action->data.mv_size = node::Buffer::Length(value);
|
|
1027
|
-
action->data.mv_data = size > 0 ? node::Buffer::Data(value) : nullptr;
|
|
1028
|
-
action->freeValue = nullptr; // don't free, belongs to node
|
|
1029
|
-
//worker->SaveToPersistent(persistedIndex++, value); // this is coordinated to always be referenced on the JS side
|
|
1030
|
-
} else {
|
|
1031
|
-
writeValueToEntry(Nan::To<v8::String>(value).ToLocalChecked(), &action->data);
|
|
1032
|
-
action->freeValue = ([](MDB_val &value) -> void {
|
|
1033
|
-
delete[] (char*)value.mv_data;
|
|
1034
|
-
});
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
//worker->SaveToPersistent("env", info.This()); // this is coordinated to always be referenced on the JS side
|
|
1039
|
-
if (callback) {
|
|
1040
|
-
Nan::AsyncQueueWorker(worker);
|
|
1041
|
-
} else {
|
|
1042
|
-
// sync mode
|
|
1043
|
-
//AsyncProgressWorker::ExecutionProgress executionProgress(worker);
|
|
1044
|
-
//worker->Execute(/*&executionProgress*/);
|
|
1045
|
-
delete worker;
|
|
1046
|
-
}
|
|
1047
|
-
return;
|
|
1048
|
-
}
|
|
1049
|
-
|
|
1050
|
-
NAN_METHOD(EnvWrap::continueBatch) {
|
|
1051
|
-
EnvWrap* ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
1052
|
-
ew->batchWorker->ContinueBatch(info[0]->IntegerValue(Nan::GetCurrentContext()).FromJust(), true);
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
NAN_METHOD(EnvWrap::resetCurrentReadTxn) {
|
|
1056
|
-
EnvWrap* ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
1057
|
-
mdb_txn_reset(ew->currentReadTxn);
|
|
1058
|
-
ew->readTxnRenewed = false;
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
|
-
void EnvWrap::setupExports(Local<Object> exports) {
|
|
1062
|
-
// EnvWrap: Prepare constructor template
|
|
1063
|
-
Local<FunctionTemplate> envTpl = Nan::New<FunctionTemplate>(EnvWrap::ctor);
|
|
1064
|
-
envTpl->SetClassName(Nan::New<String>("Env").ToLocalChecked());
|
|
1065
|
-
envTpl->InstanceTemplate()->SetInternalFieldCount(1);
|
|
1066
|
-
// EnvWrap: Add functions to the prototype
|
|
1067
|
-
Isolate *isolate = Isolate::GetCurrent();
|
|
1068
|
-
envTpl->PrototypeTemplate()->Set(isolate, "open", Nan::New<FunctionTemplate>(EnvWrap::open));
|
|
1069
|
-
envTpl->PrototypeTemplate()->Set(isolate, "close", Nan::New<FunctionTemplate>(EnvWrap::close));
|
|
1070
|
-
envTpl->PrototypeTemplate()->Set(isolate, "beginTxn", Nan::New<FunctionTemplate>(EnvWrap::beginTxn));
|
|
1071
|
-
envTpl->PrototypeTemplate()->Set(isolate, "openDbi", Nan::New<FunctionTemplate>(EnvWrap::openDbi));
|
|
1072
|
-
envTpl->PrototypeTemplate()->Set(isolate, "sync", Nan::New<FunctionTemplate>(EnvWrap::sync));
|
|
1073
|
-
envTpl->PrototypeTemplate()->Set(isolate, "batchWrite", Nan::New<FunctionTemplate>(EnvWrap::batchWrite));
|
|
1074
|
-
envTpl->PrototypeTemplate()->Set(isolate, "continueBatch", Nan::New<FunctionTemplate>(EnvWrap::continueBatch));
|
|
1075
|
-
envTpl->PrototypeTemplate()->Set(isolate, "stat", Nan::New<FunctionTemplate>(EnvWrap::stat));
|
|
1076
|
-
envTpl->PrototypeTemplate()->Set(isolate, "freeStat", Nan::New<FunctionTemplate>(EnvWrap::freeStat));
|
|
1077
|
-
envTpl->PrototypeTemplate()->Set(isolate, "info", Nan::New<FunctionTemplate>(EnvWrap::info));
|
|
1078
|
-
envTpl->PrototypeTemplate()->Set(isolate, "readerCheck", Nan::New<FunctionTemplate>(EnvWrap::readerCheck));
|
|
1079
|
-
envTpl->PrototypeTemplate()->Set(isolate, "readerList", Nan::New<FunctionTemplate>(EnvWrap::readerList));
|
|
1080
|
-
envTpl->PrototypeTemplate()->Set(isolate, "resize", Nan::New<FunctionTemplate>(EnvWrap::resize));
|
|
1081
|
-
envTpl->PrototypeTemplate()->Set(isolate, "copy", Nan::New<FunctionTemplate>(EnvWrap::copy));
|
|
1082
|
-
envTpl->PrototypeTemplate()->Set(isolate, "detachBuffer", Nan::New<FunctionTemplate>(EnvWrap::detachBuffer));
|
|
1083
|
-
envTpl->PrototypeTemplate()->Set(isolate, "resetCurrentReadTxn", Nan::New<FunctionTemplate>(EnvWrap::resetCurrentReadTxn));
|
|
1084
|
-
|
|
1085
|
-
// TxnWrap: Prepare constructor template
|
|
1086
|
-
Local<FunctionTemplate> txnTpl = Nan::New<FunctionTemplate>(TxnWrap::ctor);
|
|
1087
|
-
txnTpl->SetClassName(Nan::New<String>("Txn").ToLocalChecked());
|
|
1088
|
-
txnTpl->InstanceTemplate()->SetInternalFieldCount(1);
|
|
1089
|
-
// TxnWrap: Add functions to the prototype
|
|
1090
|
-
txnTpl->PrototypeTemplate()->Set(isolate, "commit", Nan::New<FunctionTemplate>(TxnWrap::commit));
|
|
1091
|
-
txnTpl->PrototypeTemplate()->Set(isolate, "abort", Nan::New<FunctionTemplate>(TxnWrap::abort));
|
|
1092
|
-
txnTpl->PrototypeTemplate()->Set(isolate, "getString", Nan::New<FunctionTemplate>(TxnWrap::getString));
|
|
1093
|
-
txnTpl->PrototypeTemplate()->Set(isolate, "getStringUnsafe", Nan::New<FunctionTemplate>(TxnWrap::getStringUnsafe));
|
|
1094
|
-
txnTpl->PrototypeTemplate()->Set(isolate, "getUtf8", Nan::New<FunctionTemplate>(TxnWrap::getUtf8));
|
|
1095
|
-
txnTpl->PrototypeTemplate()->Set(isolate, "getBinary", Nan::New<FunctionTemplate>(TxnWrap::getBinary));
|
|
1096
|
-
txnTpl->PrototypeTemplate()->Set(isolate, "getBinaryUnsafe", Nan::New<FunctionTemplate>(TxnWrap::getBinaryUnsafe));
|
|
1097
|
-
txnTpl->PrototypeTemplate()->Set(isolate, "getNumber", Nan::New<FunctionTemplate>(TxnWrap::getNumber));
|
|
1098
|
-
txnTpl->PrototypeTemplate()->Set(isolate, "getBoolean", Nan::New<FunctionTemplate>(TxnWrap::getBoolean));
|
|
1099
|
-
txnTpl->PrototypeTemplate()->Set(isolate, "putString", Nan::New<FunctionTemplate>(TxnWrap::putString));
|
|
1100
|
-
txnTpl->PrototypeTemplate()->Set(isolate, "putBinary", Nan::New<FunctionTemplate>(TxnWrap::putBinary));
|
|
1101
|
-
txnTpl->PrototypeTemplate()->Set(isolate, "putNumber", Nan::New<FunctionTemplate>(TxnWrap::putNumber));
|
|
1102
|
-
txnTpl->PrototypeTemplate()->Set(isolate, "putBoolean", Nan::New<FunctionTemplate>(TxnWrap::putBoolean));
|
|
1103
|
-
txnTpl->PrototypeTemplate()->Set(isolate, "putUtf8", Nan::New<FunctionTemplate>(TxnWrap::putUtf8));
|
|
1104
|
-
txnTpl->PrototypeTemplate()->Set(isolate, "del", Nan::New<FunctionTemplate>(TxnWrap::del));
|
|
1105
|
-
txnTpl->PrototypeTemplate()->Set(isolate, "reset", Nan::New<FunctionTemplate>(TxnWrap::reset));
|
|
1106
|
-
txnTpl->PrototypeTemplate()->Set(isolate, "renew", Nan::New<FunctionTemplate>(TxnWrap::renew));
|
|
1107
|
-
// TODO: wrap mdb_cmp too
|
|
1108
|
-
// TODO: wrap mdb_dcmp too
|
|
1109
|
-
// TxnWrap: Get constructor
|
|
1110
|
-
EnvWrap::txnCtor = new Nan::Persistent<Function>();
|
|
1111
|
-
EnvWrap::txnCtor->Reset( txnTpl->GetFunction(Nan::GetCurrentContext()).ToLocalChecked());
|
|
1112
|
-
|
|
1113
|
-
// DbiWrap: Prepare constructor template
|
|
1114
|
-
Local<FunctionTemplate> dbiTpl = Nan::New<FunctionTemplate>(DbiWrap::ctor);
|
|
1115
|
-
dbiTpl->SetClassName(Nan::New<String>("Dbi").ToLocalChecked());
|
|
1116
|
-
dbiTpl->InstanceTemplate()->SetInternalFieldCount(1);
|
|
1117
|
-
// DbiWrap: Add functions to the prototype
|
|
1118
|
-
dbiTpl->PrototypeTemplate()->Set(isolate, "close", Nan::New<FunctionTemplate>(DbiWrap::close));
|
|
1119
|
-
dbiTpl->PrototypeTemplate()->Set(isolate, "drop", Nan::New<FunctionTemplate>(DbiWrap::drop));
|
|
1120
|
-
dbiTpl->PrototypeTemplate()->Set(isolate, "stat", Nan::New<FunctionTemplate>(DbiWrap::stat));
|
|
1121
|
-
|
|
1122
|
-
// TODO: wrap mdb_stat too
|
|
1123
|
-
// DbiWrap: Get constructor
|
|
1124
|
-
EnvWrap::dbiCtor = new Nan::Persistent<Function>();
|
|
1125
|
-
EnvWrap::dbiCtor->Reset( dbiTpl->GetFunction(Nan::GetCurrentContext()).ToLocalChecked());
|
|
1126
|
-
|
|
1127
|
-
Local<FunctionTemplate> compressionTpl = Nan::New<FunctionTemplate>(Compression::ctor);
|
|
1128
|
-
compressionTpl->SetClassName(Nan::New<String>("Compression").ToLocalChecked());
|
|
1129
|
-
compressionTpl->InstanceTemplate()->SetInternalFieldCount(1);
|
|
1130
|
-
(void)exports->Set(Nan::GetCurrentContext(), Nan::New<String>("Compression").ToLocalChecked(), compressionTpl->GetFunction(Nan::GetCurrentContext()).ToLocalChecked());
|
|
1131
|
-
|
|
1132
|
-
// Set exports
|
|
1133
|
-
(void)exports->Set(Nan::GetCurrentContext(), Nan::New<String>("Env").ToLocalChecked(), envTpl->GetFunction(Nan::GetCurrentContext()).ToLocalChecked());
|
|
1134
|
-
}
|
|
1
|
+
|
|
2
|
+
// This file is part of node-lmdb, the Node.js binding for lmdb
|
|
3
|
+
// Copyright (c) 2013-2017 Timur Kristóf
|
|
4
|
+
// Copyright (c) 2021 Kristopher Tate
|
|
5
|
+
// Licensed to you under the terms of the MIT license
|
|
6
|
+
//
|
|
7
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
// in the Software without restriction, including without limitation the rights
|
|
10
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
// furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
// The above copyright notice and this permission notice shall be included in
|
|
15
|
+
// all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
// THE SOFTWARE.
|
|
24
|
+
|
|
25
|
+
#include "node-lmdb.h"
|
|
26
|
+
|
|
27
|
+
using namespace v8;
|
|
28
|
+
using namespace node;
|
|
29
|
+
|
|
30
|
+
#define IGNORE_NOTFOUND (1)
|
|
31
|
+
thread_local Nan::Persistent<Function>* EnvWrap::txnCtor;
|
|
32
|
+
thread_local Nan::Persistent<Function>* EnvWrap::dbiCtor;
|
|
33
|
+
//Nan::Persistent<Function> EnvWrap::txnCtor;
|
|
34
|
+
//Nan::Persistent<Function> EnvWrap::dbiCtor;
|
|
35
|
+
uv_mutex_t* EnvWrap::envsLock = EnvWrap::initMutex();
|
|
36
|
+
std::vector<env_path_t> EnvWrap::envs;
|
|
37
|
+
|
|
38
|
+
uv_mutex_t* EnvWrap::initMutex() {
|
|
39
|
+
uv_mutex_t* mutex = new uv_mutex_t;
|
|
40
|
+
uv_mutex_init(mutex);
|
|
41
|
+
return mutex;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
EnvWrap::EnvWrap() {
|
|
45
|
+
this->env = nullptr;
|
|
46
|
+
this->currentWriteTxn = nullptr;
|
|
47
|
+
this->currentBatchTxn = nullptr;
|
|
48
|
+
this->currentReadTxn = nullptr;
|
|
49
|
+
this->readTxnRenewed = false;
|
|
50
|
+
this->winMemoryPriority = 5;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
EnvWrap::~EnvWrap() {
|
|
54
|
+
// Close if not closed already
|
|
55
|
+
if (this->env) {
|
|
56
|
+
this->cleanupStrayTxns();
|
|
57
|
+
mdb_env_close(env);
|
|
58
|
+
}
|
|
59
|
+
if (this->compression)
|
|
60
|
+
this->compression->Unref();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
void EnvWrap::cleanupStrayTxns() {
|
|
64
|
+
if (this->currentWriteTxn) {
|
|
65
|
+
mdb_txn_abort(this->currentWriteTxn->txn);
|
|
66
|
+
this->currentWriteTxn->removeFromEnvWrap();
|
|
67
|
+
}
|
|
68
|
+
while (this->readTxns.size()) {
|
|
69
|
+
TxnWrap *tw = *this->readTxns.begin();
|
|
70
|
+
mdb_txn_abort(tw->txn);
|
|
71
|
+
tw->removeFromEnvWrap();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
NAN_METHOD(EnvWrap::ctor) {
|
|
76
|
+
Nan::HandleScope scope;
|
|
77
|
+
|
|
78
|
+
int rc;
|
|
79
|
+
|
|
80
|
+
EnvWrap* ew = new EnvWrap();
|
|
81
|
+
rc = mdb_env_create(&(ew->env));
|
|
82
|
+
|
|
83
|
+
if (rc != 0) {
|
|
84
|
+
mdb_env_close(ew->env);
|
|
85
|
+
return throwLmdbError(rc);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
ew->Wrap(info.This());
|
|
89
|
+
ew->Ref();
|
|
90
|
+
|
|
91
|
+
return info.GetReturnValue().Set(info.This());
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
template<class T>
|
|
95
|
+
int applyUint32Setting(int (*f)(MDB_env *, T), MDB_env* e, Local<Object> options, T dflt, const char* keyName) {
|
|
96
|
+
int rc;
|
|
97
|
+
const Local<Value> value = options->Get(Nan::GetCurrentContext(), Nan::New<String>(keyName).ToLocalChecked()).ToLocalChecked();
|
|
98
|
+
if (value->IsUint32()) {
|
|
99
|
+
rc = f(e, value->Uint32Value(Nan::GetCurrentContext()).FromJust());
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
rc = f(e, dflt);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return rc;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
class SyncWorker : public Nan::AsyncWorker {
|
|
109
|
+
public:
|
|
110
|
+
SyncWorker(MDB_env* env, Nan::Callback *callback)
|
|
111
|
+
: Nan::AsyncWorker(callback), env(env) {}
|
|
112
|
+
|
|
113
|
+
void Execute() {
|
|
114
|
+
int rc = mdb_env_sync(env, 1);
|
|
115
|
+
if (rc != 0) {
|
|
116
|
+
SetErrorMessage(mdb_strerror(rc));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
void HandleOKCallback() {
|
|
121
|
+
Nan::HandleScope scope;
|
|
122
|
+
Local<v8::Value> argv[] = {
|
|
123
|
+
Nan::Null()
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
callback->Call(1, argv, async_resource);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private:
|
|
130
|
+
MDB_env* env;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
class CopyWorker : public Nan::AsyncWorker {
|
|
134
|
+
public:
|
|
135
|
+
CopyWorker(MDB_env* env, char* inPath, int flags, Nan::Callback *callback)
|
|
136
|
+
: Nan::AsyncWorker(callback), env(env), path(strdup(inPath)), flags(flags) {
|
|
137
|
+
}
|
|
138
|
+
~CopyWorker() {
|
|
139
|
+
free(path);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
void Execute() {
|
|
143
|
+
int rc = mdb_env_copy2(env, path, flags);
|
|
144
|
+
if (rc != 0) {
|
|
145
|
+
fprintf(stderr, "Error on copy code: %u\n", rc);
|
|
146
|
+
SetErrorMessage("Error on copy");
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
void HandleOKCallback() {
|
|
151
|
+
Nan::HandleScope scope;
|
|
152
|
+
Local<v8::Value> argv[] = {
|
|
153
|
+
Nan::Null()
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
callback->Call(1, argv, async_resource);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private:
|
|
160
|
+
MDB_env* env;
|
|
161
|
+
char* path;
|
|
162
|
+
int flags;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const int CHANGE_DB = 8;
|
|
166
|
+
const int RESET_CONDITION = 9;
|
|
167
|
+
const int USER_TRANSACTION_CALLBACK = 12;
|
|
168
|
+
const int CONDITION = 1;
|
|
169
|
+
const int WRITE_WITH_VALUE = 2;
|
|
170
|
+
const int DELETE_OPERATION = 4;
|
|
171
|
+
|
|
172
|
+
const int FAILED_CONDITION = 1;
|
|
173
|
+
const int SUCCESSFUL_OPERATION = 0;
|
|
174
|
+
const int BAD_KEY = 3;
|
|
175
|
+
const int NOT_FOUND = 2;
|
|
176
|
+
|
|
177
|
+
BatchWorkerBase::BatchWorkerBase(Nan::Callback *callback, EnvWrap* envForTxn) : Nan::AsyncProgressWorker(callback, "lmdb:batch"),
|
|
178
|
+
envForTxn(envForTxn) {
|
|
179
|
+
currentTxnWrap = nullptr;
|
|
180
|
+
}
|
|
181
|
+
BatchWorkerBase::~BatchWorkerBase() {
|
|
182
|
+
uv_mutex_destroy(userCallbackLock);
|
|
183
|
+
uv_cond_destroy(userCallbackCond);
|
|
184
|
+
}
|
|
185
|
+
void BatchWorkerBase::ContinueBatch(int rc, bool hasStarted) {
|
|
186
|
+
if (hasStarted) {
|
|
187
|
+
finishedProgress = true;
|
|
188
|
+
currentTxnWrap = envForTxn->currentWriteTxn;
|
|
189
|
+
}
|
|
190
|
+
envForTxn->currentWriteTxn = nullptr;
|
|
191
|
+
uv_mutex_lock(userCallbackLock);
|
|
192
|
+
interruptionStatus = rc;
|
|
193
|
+
uv_cond_signal(userCallbackCond);
|
|
194
|
+
uv_mutex_unlock(userCallbackLock);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
class BatchWorker : public BatchWorkerBase {
|
|
198
|
+
public:
|
|
199
|
+
BatchWorker(MDB_env* env, action_t *actions, int actionCount, int putFlags, KeySpace* keySpace, EnvWrap* envForTxn, uint8_t* results, Nan::Callback *callback)
|
|
200
|
+
: BatchWorkerBase(callback, envForTxn),
|
|
201
|
+
env(env),
|
|
202
|
+
actionCount(actionCount),
|
|
203
|
+
results(results),
|
|
204
|
+
actions(actions),
|
|
205
|
+
putFlags(putFlags),
|
|
206
|
+
keySpace(keySpace) {
|
|
207
|
+
interruptionStatus = 0;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
~BatchWorker() {
|
|
211
|
+
delete[] actions;
|
|
212
|
+
delete keySpace;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
void Execute(const ExecutionProgress& executionProgress) {
|
|
216
|
+
MDB_txn *txn;
|
|
217
|
+
// we do compression in this thread to offload from main thread, but do it before transaction to minimize time that the transaction is open
|
|
218
|
+
DbiWrap* dw;
|
|
219
|
+
|
|
220
|
+
for (int i = 0; i < actionCount; i++) {
|
|
221
|
+
action_t* action = &actions[i];
|
|
222
|
+
int actionType = action->actionType;
|
|
223
|
+
if (actionType == CHANGE_DB)
|
|
224
|
+
dw = action->dw;
|
|
225
|
+
else if (actionType & WRITE_WITH_VALUE) {
|
|
226
|
+
Compression* compression = dw->compression;
|
|
227
|
+
if (compression) {
|
|
228
|
+
action->freeValue = compression->compress(&action->data, action->freeValue);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
int rc = mdb_txn_begin(env, nullptr, 0, &txn);
|
|
234
|
+
if (rc != 0) {
|
|
235
|
+
return SetErrorMessage(mdb_strerror(rc));
|
|
236
|
+
}
|
|
237
|
+
if (envForTxn) {
|
|
238
|
+
envForTxn->currentBatchTxn = txn;
|
|
239
|
+
userCallbackLock = new uv_mutex_t;
|
|
240
|
+
userCallbackCond = new uv_cond_t;
|
|
241
|
+
uv_mutex_init(userCallbackLock);
|
|
242
|
+
uv_cond_init(userCallbackCond);
|
|
243
|
+
}
|
|
244
|
+
int validatedDepth = 0;
|
|
245
|
+
int conditionDepth = 0;
|
|
246
|
+
lowerMemPriority(envForTxn);
|
|
247
|
+
for (int i = 0; i < actionCount;) {
|
|
248
|
+
action_t* action = &actions[i];
|
|
249
|
+
int actionType = action->actionType;
|
|
250
|
+
if (actionType >= 8) {
|
|
251
|
+
if (actionType == CHANGE_DB) {
|
|
252
|
+
// reset target db
|
|
253
|
+
dw = action->dw;
|
|
254
|
+
} else if (actionType == RESET_CONDITION) {
|
|
255
|
+
// reset last condition
|
|
256
|
+
conditionDepth--;
|
|
257
|
+
if (validatedDepth > conditionDepth)
|
|
258
|
+
validatedDepth--;
|
|
259
|
+
} else/* if (actionType == USER_TRANSACTION_CALLBACK) */{
|
|
260
|
+
uv_mutex_lock(userCallbackLock);
|
|
261
|
+
finishedProgress = false;
|
|
262
|
+
executionProgress.Send(reinterpret_cast<const char*>(&i), sizeof(int));
|
|
263
|
+
waitForCallback:
|
|
264
|
+
if (interruptionStatus == 0)
|
|
265
|
+
uv_cond_wait(userCallbackCond, userCallbackLock);
|
|
266
|
+
if (interruptionStatus != 0 && !finishedProgress) {
|
|
267
|
+
if (interruptionStatus == INTERRUPT_BATCH) { // interrupted by JS code that wants to run a synchronous transaction
|
|
268
|
+
rc = mdb_txn_commit(txn);
|
|
269
|
+
if (rc == 0) {
|
|
270
|
+
// wait again until the sync transaction is completed
|
|
271
|
+
uv_cond_wait(userCallbackCond, userCallbackLock);
|
|
272
|
+
// now restart our transaction
|
|
273
|
+
rc = mdb_txn_begin(env, nullptr, 0, &txn);
|
|
274
|
+
envForTxn->currentBatchTxn = txn;
|
|
275
|
+
interruptionStatus = 0;
|
|
276
|
+
uv_cond_signal(userCallbackCond);
|
|
277
|
+
goto waitForCallback;
|
|
278
|
+
}
|
|
279
|
+
if (rc != 0) {
|
|
280
|
+
uv_mutex_unlock(userCallbackLock);
|
|
281
|
+
return SetErrorMessage(mdb_strerror(rc));
|
|
282
|
+
}
|
|
283
|
+
} else {
|
|
284
|
+
uv_mutex_unlock(userCallbackLock);
|
|
285
|
+
rc = interruptionStatus;
|
|
286
|
+
goto done;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
uv_mutex_unlock(userCallbackLock);
|
|
290
|
+
}
|
|
291
|
+
results[i++] = SUCCESSFUL_OPERATION;
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
bool validated;
|
|
295
|
+
if (validatedDepth < conditionDepth) {
|
|
296
|
+
// we are in an invalidated branch, just need to track depth
|
|
297
|
+
results[i] = FAILED_CONDITION;
|
|
298
|
+
validated = false;
|
|
299
|
+
} else if (actionType & CONDITION) { // has precondition
|
|
300
|
+
MDB_val value;
|
|
301
|
+
// TODO: Use a cursor
|
|
302
|
+
rc = mdb_get(txn, dw->dbi, &action->key, &value);
|
|
303
|
+
if (rc == MDB_BAD_VALSIZE) {
|
|
304
|
+
results[i] = BAD_KEY;
|
|
305
|
+
validated = false;
|
|
306
|
+
} else {
|
|
307
|
+
if (action->ifVersion == NO_EXIST_VERSION) {
|
|
308
|
+
validated = rc;
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
if (rc)
|
|
312
|
+
validated = false;
|
|
313
|
+
else
|
|
314
|
+
validated = action->ifVersion == *((double*)value.mv_data);
|
|
315
|
+
}
|
|
316
|
+
results[i] = validated ? SUCCESSFUL_OPERATION : FAILED_CONDITION;
|
|
317
|
+
}
|
|
318
|
+
rc = 0;
|
|
319
|
+
} else {
|
|
320
|
+
validated = true;
|
|
321
|
+
results[i] = SUCCESSFUL_OPERATION;
|
|
322
|
+
}
|
|
323
|
+
if (actionType & (WRITE_WITH_VALUE | DELETE_OPERATION)) { // has write operation to perform
|
|
324
|
+
if (validated) {
|
|
325
|
+
if (actionType & DELETE_OPERATION) {
|
|
326
|
+
rc = mdb_del(txn, dw->dbi, &action->key, (actionType & WRITE_WITH_VALUE) ? &action->data : nullptr);
|
|
327
|
+
if (rc == MDB_NOTFOUND) {
|
|
328
|
+
rc = 0; // ignore not_found errors
|
|
329
|
+
results[i] = NOT_FOUND;
|
|
330
|
+
}
|
|
331
|
+
} else {
|
|
332
|
+
if (dw->hasVersions)
|
|
333
|
+
rc = putWithVersion(txn, dw->dbi, &action->key, &action->data, putFlags, action->version);
|
|
334
|
+
else
|
|
335
|
+
rc = mdb_put(txn, dw->dbi, &action->key, &action->data, putFlags);
|
|
336
|
+
}
|
|
337
|
+
if (rc != 0) {
|
|
338
|
+
if (rc == MDB_BAD_VALSIZE) {
|
|
339
|
+
results[i] = BAD_KEY;
|
|
340
|
+
rc = 0;
|
|
341
|
+
} else {
|
|
342
|
+
goto done;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (action->freeValue) {
|
|
347
|
+
action->freeValue(action->data);
|
|
348
|
+
}
|
|
349
|
+
} else {
|
|
350
|
+
// starting condition branch
|
|
351
|
+
conditionDepth++;
|
|
352
|
+
if (validated)
|
|
353
|
+
validatedDepth++;
|
|
354
|
+
}
|
|
355
|
+
i++;
|
|
356
|
+
}
|
|
357
|
+
done:
|
|
358
|
+
if (envForTxn) {
|
|
359
|
+
envForTxn->currentBatchTxn = nullptr;
|
|
360
|
+
if (currentTxnWrap) {
|
|
361
|
+
// if a transaction was wrapped, need to do clean up
|
|
362
|
+
currentTxnWrap->removeFromEnvWrap();
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (rc)
|
|
366
|
+
mdb_txn_abort(txn);
|
|
367
|
+
else
|
|
368
|
+
rc = mdb_txn_commit(txn);
|
|
369
|
+
restoreMemPriority(envForTxn);
|
|
370
|
+
if (rc != 0) {
|
|
371
|
+
if ((putFlags & 1) > 0) // sync mode
|
|
372
|
+
return Nan::ThrowError(mdb_strerror(rc));
|
|
373
|
+
else {
|
|
374
|
+
return SetErrorMessage(mdb_strerror(rc));
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
void HandleProgressCallback(const char* data, size_t count) {
|
|
380
|
+
Nan::HandleScope scope;
|
|
381
|
+
if (interruptionStatus != 0) {
|
|
382
|
+
uv_mutex_lock(userCallbackLock);
|
|
383
|
+
if (interruptionStatus != 0)
|
|
384
|
+
uv_cond_wait(userCallbackCond, userCallbackLock);
|
|
385
|
+
// aquire the lock so that we can ensure that if it is restarting the transaction, it finishes doing that
|
|
386
|
+
uv_mutex_unlock(userCallbackLock);
|
|
387
|
+
}
|
|
388
|
+
v8::Local<v8::Value> argv[] = {
|
|
389
|
+
Nan::True()
|
|
390
|
+
};
|
|
391
|
+
envForTxn->currentWriteTxn = currentTxnWrap;
|
|
392
|
+
bool immediateContinue = callback->Call(1, argv, async_resource).ToLocalChecked()->IsTrue();
|
|
393
|
+
if (immediateContinue)
|
|
394
|
+
ContinueBatch(0, true);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
void HandleOKCallback() {
|
|
398
|
+
Nan::HandleScope scope;
|
|
399
|
+
Local<v8::Value> argv[] = {
|
|
400
|
+
Nan::Null(),
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
callback->Call(1, argv, async_resource);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
private:
|
|
407
|
+
MDB_env* env;
|
|
408
|
+
int actionCount;
|
|
409
|
+
uint8_t* results;
|
|
410
|
+
int resultIndex = 0;
|
|
411
|
+
action_t* actions;
|
|
412
|
+
int putFlags;
|
|
413
|
+
KeySpace* keySpace;
|
|
414
|
+
friend class DbiWrap;
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
MDB_txn* EnvWrap::getReadTxn() {
|
|
418
|
+
MDB_txn* txn = currentWriteTxn ? currentWriteTxn->txn : nullptr;
|
|
419
|
+
if (txn)
|
|
420
|
+
return txn;
|
|
421
|
+
txn = currentReadTxn;
|
|
422
|
+
if (readTxnRenewed)
|
|
423
|
+
return txn;
|
|
424
|
+
if (txn)
|
|
425
|
+
mdb_txn_renew(txn);
|
|
426
|
+
else {
|
|
427
|
+
mdb_txn_begin(env, nullptr, MDB_RDONLY, &txn);
|
|
428
|
+
currentReadTxn = txn;
|
|
429
|
+
}
|
|
430
|
+
readTxnRenewed = true;
|
|
431
|
+
Local<v8::Value> argv[] = {
|
|
432
|
+
Nan::Null()
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
(new Nan::Callback(onReadTxnRenew.Get(Isolate::GetCurrent())))->Call(1, argv);
|
|
436
|
+
return txn;
|
|
437
|
+
}
|
|
438
|
+
static int encfunc(const MDB_val* src, MDB_val* dst, const MDB_val* key, int encdec)
|
|
439
|
+
{
|
|
440
|
+
chacha8(src->mv_data, src->mv_size, (uint8_t*) key[0].mv_data, (uint8_t*) key[1].mv_data, (char*)dst->mv_data);
|
|
441
|
+
return 0;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
NAN_METHOD(EnvWrap::open) {
|
|
445
|
+
Nan::HandleScope scope;
|
|
446
|
+
|
|
447
|
+
int rc;
|
|
448
|
+
int flags = 0;
|
|
449
|
+
|
|
450
|
+
// Get the wrapper
|
|
451
|
+
EnvWrap *ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
452
|
+
|
|
453
|
+
if (!ew->env) {
|
|
454
|
+
return Nan::ThrowError("The environment is already closed.");
|
|
455
|
+
}
|
|
456
|
+
Local<Object> options = Local<Object>::Cast(info[0]);
|
|
457
|
+
ew->compression = nullptr;
|
|
458
|
+
Local<Value> compressionOption = options->Get(Nan::GetCurrentContext(), Nan::New<String>("compression").ToLocalChecked()).ToLocalChecked();
|
|
459
|
+
if (compressionOption->IsObject()) {
|
|
460
|
+
ew->compression = Nan::ObjectWrap::Unwrap<Compression>(Nan::To<Object>(compressionOption).ToLocalChecked());
|
|
461
|
+
ew->compression->Ref();
|
|
462
|
+
}
|
|
463
|
+
Local<Value> syncInstructionsValue = options->Get(Nan::GetCurrentContext(), Nan::New<String>("syncInstructions").ToLocalChecked()).ToLocalChecked();
|
|
464
|
+
if (syncInstructionsValue->IsArrayBufferView())
|
|
465
|
+
ew->syncInstructions = node::Buffer::Data(syncInstructionsValue);
|
|
466
|
+
|
|
467
|
+
Local<Value> onReadTxnRenew = options->Get(Nan::GetCurrentContext(), Nan::New<String>("onReadTxnRenew").ToLocalChecked()).ToLocalChecked();
|
|
468
|
+
ew->onReadTxnRenew.Reset(Local<Function>::Cast(onReadTxnRenew));
|
|
469
|
+
Local<Value> winMemoryPriorityLocal = options->Get(Nan::GetCurrentContext(), Nan::New<String>("winMemoryPriority").ToLocalChecked()).ToLocalChecked();
|
|
470
|
+
if (winMemoryPriorityLocal->IsNumber())
|
|
471
|
+
ew->winMemoryPriority = winMemoryPriorityLocal->IntegerValue(Nan::GetCurrentContext()).FromJust();
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
Local<String> path = Local<String>::Cast(options->Get(Nan::GetCurrentContext(), Nan::New<String>("path").ToLocalChecked()).ToLocalChecked());
|
|
475
|
+
Nan::Utf8String charPath(path);
|
|
476
|
+
uv_mutex_lock(envsLock);
|
|
477
|
+
for (env_path_t envPath : envs) {
|
|
478
|
+
char* existingPath = envPath.path;
|
|
479
|
+
if (!strcmp(existingPath, *charPath)) {
|
|
480
|
+
envPath.count++;
|
|
481
|
+
mdb_env_close(ew->env);
|
|
482
|
+
ew->env = envPath.env;
|
|
483
|
+
uv_mutex_unlock(envsLock);
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// Parse the maxDbs option
|
|
489
|
+
rc = applyUint32Setting<unsigned>(&mdb_env_set_maxdbs, ew->env, options, 1, "maxDbs");
|
|
490
|
+
if (rc != 0) {
|
|
491
|
+
uv_mutex_unlock(envsLock);
|
|
492
|
+
return throwLmdbError(rc);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// Parse the mapSize option
|
|
496
|
+
Local<Value> mapSizeOption = options->Get(Nan::GetCurrentContext(), Nan::New<String>("mapSize").ToLocalChecked()).ToLocalChecked();
|
|
497
|
+
if (mapSizeOption->IsNumber()) {
|
|
498
|
+
mdb_size_t mapSizeSizeT = mapSizeOption->IntegerValue(Nan::GetCurrentContext()).FromJust();
|
|
499
|
+
rc = mdb_env_set_mapsize(ew->env, mapSizeSizeT);
|
|
500
|
+
if (rc != 0) {
|
|
501
|
+
uv_mutex_unlock(envsLock);
|
|
502
|
+
return throwLmdbError(rc);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
Local<Value> encryptionKey = options->Get(Nan::GetCurrentContext(), Nan::New<String>("encryptionKey").ToLocalChecked()).ToLocalChecked();
|
|
507
|
+
if (!encryptionKey->IsUndefined()) {
|
|
508
|
+
MDB_val enckey;
|
|
509
|
+
KeySpace* keySpace = new KeySpace(false);
|
|
510
|
+
rc = valueToMDBKey(encryptionKey, enckey, *keySpace);
|
|
511
|
+
if (!rc)
|
|
512
|
+
return Nan::ThrowError("Bad encryption key");
|
|
513
|
+
if (enckey.mv_size != 32) {
|
|
514
|
+
return Nan::ThrowError("Encryption key must be 32 bytes long");
|
|
515
|
+
}
|
|
516
|
+
rc = mdb_env_set_encrypt(ew->env, encfunc, &enckey, 0);
|
|
517
|
+
if (rc != 0) {
|
|
518
|
+
return throwLmdbError(rc);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// Parse the maxReaders option
|
|
523
|
+
// NOTE: mdb.c defines DEFAULT_READERS as 126
|
|
524
|
+
rc = applyUint32Setting<unsigned>(&mdb_env_set_maxreaders, ew->env, options, 126, "maxReaders");
|
|
525
|
+
if (rc != 0) {
|
|
526
|
+
return throwLmdbError(rc);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
// Parse the pageSize option
|
|
530
|
+
// default is 4096
|
|
531
|
+
rc = applyUint32Setting<int>(&mdb_env_set_pagesize, ew->env, options, 4096, "pageSize");
|
|
532
|
+
if (rc != 0) {
|
|
533
|
+
return throwLmdbError(rc);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// NOTE: MDB_FIXEDMAP is not exposed here since it is "highly experimental" + it is irrelevant for this use case
|
|
537
|
+
// NOTE: MDB_NOTLS is not exposed here because it is irrelevant for this use case, as node will run all this on a single thread anyway
|
|
538
|
+
setFlagFromValue(&flags, MDB_NOSUBDIR, "noSubdir", false, options);
|
|
539
|
+
setFlagFromValue(&flags, MDB_RDONLY, "readOnly", false, options);
|
|
540
|
+
setFlagFromValue(&flags, MDB_WRITEMAP, "useWritemap", false, options);
|
|
541
|
+
setFlagFromValue(&flags, MDB_PREVSNAPSHOT, "usePreviousSnapshot", false, options);
|
|
542
|
+
setFlagFromValue(&flags, MDB_NOMEMINIT , "noMemInit", false, options);
|
|
543
|
+
setFlagFromValue(&flags, MDB_NORDAHEAD , "noReadAhead", false, options);
|
|
544
|
+
setFlagFromValue(&flags, MDB_NOMETASYNC, "noMetaSync", false, options);
|
|
545
|
+
setFlagFromValue(&flags, MDB_NOSYNC, "noSync", false, options);
|
|
546
|
+
setFlagFromValue(&flags, MDB_MAPASYNC, "mapAsync", false, options);
|
|
547
|
+
setFlagFromValue(&flags, MDB_NOLOCK, "unsafeNoLock", false, options);
|
|
548
|
+
setFlagFromValue(&flags, MDB_REMAP_CHUNKS, "remapChunks", false, options);
|
|
549
|
+
|
|
550
|
+
if (flags & MDB_NOLOCK) {
|
|
551
|
+
fprintf(stderr, "You chose to use MDB_NOLOCK which is not officially supported by node-lmdb. You have been warned!\n");
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// Set MDB_NOTLS to enable multiple read-only transactions on the same thread (in this case, the nodejs main thread)
|
|
555
|
+
flags |= MDB_NOTLS;
|
|
556
|
+
#ifdef _WIN32
|
|
557
|
+
if ((flags & MDB_WRITEMAP) && !(flags & MDB_NOSYNC) && !(flags & MDB_REMAP_CHUNKS)) {
|
|
558
|
+
fprintf(stderr, "Writemaps are currently disabled on Windows doing to issues with syncing\n");
|
|
559
|
+
flags &= ~MDB_WRITEMAP;
|
|
560
|
+
}
|
|
561
|
+
#endif
|
|
562
|
+
lowerMemPriority(ew);
|
|
563
|
+
// TODO: make file attributes configurable
|
|
564
|
+
#if NODE_VERSION_AT_LEAST(12,0,0)
|
|
565
|
+
rc = mdb_env_open(ew->env, *String::Utf8Value(Isolate::GetCurrent(), path), flags, 0664);
|
|
566
|
+
#else
|
|
567
|
+
rc = mdb_env_open(ew->env, *String::Utf8Value(path), flags, 0664);
|
|
568
|
+
#endif
|
|
569
|
+
restoreMemPriority(ew);
|
|
570
|
+
|
|
571
|
+
if (rc != 0) {
|
|
572
|
+
mdb_env_close(ew->env);
|
|
573
|
+
uv_mutex_unlock(envsLock);
|
|
574
|
+
ew->env = nullptr;
|
|
575
|
+
return throwLmdbError(rc);
|
|
576
|
+
}
|
|
577
|
+
env_path_t envPath;
|
|
578
|
+
envPath.path = strdup(*charPath);
|
|
579
|
+
envPath.env = ew->env;
|
|
580
|
+
envPath.count = 1;
|
|
581
|
+
envs.push_back(envPath);
|
|
582
|
+
uv_mutex_unlock(envsLock);
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
NAN_METHOD(EnvWrap::resize) {
|
|
586
|
+
Nan::HandleScope scope;
|
|
587
|
+
|
|
588
|
+
// Get the wrapper
|
|
589
|
+
EnvWrap *ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
590
|
+
|
|
591
|
+
if (!ew->env) {
|
|
592
|
+
return Nan::ThrowError("The environment is already closed.");
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
// Check that the correct number/type of arguments was given.
|
|
596
|
+
if (info.Length() != 1 || !info[0]->IsNumber()) {
|
|
597
|
+
return Nan::ThrowError("Call env.resize() with exactly one argument which is a number.");
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// Since this function may only be called if no transactions are active in this process, check this condition.
|
|
601
|
+
if (ew->currentWriteTxn/* || ew->readTxns.size()*/) {
|
|
602
|
+
return Nan::ThrowError("Only call env.resize() when there are no active transactions. Please close all transactions before calling env.resize().");
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
mdb_size_t mapSizeSizeT = info[0]->IntegerValue(Nan::GetCurrentContext()).FromJust();
|
|
606
|
+
lowerMemPriority(ew);
|
|
607
|
+
int rc = mdb_env_set_mapsize(ew->env, mapSizeSizeT);
|
|
608
|
+
restoreMemPriority(ew);
|
|
609
|
+
if (rc == EINVAL) {
|
|
610
|
+
//fprintf(stderr, "Resize failed, will try to get transaction and try again");
|
|
611
|
+
MDB_txn *txn;
|
|
612
|
+
rc = mdb_txn_begin(ew->env, nullptr, 0, &txn);
|
|
613
|
+
if (rc != 0)
|
|
614
|
+
return throwLmdbError(rc);
|
|
615
|
+
rc = mdb_txn_commit(txn);
|
|
616
|
+
if (rc != 0)
|
|
617
|
+
return throwLmdbError(rc);
|
|
618
|
+
rc = mdb_env_set_mapsize(ew->env, mapSizeSizeT);
|
|
619
|
+
}
|
|
620
|
+
if (rc != 0) {
|
|
621
|
+
return throwLmdbError(rc);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
NAN_METHOD(EnvWrap::close) {
|
|
626
|
+
EnvWrap *ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
627
|
+
ew->Unref();
|
|
628
|
+
|
|
629
|
+
if (!ew->env) {
|
|
630
|
+
return Nan::ThrowError("The environment is already closed.");
|
|
631
|
+
}
|
|
632
|
+
ew->cleanupStrayTxns();
|
|
633
|
+
|
|
634
|
+
uv_mutex_lock(envsLock);
|
|
635
|
+
for (auto envPath = envs.begin(); envPath != envs.end(); ) {
|
|
636
|
+
if (envPath->env == ew->env) {
|
|
637
|
+
envPath->count--;
|
|
638
|
+
if (envPath->count <= 0) {
|
|
639
|
+
// last thread using it, we can really close it now
|
|
640
|
+
envs.erase(envPath);
|
|
641
|
+
mdb_env_close(ew->env);
|
|
642
|
+
}
|
|
643
|
+
break;
|
|
644
|
+
}
|
|
645
|
+
++envPath;
|
|
646
|
+
}
|
|
647
|
+
uv_mutex_unlock(envsLock);
|
|
648
|
+
|
|
649
|
+
ew->env = nullptr;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
NAN_METHOD(EnvWrap::stat) {
|
|
653
|
+
Nan::HandleScope scope;
|
|
654
|
+
|
|
655
|
+
// Get the wrapper
|
|
656
|
+
EnvWrap *ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
657
|
+
if (!ew->env) {
|
|
658
|
+
return Nan::ThrowError("The environment is already closed.");
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
int rc;
|
|
662
|
+
MDB_stat stat;
|
|
663
|
+
|
|
664
|
+
rc = mdb_env_stat(ew->env, &stat);
|
|
665
|
+
if (rc != 0) {
|
|
666
|
+
return throwLmdbError(rc);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
Local<Context> context = Nan::GetCurrentContext();
|
|
670
|
+
Local<Object> obj = Nan::New<Object>();
|
|
671
|
+
(void)obj->Set(context, Nan::New<String>("pageSize").ToLocalChecked(), Nan::New<Number>(stat.ms_psize));
|
|
672
|
+
(void)obj->Set(context, Nan::New<String>("treeDepth").ToLocalChecked(), Nan::New<Number>(stat.ms_depth));
|
|
673
|
+
(void)obj->Set(context, Nan::New<String>("treeBranchPageCount").ToLocalChecked(), Nan::New<Number>(stat.ms_branch_pages));
|
|
674
|
+
(void)obj->Set(context, Nan::New<String>("treeLeafPageCount").ToLocalChecked(), Nan::New<Number>(stat.ms_leaf_pages));
|
|
675
|
+
(void)obj->Set(context, Nan::New<String>("entryCount").ToLocalChecked(), Nan::New<Number>(stat.ms_entries));
|
|
676
|
+
(void)obj->Set(context, Nan::New<String>("overflowPages").ToLocalChecked(), Nan::New<Number>(stat.ms_overflow_pages));
|
|
677
|
+
|
|
678
|
+
info.GetReturnValue().Set(obj);
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
NAN_METHOD(EnvWrap::freeStat) {
|
|
682
|
+
Nan::HandleScope scope;
|
|
683
|
+
|
|
684
|
+
// Get the wrapper
|
|
685
|
+
EnvWrap *ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
686
|
+
if (!ew->env) {
|
|
687
|
+
return Nan::ThrowError("The environment is already closed.");
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
if (info.Length() != 1) {
|
|
691
|
+
return Nan::ThrowError("env.freeStat should be called with a single argument which is a txn.");
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
TxnWrap *txn = Nan::ObjectWrap::Unwrap<TxnWrap>(Local<Object>::Cast(info[0]));
|
|
695
|
+
|
|
696
|
+
int rc;
|
|
697
|
+
MDB_stat stat;
|
|
698
|
+
|
|
699
|
+
rc = mdb_stat(txn->txn, 0, &stat);
|
|
700
|
+
if (rc != 0) {
|
|
701
|
+
return throwLmdbError(rc);
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
Local<Context> context = Nan::GetCurrentContext();
|
|
705
|
+
Local<Object> obj = Nan::New<Object>();
|
|
706
|
+
(void)obj->Set(context, Nan::New<String>("pageSize").ToLocalChecked(), Nan::New<Number>(stat.ms_psize));
|
|
707
|
+
(void)obj->Set(context, Nan::New<String>("treeDepth").ToLocalChecked(), Nan::New<Number>(stat.ms_depth));
|
|
708
|
+
(void)obj->Set(context, Nan::New<String>("treeBranchPageCount").ToLocalChecked(), Nan::New<Number>(stat.ms_branch_pages));
|
|
709
|
+
(void)obj->Set(context, Nan::New<String>("treeLeafPageCount").ToLocalChecked(), Nan::New<Number>(stat.ms_leaf_pages));
|
|
710
|
+
(void)obj->Set(context, Nan::New<String>("entryCount").ToLocalChecked(), Nan::New<Number>(stat.ms_entries));
|
|
711
|
+
(void)obj->Set(context, Nan::New<String>("overflowPages").ToLocalChecked(), Nan::New<Number>(stat.ms_overflow_pages));
|
|
712
|
+
|
|
713
|
+
info.GetReturnValue().Set(obj);
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
NAN_METHOD(EnvWrap::info) {
|
|
717
|
+
Nan::HandleScope scope;
|
|
718
|
+
|
|
719
|
+
// Get the wrapper
|
|
720
|
+
EnvWrap *ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
721
|
+
if (!ew->env) {
|
|
722
|
+
return Nan::ThrowError("The environment is already closed.");
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
int rc;
|
|
726
|
+
MDB_envinfo envinfo;
|
|
727
|
+
|
|
728
|
+
rc = mdb_env_info(ew->env, &envinfo);
|
|
729
|
+
if (rc != 0) {
|
|
730
|
+
return throwLmdbError(rc);
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
Local<Context> context = Nan::GetCurrentContext();
|
|
734
|
+
Local<Object> obj = Nan::New<Object>();
|
|
735
|
+
(void)obj->Set(context, Nan::New<String>("mapAddress").ToLocalChecked(), Nan::New<Number>((uint64_t) envinfo.me_mapaddr));
|
|
736
|
+
(void)obj->Set(context, Nan::New<String>("mapSize").ToLocalChecked(), Nan::New<Number>(envinfo.me_mapsize));
|
|
737
|
+
(void)obj->Set(context, Nan::New<String>("lastPageNumber").ToLocalChecked(), Nan::New<Number>(envinfo.me_last_pgno));
|
|
738
|
+
(void)obj->Set(context, Nan::New<String>("lastTxnId").ToLocalChecked(), Nan::New<Number>(envinfo.me_last_txnid));
|
|
739
|
+
(void)obj->Set(context, Nan::New<String>("maxReaders").ToLocalChecked(), Nan::New<Number>(envinfo.me_maxreaders));
|
|
740
|
+
(void)obj->Set(context, Nan::New<String>("numReaders").ToLocalChecked(), Nan::New<Number>(envinfo.me_numreaders));
|
|
741
|
+
|
|
742
|
+
info.GetReturnValue().Set(obj);
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
NAN_METHOD(EnvWrap::readerCheck) {
|
|
746
|
+
Nan::HandleScope scope;
|
|
747
|
+
|
|
748
|
+
// Get the wrapper
|
|
749
|
+
EnvWrap *ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
750
|
+
if (!ew->env) {
|
|
751
|
+
return Nan::ThrowError("The environment is already closed.");
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
int rc, dead;
|
|
755
|
+
rc = mdb_reader_check(ew->env, &dead);
|
|
756
|
+
if (rc != 0) {
|
|
757
|
+
return throwLmdbError(rc);
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
info.GetReturnValue().Set(Nan::New<Number>(dead));
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
Local<Array> readerStrings;
|
|
764
|
+
MDB_msg_func* printReaders = ([](const char* message, void* ctx) -> int {
|
|
765
|
+
readerStrings->Set(Nan::GetCurrentContext(), readerStrings->Length(), Nan::New<String>(message).ToLocalChecked());
|
|
766
|
+
return 0;
|
|
767
|
+
});
|
|
768
|
+
|
|
769
|
+
NAN_METHOD(EnvWrap::readerList) {
|
|
770
|
+
Nan::HandleScope scope;
|
|
771
|
+
|
|
772
|
+
// Get the wrapper
|
|
773
|
+
EnvWrap* ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
774
|
+
if (!ew->env) {
|
|
775
|
+
return Nan::ThrowError("The environment is already closed.");
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
readerStrings = Nan::New<Array>(0);
|
|
779
|
+
int rc;
|
|
780
|
+
rc = mdb_reader_list(ew->env, printReaders, nullptr);
|
|
781
|
+
if (rc != 0) {
|
|
782
|
+
return throwLmdbError(rc);
|
|
783
|
+
}
|
|
784
|
+
info.GetReturnValue().Set(readerStrings);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
NAN_METHOD(EnvWrap::copy) {
|
|
789
|
+
Nan::HandleScope scope;
|
|
790
|
+
|
|
791
|
+
// Get the wrapper
|
|
792
|
+
EnvWrap *ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
793
|
+
|
|
794
|
+
if (!ew->env) {
|
|
795
|
+
return Nan::ThrowError("The environment is already closed.");
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
// Check that the correct number/type of arguments was given.
|
|
799
|
+
if (!info[0]->IsString()) {
|
|
800
|
+
return Nan::ThrowError("Call env.copy(path, compact?, callback) with a file path.");
|
|
801
|
+
}
|
|
802
|
+
if (!info[info.Length() - 1]->IsFunction()) {
|
|
803
|
+
return Nan::ThrowError("Call env.copy(path, compact?, callback) with a file path.");
|
|
804
|
+
}
|
|
805
|
+
Nan::Utf8String path(info[0].As<String>());
|
|
806
|
+
|
|
807
|
+
int flags = 0;
|
|
808
|
+
if (info.Length() > 1 && info[1]->IsTrue()) {
|
|
809
|
+
flags = MDB_CP_COMPACT;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
Nan::Callback* callback = new Nan::Callback(
|
|
813
|
+
Local<v8::Function>::Cast(info[info.Length() > 2 ? 2 : 1])
|
|
814
|
+
);
|
|
815
|
+
|
|
816
|
+
CopyWorker* worker = new CopyWorker(
|
|
817
|
+
ew->env, *path, flags, callback
|
|
818
|
+
);
|
|
819
|
+
|
|
820
|
+
Nan::AsyncQueueWorker(worker);
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
NAN_METHOD(EnvWrap::detachBuffer) {
|
|
824
|
+
Nan::HandleScope scope;
|
|
825
|
+
#if NODE_VERSION_AT_LEAST(12,0,0)
|
|
826
|
+
Local<v8::ArrayBuffer>::Cast(info[0])->Detach();
|
|
827
|
+
#endif
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
NAN_METHOD(EnvWrap::beginTxn) {
|
|
831
|
+
Nan::HandleScope scope;
|
|
832
|
+
|
|
833
|
+
Nan::MaybeLocal<Object> maybeInstance;
|
|
834
|
+
|
|
835
|
+
if (info.Length() > 1) {
|
|
836
|
+
const int argc = 3;
|
|
837
|
+
|
|
838
|
+
Local<Value> argv[argc] = { info.This(), info[0], info[1] };
|
|
839
|
+
maybeInstance = Nan::NewInstance(Nan::New(*txnCtor), argc, argv);
|
|
840
|
+
|
|
841
|
+
} else {
|
|
842
|
+
const int argc = 2;
|
|
843
|
+
|
|
844
|
+
Local<Value> argv[argc] = { info.This(), info[0] };
|
|
845
|
+
maybeInstance = Nan::NewInstance(Nan::New(*txnCtor), argc, argv);
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
// Check if txn could be created
|
|
849
|
+
if ((maybeInstance.IsEmpty())) {
|
|
850
|
+
// The maybeInstance is empty because the txnCtor called Nan::ThrowError.
|
|
851
|
+
// No need to call that here again, the user will get the error thrown there.
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
Local<Object> instance = maybeInstance.ToLocalChecked();
|
|
856
|
+
info.GetReturnValue().Set(instance);
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
NAN_METHOD(EnvWrap::openDbi) {
|
|
860
|
+
Nan::HandleScope scope;
|
|
861
|
+
|
|
862
|
+
const unsigned argc = 2;
|
|
863
|
+
Local<Value> argv[argc] = { info.This(), info[0] };
|
|
864
|
+
Nan::MaybeLocal<Object> maybeInstance = Nan::NewInstance(Nan::New(*dbiCtor), argc, argv);
|
|
865
|
+
|
|
866
|
+
// Check if database could be opened
|
|
867
|
+
if ((maybeInstance.IsEmpty())) {
|
|
868
|
+
// The maybeInstance is empty because the dbiCtor called Nan::ThrowError.
|
|
869
|
+
// No need to call that here again, the user will get the error thrown there.
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
Local<Object> instance = maybeInstance.ToLocalChecked();
|
|
874
|
+
info.GetReturnValue().Set(instance);
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
NAN_METHOD(EnvWrap::sync) {
|
|
878
|
+
Nan::HandleScope scope;
|
|
879
|
+
|
|
880
|
+
EnvWrap *ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
881
|
+
|
|
882
|
+
if (!ew->env) {
|
|
883
|
+
return Nan::ThrowError("The environment is already closed.");
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
Nan::Callback* callback = new Nan::Callback(
|
|
887
|
+
Local<v8::Function>::Cast(info[0])
|
|
888
|
+
);
|
|
889
|
+
|
|
890
|
+
SyncWorker* worker = new SyncWorker(
|
|
891
|
+
ew->env, callback
|
|
892
|
+
);
|
|
893
|
+
|
|
894
|
+
Nan::AsyncQueueWorker(worker);
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
NAN_METHOD(EnvWrap::batchWrite) {
|
|
900
|
+
Nan::HandleScope scope;
|
|
901
|
+
|
|
902
|
+
EnvWrap *ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
903
|
+
Local<Context> context = Nan::GetCurrentContext();
|
|
904
|
+
|
|
905
|
+
if (!ew->env) {
|
|
906
|
+
return Nan::ThrowError("The environment is already closed.");
|
|
907
|
+
}
|
|
908
|
+
Local<v8::Array> array = Local<v8::Array>::Cast(info[0]);
|
|
909
|
+
|
|
910
|
+
int length = array->Length();
|
|
911
|
+
action_t* actions = new action_t[length];
|
|
912
|
+
|
|
913
|
+
int putFlags = 0;
|
|
914
|
+
KeySpace* keySpace = new KeySpace(false);
|
|
915
|
+
Nan::Callback* callback;
|
|
916
|
+
uint8_t* results = (uint8_t*) node::Buffer::Data(Local<Object>::Cast(info[1]));
|
|
917
|
+
Local<Value> options = info[2];
|
|
918
|
+
|
|
919
|
+
if (!info[2]->IsNull() && !info[2]->IsUndefined() && info[2]->IsObject() && !info[2]->IsFunction()) {
|
|
920
|
+
Local<Object> optionsObject = Local<Object>::Cast(options);
|
|
921
|
+
setFlagFromValue(&putFlags, MDB_NODUPDATA, "noDupData", false, optionsObject);
|
|
922
|
+
setFlagFromValue(&putFlags, MDB_NOOVERWRITE, "noOverwrite", false, optionsObject);
|
|
923
|
+
setFlagFromValue(&putFlags, MDB_APPEND, "append", false, optionsObject);
|
|
924
|
+
setFlagFromValue(&putFlags, MDB_APPENDDUP, "appendDup", false, optionsObject);
|
|
925
|
+
callback = new Nan::Callback(
|
|
926
|
+
Local<v8::Function>::Cast(info[3])
|
|
927
|
+
);
|
|
928
|
+
} else {
|
|
929
|
+
if (info.Length() > 2 || info[0]->IsFunction())
|
|
930
|
+
callback = new Nan::Callback(
|
|
931
|
+
Local<v8::Function>::Cast(info[2])
|
|
932
|
+
);
|
|
933
|
+
else {
|
|
934
|
+
// sync mode
|
|
935
|
+
putFlags &= 1;
|
|
936
|
+
callback = nullptr;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
BatchWorker* worker = new BatchWorker(
|
|
941
|
+
ew->env, actions, length, putFlags, keySpace, ew, results, callback
|
|
942
|
+
);
|
|
943
|
+
ew->batchWorker = worker;
|
|
944
|
+
bool keyIsValid = false;
|
|
945
|
+
NodeLmdbKeyType keyType;
|
|
946
|
+
DbiWrap* dw;
|
|
947
|
+
|
|
948
|
+
for (unsigned int i = 0; i < array->Length(); i++) {
|
|
949
|
+
//Local<Value> element = array->Get(context, i).ToLocalChecked(); // checked/enforce in js
|
|
950
|
+
//if (!element->IsObject())
|
|
951
|
+
// continue;
|
|
952
|
+
action_t* action = &actions[i];
|
|
953
|
+
Local<Value> operationValue = array->Get(context, i).ToLocalChecked();
|
|
954
|
+
|
|
955
|
+
bool isArray = operationValue->IsArray();
|
|
956
|
+
if (!isArray) {
|
|
957
|
+
// change target db
|
|
958
|
+
if (operationValue->IsObject()) {
|
|
959
|
+
action->actionType = CHANGE_DB;
|
|
960
|
+
dw = action->dw = Nan::ObjectWrap::Unwrap<DbiWrap>(Local<Object>::Cast(operationValue));
|
|
961
|
+
} else if (operationValue->IsTrue()) {
|
|
962
|
+
action->actionType = USER_TRANSACTION_CALLBACK;
|
|
963
|
+
} else { // else false
|
|
964
|
+
// reset condition
|
|
965
|
+
action->actionType = RESET_CONDITION;
|
|
966
|
+
}
|
|
967
|
+
continue;
|
|
968
|
+
// if we did not coordinate to always reference the object on the JS side, we would need this (but it is expensive):
|
|
969
|
+
// worker->SaveToPersistent(persistedIndex++, currentDb);
|
|
970
|
+
}
|
|
971
|
+
Local<Object> operation = Local<Object>::Cast(operationValue);
|
|
972
|
+
Local<v8::Value> key = operation->Get(context, 0).ToLocalChecked();
|
|
973
|
+
|
|
974
|
+
keyType = dw->keyType;
|
|
975
|
+
if (keyType == NodeLmdbKeyType::DefaultKey) {
|
|
976
|
+
keyIsValid = valueToMDBKey(key, action->key, *keySpace);
|
|
977
|
+
}
|
|
978
|
+
else {
|
|
979
|
+
argToKey(key, action->key, keyType, keyIsValid);
|
|
980
|
+
if (!keyIsValid) {
|
|
981
|
+
// argToKey already threw an error
|
|
982
|
+
delete worker;
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
// if we did not coordinate to always reference the object on the JS side, we would need this (but it is expensive):
|
|
987
|
+
//if (!action->freeKey)
|
|
988
|
+
// worker->SaveToPersistent(persistedIndex++, key);
|
|
989
|
+
Local<v8::Value> value = operation->Get(context, 1).ToLocalChecked();
|
|
990
|
+
|
|
991
|
+
if (dw->hasVersions) {
|
|
992
|
+
if (value->IsNumber()) {
|
|
993
|
+
action->actionType = CONDITION; // checking version action type
|
|
994
|
+
action->ifVersion = Nan::To<v8::Number>(value).ToLocalChecked()->Value();
|
|
995
|
+
continue;
|
|
996
|
+
}
|
|
997
|
+
action->actionType = CONDITION | WRITE_WITH_VALUE; // conditional save value
|
|
998
|
+
// TODO: Check length before continuing?
|
|
999
|
+
double version = 0;
|
|
1000
|
+
Local<v8::Value> versionValue = operation->Get(context, 2).ToLocalChecked();
|
|
1001
|
+
if (versionValue->IsNumber())
|
|
1002
|
+
version = Nan::To<v8::Number>(versionValue).ToLocalChecked()->Value();
|
|
1003
|
+
action->version = version;
|
|
1004
|
+
|
|
1005
|
+
versionValue = operation->Get(context, 3).ToLocalChecked();
|
|
1006
|
+
if (versionValue->IsNumber())
|
|
1007
|
+
version = Nan::To<v8::Number>(versionValue).ToLocalChecked()->Value();
|
|
1008
|
+
else if (versionValue->IsNull())
|
|
1009
|
+
version = NO_EXIST_VERSION;
|
|
1010
|
+
else
|
|
1011
|
+
action->actionType = WRITE_WITH_VALUE;
|
|
1012
|
+
action->ifVersion = version;
|
|
1013
|
+
} else {
|
|
1014
|
+
Local<v8::Value> deleteValue = operation->Get(context, 2).ToLocalChecked();
|
|
1015
|
+
if (deleteValue->IsTrue()) // useful for dupsort so we can specify a specfic value to delete
|
|
1016
|
+
action->actionType = DELETE_OPERATION | WRITE_WITH_VALUE;
|
|
1017
|
+
else
|
|
1018
|
+
action->actionType = WRITE_WITH_VALUE;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
if (value->IsNull() || value->IsUndefined()) {
|
|
1022
|
+
// standard delete (no regard for value)
|
|
1023
|
+
action->actionType = DELETE_OPERATION | (action->actionType & CONDITION); // only DELETE_OPERATION, no WRITE_WITH_VALUE
|
|
1024
|
+
action->freeValue = nullptr;
|
|
1025
|
+
} else if (value->IsArrayBufferView()) {
|
|
1026
|
+
int size = action->data.mv_size = node::Buffer::Length(value);
|
|
1027
|
+
action->data.mv_data = size > 0 ? node::Buffer::Data(value) : nullptr;
|
|
1028
|
+
action->freeValue = nullptr; // don't free, belongs to node
|
|
1029
|
+
//worker->SaveToPersistent(persistedIndex++, value); // this is coordinated to always be referenced on the JS side
|
|
1030
|
+
} else {
|
|
1031
|
+
writeValueToEntry(Nan::To<v8::String>(value).ToLocalChecked(), &action->data);
|
|
1032
|
+
action->freeValue = ([](MDB_val &value) -> void {
|
|
1033
|
+
delete[] (char*)value.mv_data;
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
//worker->SaveToPersistent("env", info.This()); // this is coordinated to always be referenced on the JS side
|
|
1039
|
+
if (callback) {
|
|
1040
|
+
Nan::AsyncQueueWorker(worker);
|
|
1041
|
+
} else {
|
|
1042
|
+
// sync mode
|
|
1043
|
+
//AsyncProgressWorker::ExecutionProgress executionProgress(worker);
|
|
1044
|
+
//worker->Execute(/*&executionProgress*/);
|
|
1045
|
+
delete worker;
|
|
1046
|
+
}
|
|
1047
|
+
return;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
NAN_METHOD(EnvWrap::continueBatch) {
|
|
1051
|
+
EnvWrap* ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
1052
|
+
ew->batchWorker->ContinueBatch(info[0]->IntegerValue(Nan::GetCurrentContext()).FromJust(), true);
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
NAN_METHOD(EnvWrap::resetCurrentReadTxn) {
|
|
1056
|
+
EnvWrap* ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info.This());
|
|
1057
|
+
mdb_txn_reset(ew->currentReadTxn);
|
|
1058
|
+
ew->readTxnRenewed = false;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
void EnvWrap::setupExports(Local<Object> exports) {
|
|
1062
|
+
// EnvWrap: Prepare constructor template
|
|
1063
|
+
Local<FunctionTemplate> envTpl = Nan::New<FunctionTemplate>(EnvWrap::ctor);
|
|
1064
|
+
envTpl->SetClassName(Nan::New<String>("Env").ToLocalChecked());
|
|
1065
|
+
envTpl->InstanceTemplate()->SetInternalFieldCount(1);
|
|
1066
|
+
// EnvWrap: Add functions to the prototype
|
|
1067
|
+
Isolate *isolate = Isolate::GetCurrent();
|
|
1068
|
+
envTpl->PrototypeTemplate()->Set(isolate, "open", Nan::New<FunctionTemplate>(EnvWrap::open));
|
|
1069
|
+
envTpl->PrototypeTemplate()->Set(isolate, "close", Nan::New<FunctionTemplate>(EnvWrap::close));
|
|
1070
|
+
envTpl->PrototypeTemplate()->Set(isolate, "beginTxn", Nan::New<FunctionTemplate>(EnvWrap::beginTxn));
|
|
1071
|
+
envTpl->PrototypeTemplate()->Set(isolate, "openDbi", Nan::New<FunctionTemplate>(EnvWrap::openDbi));
|
|
1072
|
+
envTpl->PrototypeTemplate()->Set(isolate, "sync", Nan::New<FunctionTemplate>(EnvWrap::sync));
|
|
1073
|
+
envTpl->PrototypeTemplate()->Set(isolate, "batchWrite", Nan::New<FunctionTemplate>(EnvWrap::batchWrite));
|
|
1074
|
+
envTpl->PrototypeTemplate()->Set(isolate, "continueBatch", Nan::New<FunctionTemplate>(EnvWrap::continueBatch));
|
|
1075
|
+
envTpl->PrototypeTemplate()->Set(isolate, "stat", Nan::New<FunctionTemplate>(EnvWrap::stat));
|
|
1076
|
+
envTpl->PrototypeTemplate()->Set(isolate, "freeStat", Nan::New<FunctionTemplate>(EnvWrap::freeStat));
|
|
1077
|
+
envTpl->PrototypeTemplate()->Set(isolate, "info", Nan::New<FunctionTemplate>(EnvWrap::info));
|
|
1078
|
+
envTpl->PrototypeTemplate()->Set(isolate, "readerCheck", Nan::New<FunctionTemplate>(EnvWrap::readerCheck));
|
|
1079
|
+
envTpl->PrototypeTemplate()->Set(isolate, "readerList", Nan::New<FunctionTemplate>(EnvWrap::readerList));
|
|
1080
|
+
envTpl->PrototypeTemplate()->Set(isolate, "resize", Nan::New<FunctionTemplate>(EnvWrap::resize));
|
|
1081
|
+
envTpl->PrototypeTemplate()->Set(isolate, "copy", Nan::New<FunctionTemplate>(EnvWrap::copy));
|
|
1082
|
+
envTpl->PrototypeTemplate()->Set(isolate, "detachBuffer", Nan::New<FunctionTemplate>(EnvWrap::detachBuffer));
|
|
1083
|
+
envTpl->PrototypeTemplate()->Set(isolate, "resetCurrentReadTxn", Nan::New<FunctionTemplate>(EnvWrap::resetCurrentReadTxn));
|
|
1084
|
+
|
|
1085
|
+
// TxnWrap: Prepare constructor template
|
|
1086
|
+
Local<FunctionTemplate> txnTpl = Nan::New<FunctionTemplate>(TxnWrap::ctor);
|
|
1087
|
+
txnTpl->SetClassName(Nan::New<String>("Txn").ToLocalChecked());
|
|
1088
|
+
txnTpl->InstanceTemplate()->SetInternalFieldCount(1);
|
|
1089
|
+
// TxnWrap: Add functions to the prototype
|
|
1090
|
+
txnTpl->PrototypeTemplate()->Set(isolate, "commit", Nan::New<FunctionTemplate>(TxnWrap::commit));
|
|
1091
|
+
txnTpl->PrototypeTemplate()->Set(isolate, "abort", Nan::New<FunctionTemplate>(TxnWrap::abort));
|
|
1092
|
+
txnTpl->PrototypeTemplate()->Set(isolate, "getString", Nan::New<FunctionTemplate>(TxnWrap::getString));
|
|
1093
|
+
txnTpl->PrototypeTemplate()->Set(isolate, "getStringUnsafe", Nan::New<FunctionTemplate>(TxnWrap::getStringUnsafe));
|
|
1094
|
+
txnTpl->PrototypeTemplate()->Set(isolate, "getUtf8", Nan::New<FunctionTemplate>(TxnWrap::getUtf8));
|
|
1095
|
+
txnTpl->PrototypeTemplate()->Set(isolate, "getBinary", Nan::New<FunctionTemplate>(TxnWrap::getBinary));
|
|
1096
|
+
txnTpl->PrototypeTemplate()->Set(isolate, "getBinaryUnsafe", Nan::New<FunctionTemplate>(TxnWrap::getBinaryUnsafe));
|
|
1097
|
+
txnTpl->PrototypeTemplate()->Set(isolate, "getNumber", Nan::New<FunctionTemplate>(TxnWrap::getNumber));
|
|
1098
|
+
txnTpl->PrototypeTemplate()->Set(isolate, "getBoolean", Nan::New<FunctionTemplate>(TxnWrap::getBoolean));
|
|
1099
|
+
txnTpl->PrototypeTemplate()->Set(isolate, "putString", Nan::New<FunctionTemplate>(TxnWrap::putString));
|
|
1100
|
+
txnTpl->PrototypeTemplate()->Set(isolate, "putBinary", Nan::New<FunctionTemplate>(TxnWrap::putBinary));
|
|
1101
|
+
txnTpl->PrototypeTemplate()->Set(isolate, "putNumber", Nan::New<FunctionTemplate>(TxnWrap::putNumber));
|
|
1102
|
+
txnTpl->PrototypeTemplate()->Set(isolate, "putBoolean", Nan::New<FunctionTemplate>(TxnWrap::putBoolean));
|
|
1103
|
+
txnTpl->PrototypeTemplate()->Set(isolate, "putUtf8", Nan::New<FunctionTemplate>(TxnWrap::putUtf8));
|
|
1104
|
+
txnTpl->PrototypeTemplate()->Set(isolate, "del", Nan::New<FunctionTemplate>(TxnWrap::del));
|
|
1105
|
+
txnTpl->PrototypeTemplate()->Set(isolate, "reset", Nan::New<FunctionTemplate>(TxnWrap::reset));
|
|
1106
|
+
txnTpl->PrototypeTemplate()->Set(isolate, "renew", Nan::New<FunctionTemplate>(TxnWrap::renew));
|
|
1107
|
+
// TODO: wrap mdb_cmp too
|
|
1108
|
+
// TODO: wrap mdb_dcmp too
|
|
1109
|
+
// TxnWrap: Get constructor
|
|
1110
|
+
EnvWrap::txnCtor = new Nan::Persistent<Function>();
|
|
1111
|
+
EnvWrap::txnCtor->Reset( txnTpl->GetFunction(Nan::GetCurrentContext()).ToLocalChecked());
|
|
1112
|
+
|
|
1113
|
+
// DbiWrap: Prepare constructor template
|
|
1114
|
+
Local<FunctionTemplate> dbiTpl = Nan::New<FunctionTemplate>(DbiWrap::ctor);
|
|
1115
|
+
dbiTpl->SetClassName(Nan::New<String>("Dbi").ToLocalChecked());
|
|
1116
|
+
dbiTpl->InstanceTemplate()->SetInternalFieldCount(1);
|
|
1117
|
+
// DbiWrap: Add functions to the prototype
|
|
1118
|
+
dbiTpl->PrototypeTemplate()->Set(isolate, "close", Nan::New<FunctionTemplate>(DbiWrap::close));
|
|
1119
|
+
dbiTpl->PrototypeTemplate()->Set(isolate, "drop", Nan::New<FunctionTemplate>(DbiWrap::drop));
|
|
1120
|
+
dbiTpl->PrototypeTemplate()->Set(isolate, "stat", Nan::New<FunctionTemplate>(DbiWrap::stat));
|
|
1121
|
+
|
|
1122
|
+
// TODO: wrap mdb_stat too
|
|
1123
|
+
// DbiWrap: Get constructor
|
|
1124
|
+
EnvWrap::dbiCtor = new Nan::Persistent<Function>();
|
|
1125
|
+
EnvWrap::dbiCtor->Reset( dbiTpl->GetFunction(Nan::GetCurrentContext()).ToLocalChecked());
|
|
1126
|
+
|
|
1127
|
+
Local<FunctionTemplate> compressionTpl = Nan::New<FunctionTemplate>(Compression::ctor);
|
|
1128
|
+
compressionTpl->SetClassName(Nan::New<String>("Compression").ToLocalChecked());
|
|
1129
|
+
compressionTpl->InstanceTemplate()->SetInternalFieldCount(1);
|
|
1130
|
+
(void)exports->Set(Nan::GetCurrentContext(), Nan::New<String>("Compression").ToLocalChecked(), compressionTpl->GetFunction(Nan::GetCurrentContext()).ToLocalChecked());
|
|
1131
|
+
|
|
1132
|
+
// Set exports
|
|
1133
|
+
(void)exports->Set(Nan::GetCurrentContext(), Nan::New<String>("Env").ToLocalChecked(), envTpl->GetFunction(Nan::GetCurrentContext()).ToLocalChecked());
|
|
1134
|
+
}
|