gitoria

mpackdb

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmastercde6b2751.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 killmremaster/tests/repro-bug2-hardkill.mjs

2.2 KB

  1. // Bug 2: process killed (SIGKILL) without close(); after restart find(pk) must find every record.
  2. // usage: node repro-bug2-hardkill.mjs <path to MPackDB.js> [workdir]
  3. import { rm } from 'node:fs/promises';
  4. import { resolve } from 'node:path';
  5. import { spawn } from 'node:child_process';
  6. import { fileURLToPath } from 'node:url';
  7. const lib = resolve(process.argv[2] || '../src/MPackDB.js');
  8. const dir = resolve(process.argv[3] || 'db/repro-bug2');
  9. if (process.argv[4] === 'child') {
  10. const { MPackDB } = await import(lib);
  11. const db = new MPackDB(`${dir}/sessions`, { primaryKey: 'sessionId', indexes: ['userId'] });
  12. for (let i = 0; i < 5; i++) await db.insert({ sessionId: 'a' + i, userId: 'u' }); // before "clean" point
  13. await db.close(); // persisted baseline
  14. const db2 = new MPackDB(`${dir}/sessions`, { primaryKey: 'sessionId', indexes: ['userId'] });
  15. for (let i = 0; i < 5; i++) await db2.insert({ sessionId: 'b' + i, userId: 'u' }); // never persisted
  16. await db2.update('a1', r => ({ ...r, upd: 1 }));
  17. await db2.delete('a2');
  18. process.stdout.write('READY\n');
  19. setInterval(() => {}, 1000);
  20. } else {
  21. await rm(dir, { recursive: true, force: true });
  22. const child = spawn(process.execPath, [fileURLToPath(import.meta.url), lib, dir, 'child'], { stdio: ['ignore', 'pipe', 'inherit'] });
  23. await new Promise(r => child.stdout.on('data', d => String(d).includes('READY') && r()));
  24. child.kill('SIGKILL');
  25. await new Promise(r => child.on('exit', r));
  26. const { MPackDB } = await import(lib);
  27. const db = new MPackDB(`${dir}/sessions`, { primaryKey: 'sessionId', indexes: ['userId'], compact: false });
  28. const expect = ['a0', 'a1', 'a3', 'a4', 'b0', 'b1', 'b2', 'b3', 'b4'];
  29. let fail = 0;
  30. for (const id of expect) {
  31. try {
  32. const r = await db.find(id).toArray();
  33. if (r.length !== 1) { fail++; console.log('MISS', id, r.length); }
  34. else if (id === 'a1' && r[0].upd !== 1) { fail++; console.log('STALE a1'); }
  35. } catch (e) { fail++; console.log('THROW', id, e.message); }
  36. }
  37. if ((await db.find('a2').toArray()).length) { fail++; console.log('deleted a2 found'); }
  38. console.log('scan count', (await db.find(() => true).toArray()).length, 'expected', expect.length);
  39. await db.close();
  40. console.log(fail ? `FAIL (${fail})` : 'PASS');
  41. process.exit(fail ? 1 : 0);
  42. }

Branches

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