mpackdb
All repositories: gitoria
1.5 KB
// Bug 1: update/delete, restart (startup compaction), find(pk) must work for every record.// usage: node repro-bug1-compaction-pk.mjs <path to MPackDB.js> [workdir]import { rm } from 'node:fs/promises';import { resolve } from 'node:path';const { MPackDB } = await import(resolve(process.argv[2] || '../src/MPackDB.js'));const dir = resolve(process.argv[3] || 'db/repro-bug1');await rm(dir, { recursive: true, force: true });const opts = { primaryKey: 'sessionId', indexes: ['userId'], indexPersistInterval: 0 };const N = 7;let db = new MPackDB(`${dir}/sessions`, opts);for (let i = 0; i < N; i++) await db.insert({ sessionId: 's' + i, userId: 'u' + (i % 3), n: i, pad: 'x'.repeat(10 + i * 7) });await db.update('s1', r => ({ ...r, n: 100 }));await db.update('s4', r => ({ ...r, n: 400, extra: 'longer value'.repeat(5) }));await db.delete('s2');await db.close();db = new MPackDB(`${dir}/sessions`, opts); // startup compactionconst expect = ['s0', 's1', 's3', 's4', 's5', 's6'];let fail = 0;for (const id of expect) {try {const r = await db.find(id).toArray();if (r.length !== 1 || r[0].sessionId !== id) { fail++; console.log('WRONG', id, JSON.stringify(r)); }} catch (e) { fail++; console.log('THROW', id, e.message); }}if ((await db.find('s2').toArray()).length) { fail++; console.log('deleted s2 still found'); }const scan = await db.find(() => true).toArray();console.log('scan count', scan.length, 'expected', expect.length);if (scan.length !== expect.length) fail++;await db.close();console.log(fail ? `FAIL (${fail})` : 'PASS');process.exit(fail ? 1 : 0);
Branches
- mastermain branch
Latest commits
- cde6b2751.0.8: validate indexes against the data file on open, atomic index writes, invalidate index state before compaction; tests for pk find after compaction and hard killmre
- 87888725release 1.0.7caramboleyo
- c4cdb9b6node: import prefixes (Deno compat) + pre-existing index-state WIPcaramboleyo
- 0afb8f4bupdate now must be a callbackcaramboleyo
- cde73eb4release 1.0.6caramboleyo
- d01dda02add index hints, intersection, boundingBox; remove findByIndexcaramboleyo
- b8ffc1a0release 1.0.5caramboleyo
- d47876a1reimplemented lost features like indexed find and more testscaramboleyo
- 7f08da9afixed insert ignoring model definitioncaramboleyo
- 705774a9added flush before findcaramboleyo
- b4db6391initial commitcaramboleyo