Comparing version 2.1.2 to 2.1.3
@@ -30,2 +30,5 @@ import { WeakLRUCache } from './external.js'; | ||
} | ||
get isCaching() { | ||
return true | ||
} | ||
get(id, cacheMode) { | ||
@@ -32,0 +35,0 @@ let value = this.cache.getValue(id); |
@@ -84,3 +84,3 @@ import { getAddress, orderedBinary } from './external.js'; | ||
} | ||
if (savePosition >= 8180) { // need to reserve enough room at the end for pointers | ||
if (savePosition >= 8160) { // need to reserve enough room at the end for pointers | ||
savePosition = start // reset position | ||
@@ -87,0 +87,0 @@ allocateSaveBuffer(); // try again: |
22
mod.ts
@@ -43,2 +43,3 @@ import { fileURLToPath } from './deps.ts'; | ||
abortTxn: { parameters: ['f64'], result: 'void'}, | ||
commitTxn: { parameters: ['f64'], result: 'i32'}, | ||
commitEnvTxn: { parameters: ['f64'], result: 'i32'}, | ||
@@ -65,6 +66,5 @@ abortEnvTxn: { parameters: ['f64'], result: 'void'}, | ||
let { envOpen, closeEnv, getAddress, freeData, getMaxKeySize, openDbi, getDbi, readerCheck, | ||
commitEnvTxn, abortEnvTxn, beginTxn, resetTxn, renewTxn, abortTxn, dbiGetByBinary, startWriting, compress, envWrite, openCursor, cursorRenew, cursorClose, cursorIterate, cursorPosition, cursorCurrentValue, setGlobalBuffer: setGlobalBuffer2, setCompressionBuffer, getError, newCompression, prefetch } = lmdbLib.symbols; | ||
commitEnvTxn, abortEnvTxn, beginTxn, resetTxn, renewTxn, abortTxn, commitTxn, dbiGetByBinary, startWriting, compress, envWrite, openCursor, cursorRenew, cursorClose, cursorIterate, cursorPosition, cursorCurrentValue, setGlobalBuffer: setGlobalBuffer2, setCompressionBuffer, getError, newCompression, prefetch } = lmdbLib.symbols; | ||
let registry = new FinalizationRegistry(address => { | ||
// when an object is GC'ed, free it in C. | ||
console.log('freeData',address) | ||
freeData(address); | ||
@@ -113,15 +113,6 @@ }); | ||
} | ||
openDbi(options: any) { | ||
let flags = (options.reverseKey ? 0x02 : 0) | | ||
(options.dupSort ? 0x04 : 0) | | ||
(options.dupFixed ? 0x08 : 0) | | ||
(options.integerDup ? 0x20 : 0) | | ||
(options.reverseDup ? 0x40 : 0) | | ||
(options.create ? 0x40000 : 0) | | ||
(options.useVersions ? 0x1000 : 0); | ||
let keyType = (options.keyIsUint32 || options.keyEncoding == 'uint32') ? 2 : | ||
(options.keyIsBuffer || options.keyEncoding == 'binary') ? 3 : 0; | ||
let rc: number = openDbi(this.address, flags, toCString(options.name), keyType, options.compression?.address || 0) as number; | ||
openDbi(flags: number, name: string, keyType: number, compression: Compression) { | ||
let rc: number = openDbi(this.address, flags, toCString(name), keyType, compression?.address || 0) as number; | ||
if (rc == -30798) { // MDB_NOTFOUND | ||
console.log('dbi not found, need to try again with write txn'); | ||
return; | ||
} | ||
@@ -191,2 +182,5 @@ return new Dbi(checkError(rc), | ||
} | ||
commit() { | ||
commitTxn(this.address); | ||
} | ||
} | ||
@@ -193,0 +187,0 @@ |
42
open.js
@@ -38,3 +38,3 @@ import { Compression, getAddress, require, arch, fs, path as pathModule, lmdbError, EventEmitter, MsgpackrEncoder, Env } from './external.js'; | ||
options = Object.assign({ | ||
path, | ||
path: path || '.', | ||
noSubdir: Boolean(extension), | ||
@@ -129,4 +129,6 @@ isRoot: true, | ||
} | ||
// make sure we are using a fresh read txn, so we don't want to share with a cursor txn | ||
this.resetReadTxn(); | ||
this.ensureReadTxn(); | ||
let keyIsBuffer | ||
let keyIsBuffer = dbOptions.keyIsBuffer | ||
if (dbOptions.keyEncoding == 'uint32') { | ||
@@ -137,3 +139,3 @@ dbOptions.keyIsUint32 = true; | ||
dbOptions.keyEncoder.enableNullTermination() | ||
}else | ||
} else | ||
keyIsBuffer = true; | ||
@@ -143,9 +145,24 @@ } else if (dbOptions.keyEncoding == 'binary') { | ||
} | ||
this.db = env.openDbi(Object.assign({ | ||
name: dbName, | ||
create: true, | ||
keyIsBuffer, | ||
}, dbOptions)); | ||
let flags = (dbOptions.reverseKey ? 0x02 : 0) | | ||
(dbOptions.dupSort ? 0x04 : 0) | | ||
(dbOptions.dupFixed ? 0x10 : 0) | | ||
(dbOptions.integerDup ? 0x20 : 0) | | ||
(dbOptions.reverseDup ? 0x40 : 0) | | ||
(dbOptions.useVersions ? 0x1000 : 0); | ||
let keyType = (dbOptions.keyIsUint32 || dbOptions.keyEncoding == 'uint32') ? 2 : keyIsBuffer ? 3 : 0; | ||
if (keyType == 2) | ||
flags |= 0x08; // integer key | ||
this.db = env.openDbi(flags, dbName, keyType, dbOptions.compression); | ||
this._commitReadTxn(); // current read transaction becomes invalid after opening another db | ||
if (!this.db) {// not found | ||
if (dbOptions.create !== false && !options.readOnly) { | ||
flags |= 0x40000; // add create flag | ||
this.transactionSync(() => { | ||
this.db = env.openDbi(flags, dbName, keyType, dbOptions.compression); | ||
}); | ||
} else { | ||
return; // return undefined to indicate it could not be found | ||
} | ||
} | ||
this.db.name = dbName || null; | ||
this.resetReadTxn(); // a read transaction becomes invalid after opening another db | ||
this.name = dbName; | ||
@@ -198,3 +215,3 @@ this.status = 'open'; | ||
dbOptions = dbName; | ||
dbName = options.name; | ||
dbName = dbOptions.name; | ||
} else | ||
@@ -337,4 +354,5 @@ dbOptions = dbOptions || {}; | ||
addReadMethods(LMDBStore, { env, maxKeySize, keyBytes, keyBytesView, getLastVersion }); | ||
addWriteMethods(LMDBStore, { env, maxKeySize, fixedBuffer: keyBytes, | ||
resetReadTxn: LMDBStore.prototype.resetReadTxn, ...options }); | ||
if (!options.readOnly) | ||
addWriteMethods(LMDBStore, { env, maxKeySize, fixedBuffer: keyBytes, | ||
resetReadTxn: LMDBStore.prototype.resetReadTxn, ...options }); | ||
LMDBStore.prototype.supports = { | ||
@@ -341,0 +359,0 @@ permanence: true, |
{ | ||
"name": "lmdb", | ||
"author": "Kris Zyp", | ||
"version": "2.1.2", | ||
"version": "2.1.3", | ||
"description": "Simple, efficient, scalable, high-performance LMDB interface", | ||
@@ -58,3 +58,4 @@ "license": "MIT", | ||
"prebuild-musl": "prebuildify --target 17.3.0 --libc musl --tag-libc && prebuildify --target 16.13.0 --libc musl --tag-libc && prebuildify --target 14.17.6 --libc musl --tag-libc && prebuildify --target 12.22.7 --libc musl --tag-libc", | ||
"prebuild-arm64": "prebuildify --arch=arm64 --target 17.3.0 --libc musl && prebuildify --arch=arm64 --target 16.13.0 && prebuildify --arch=arm64 --target 14.17.6 && prebuildify --arch=arm64 --target electron@16.0.2", | ||
"prebuild-musl-arm64": "prebuildify --arch=arm64 --target 17.3.0 --libc musl --tag-libc && prebuildify --arch=arm64 --target 16.13.0 --libc musl --tag-libc && prebuildify --arch=arm64 --target 14.17.6 --libc musl --tag-libc && prebuildify --arch=arm64 --target 12.22.7 --libc musl --tag-libc", | ||
"prebuild-arm64": "prebuildify --arch=arm64 --target 17.3.0 --tag-libc && prebuildify --arch=arm64 --tag-libc --target 16.13.0 && prebuildify --arch=arm64 --tag-libc --target 14.17.6 && prebuildify --arch=arm64 --tag-libc --target electron@16.0.2", | ||
"recompile": "node-gyp clean && node-gyp configure && node-gyp build", | ||
@@ -61,0 +62,0 @@ "test": "mocha test/**.test.js --recursive && npm run test:types", |
49
read.js
@@ -107,2 +107,7 @@ import { RangeIterable } from './util/RangeIterable.js'; | ||
}, | ||
_commitReadTxn() { | ||
readTxn.commit(); | ||
readTxnRenewed = null; | ||
readTxn = null; | ||
}, | ||
ensureReadTxn() { | ||
@@ -199,8 +204,3 @@ if (!env.writeTxn && !readTxnRenewed) | ||
db.availableCursor = null; | ||
if (db.cursorTxn != txn) { | ||
let rc = cursor.renew(); | ||
if (rc) | ||
lmdbError(rc); | ||
} else// if (db.currentRenewId != renewId) | ||
flags |= 0x2000; | ||
flags |= 0x2000; | ||
} else { | ||
@@ -297,4 +297,10 @@ cursor = new Cursor(db); | ||
} | ||
if (!valuesForKey || snapshot === false) | ||
if (!valuesForKey || snapshot === false) { | ||
if (keySize > 20000) { | ||
if (keySize > 0x1000000) | ||
lmdbError(keySize - 0x100000000) | ||
throw new Error('Invalid key size ' + keySize.toString(16)) | ||
} | ||
currentKey = store.readKey(keyBytes, 32, keySize + 32); | ||
} | ||
if (includeValues) { | ||
@@ -461,3 +467,4 @@ let value; | ||
getStats() { | ||
return this.db.stat(readTxnRenewed ? readTxn : renewReadTxn()); | ||
readTxnRenewed ? readTxn : renewReadTxn(); | ||
return this.db.stat(); | ||
} | ||
@@ -467,10 +474,23 @@ }); | ||
function renewReadTxn() { | ||
if (readTxn) | ||
readTxn.renew(); | ||
else | ||
readTxn = env.beginTxn(0x20000); | ||
if (!readTxn) { | ||
let retries = 0; | ||
let waitArray; | ||
do { | ||
try { | ||
readTxn = env.beginTxn(0x20000); | ||
break; | ||
} catch (error) { | ||
if (error.message.includes('temporarily')) { | ||
if (!waitArray) | ||
waitArray = new Int32Array(new SharedArrayBuffer(4), 0, 1); | ||
Atomics.wait(waitArray, 0, 0, retries * 2); | ||
} else | ||
throw error; | ||
} | ||
} while (retries++ < 100); | ||
} | ||
readTxnRenewed = setTimeout(resetReadTxn, 0); | ||
return readTxn; | ||
} | ||
function resetReadTxn() { | ||
function resetReadTxn(hardReset) { | ||
renewId++; | ||
@@ -482,4 +502,3 @@ if (readTxnRenewed) { | ||
readTxn = null; | ||
} | ||
else | ||
} else | ||
readTxn.reset(); | ||
@@ -486,0 +505,0 @@ } |
@@ -711,3 +711,3 @@ import { getAddress } from './external.js'; | ||
if (writeTxn) { | ||
if (!useWritemap && !this.cache) | ||
if (!useWritemap && !this.isCaching) // can't use child transactions in write maps or caching stores | ||
// already nested in a transaction, execute as child transaction (if possible) and return | ||
@@ -714,0 +714,0 @@ return this.childTransaction(callback); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 8 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 4 instances in 1 package
17875270
158
8651
23
35