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/helpers/stage-old.mjs

1.4 KB

  1. // Stage a store with an OLD mpackdb lib (path in argv[2]); scenario argv[4]; dir argv[3].
  2. // compact-bug : insert, update, delete, close, reopen (startup compaction) + close => old lib writes wrong pk index
  3. // hardkill : insert+close, reopen, insert/update/delete, then SIGKILL itself (no close)
  4. import { rm } from 'node:fs/promises';
  5. import { resolve } from 'node:path';
  6. const { MPackDB } = await import(resolve(process.argv[2]));
  7. const dir = resolve(process.argv[3]);
  8. const scenario = process.argv[4];
  9. const opts = { primaryKey: 'sessionId', indexes: ['userId'], indexPersistInterval: 0 };
  10. await rm(dir, { recursive: true, force: true });
  11. let db = new MPackDB(`${dir}/sessions`, opts);
  12. for (let i = 0; i < 7; i++) await db.insert({ sessionId: 's' + i, userId: 'u' + (i % 3), n: i, pad: 'x'.repeat(10 + i * 7) });
  13. if (scenario === 'compact-bug') {
  14. await db.update('s1', r => ({ ...r, n: 100 }));
  15. await db.update('s4', r => ({ ...r, n: 400, extra: 'longer value'.repeat(5) }));
  16. await db.delete('s2');
  17. }
  18. await db.close();
  19. db = new MPackDB(`${dir}/sessions`, opts);
  20. if (scenario === 'compact-bug') { await db.find('s0').toArray().catch(() => {}); await db.close(); process.exit(0); }
  21. await db.insert({ sessionId: 's7', userId: 'u1', n: 7 });
  22. await db.update('s3', r => ({ ...r, n: 300 }));
  23. await db.delete('s5');
  24. await db.insert({ sessionId: 's8', userId: 'u2', n: 8 });
  25. await new Promise(r => setTimeout(r, 50));
  26. process.kill(process.pid, 'SIGKILL');

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