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-bug1-compaction-pk.mjs

1.5 KB

  1. // Bug 1: update/delete, restart (startup compaction), find(pk) must work for every record.
  2. // usage: node repro-bug1-compaction-pk.mjs <path to MPackDB.js> [workdir]
  3. import { rm } from 'node:fs/promises';
  4. import { resolve } from 'node:path';
  5. const { MPackDB } = await import(resolve(process.argv[2] || '../src/MPackDB.js'));
  6. const dir = resolve(process.argv[3] || 'db/repro-bug1');
  7. await rm(dir, { recursive: true, force: true });
  8. const opts = { primaryKey: 'sessionId', indexes: ['userId'], indexPersistInterval: 0 };
  9. const N = 7;
  10. let db = new MPackDB(`${dir}/sessions`, opts);
  11. 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) });
  12. await db.update('s1', r => ({ ...r, n: 100 }));
  13. await db.update('s4', r => ({ ...r, n: 400, extra: 'longer value'.repeat(5) }));
  14. await db.delete('s2');
  15. await db.close();
  16. db = new MPackDB(`${dir}/sessions`, opts); // startup compaction
  17. const expect = ['s0', 's1', 's3', 's4', 's5', 's6'];
  18. let fail = 0;
  19. for (const id of expect) {
  20. try {
  21. const r = await db.find(id).toArray();
  22. if (r.length !== 1 || r[0].sessionId !== id) { fail++; console.log('WRONG', id, JSON.stringify(r)); }
  23. } catch (e) { fail++; console.log('THROW', id, e.message); }
  24. }
  25. if ((await db.find('s2').toArray()).length) { fail++; console.log('deleted s2 still found'); }
  26. const scan = await db.find(() => true).toArray();
  27. console.log('scan count', scan.length, 'expected', expect.length);
  28. if (scan.length !== expect.length) fail++;
  29. await db.close();
  30. console.log(fail ? `FAIL (${fail})` : 'PASS');
  31. process.exit(fail ? 1 : 0);

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