mpackdb
All repositories: gitoria
2.2 KB
// Bug 2: process killed (SIGKILL) without close(); after restart find(pk) must find every record.// usage: node repro-bug2-hardkill.mjs <path to MPackDB.js> [workdir]import { rm } from 'node:fs/promises';import { resolve } from 'node:path';import { spawn } from 'node:child_process';import { fileURLToPath } from 'node:url';const lib = resolve(process.argv[2] || '../src/MPackDB.js');const dir = resolve(process.argv[3] || 'db/repro-bug2');if (process.argv[4] === 'child') {const { MPackDB } = await import(lib);const db = new MPackDB(`${dir}/sessions`, { primaryKey: 'sessionId', indexes: ['userId'] });for (let i = 0; i < 5; i++) await db.insert({ sessionId: 'a' + i, userId: 'u' }); // before "clean" pointawait db.close(); // persisted baselineconst db2 = new MPackDB(`${dir}/sessions`, { primaryKey: 'sessionId', indexes: ['userId'] });for (let i = 0; i < 5; i++) await db2.insert({ sessionId: 'b' + i, userId: 'u' }); // never persistedawait db2.update('a1', r => ({ ...r, upd: 1 }));await db2.delete('a2');process.stdout.write('READY\n');setInterval(() => {}, 1000);} else {await rm(dir, { recursive: true, force: true });const child = spawn(process.execPath, [fileURLToPath(import.meta.url), lib, dir, 'child'], { stdio: ['ignore', 'pipe', 'inherit'] });await new Promise(r => child.stdout.on('data', d => String(d).includes('READY') && r()));child.kill('SIGKILL');await new Promise(r => child.on('exit', r));const { MPackDB } = await import(lib);const db = new MPackDB(`${dir}/sessions`, { primaryKey: 'sessionId', indexes: ['userId'], compact: false });const expect = ['a0', 'a1', 'a3', 'a4', 'b0', 'b1', 'b2', 'b3', 'b4'];let fail = 0;for (const id of expect) {try {const r = await db.find(id).toArray();if (r.length !== 1) { fail++; console.log('MISS', id, r.length); }else if (id === 'a1' && r[0].upd !== 1) { fail++; console.log('STALE a1'); }} catch (e) { fail++; console.log('THROW', id, e.message); }}if ((await db.find('a2').toArray()).length) { fail++; console.log('deleted a2 found'); }console.log('scan count', (await db.find(() => true).toArray()).length, 'expected', expect.length);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