From dd08273cc5fa238eb86186f4b64506ee56470a51 Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Thu, 29 Feb 2024 17:20:25 -0700 Subject: [PATCH] Properly assign overflow page number on compact backup --- dependencies/lmdb/libraries/liblmdb/mdb.c | 2 +- open.js | 2 +- test/index.test.js | 8 ++------ 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/dependencies/lmdb/libraries/liblmdb/mdb.c b/dependencies/lmdb/libraries/liblmdb/mdb.c index 00ca9eee5..c07795919 100644 --- a/dependencies/lmdb/libraries/liblmdb/mdb.c +++ b/dependencies/lmdb/libraries/liblmdb/mdb.c @@ -11577,7 +11577,7 @@ mdb_env_cwalk(mdb_copy *my, pgno_t *pg, int flags) } mo = (MDB_page *)(my->mc_wbuf[toggle] + my->mc_wlen[toggle]); memcpy(mo, omp, my->mc_env->me_psize); - ovp.op_pgno = my->mc_next_pgno; + ovp.op_pgno = mo->mp_pgno = my->mc_next_pgno; ovp.op_txnid = 1; memcpy(NODEDATA(ni), &ovp, sizeof(ovp)); my->mc_next_pgno += ovp.op_pages; diff --git a/open.js b/open.js index 77f299c72..2ef3fc3c3 100644 --- a/open.js +++ b/open.js @@ -296,7 +296,7 @@ export function open(path, options) { if (noFSAccess) return; fs.mkdirSync(pathModule.dirname(path), { recursive: true }); - return new Promise((resolve, reject) => env.copy(path, false, (error) => { + return new Promise((resolve, reject) => env.copy(path, compact, (error) => { if (error) { reject(error); } else { diff --git a/test/index.test.js b/test/index.test.js index cc53e1b45..7af50ada3 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1745,7 +1745,7 @@ describe('lmdb-js', function () { }); should.equal(dbRAS.get(3).name, 'three'); }); - it.skip('can backup and use backup', async function () { + it('can backup and use backup', async function () { if (options.encryptionKey) // it won't match the environment return; @@ -1764,14 +1764,10 @@ describe('lmdb-js', function () { let backupDb = open(testDirPath + '/backup.mdb', options); try { backupDb.get('for-backup-110').should.equal(value.slice(0, 5500)); - value += ' changed'; for (let i = 0; i < 100; i++) { - const testGet = backupDb.get('for-backup-5'); - console.log('testGetSize', testGet.length); - console.log('writing on backup file',i); await backupDb.put('for-backup-' + i, 'test'); } - backupDb.get('for-backup-1').should.equal(value); + backupDb.get('for-backup-1').should.equal('test'); } finally { await backupDb.close(); }