gitoriaLog in with ident

mpackdb

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit8788872587888725release 1.0.7caramboleyo87888725/tests/helpers/multi-process-worker.js

1.5 KB

  1. // Worker for multi-process-write.test.js — spawned as a separate node process.
  2. // argv: <dbPath> <workerId> <mode>
  3. import MPackDB from '../../src/MPackDB.js';
  4. const [, , dbPath, workerId, mode] = process.argv;
  5. if (mode === 'utxo') {
  6. // String-PK store like the blockchain's utxos: insert 15, delete every 3rd
  7. const db = new MPackDB(dbPath, { primaryKey: 'id', indexes: ['symbol', '*blockNumber'], compact: false });
  8. for (let i = 0; i < 15; i++) {
  9. await db.insert({ id: `w${workerId}-${i}`, symbol: `SYM${workerId}`, blockNumber: i, worker: Number(workerId) });
  10. }
  11. for (let i = 0; i < 15; i += 3) {
  12. await db.delete(`w${workerId}-${i}`);
  13. }
  14. await db.close();
  15. process.exit(0);
  16. }
  17. if (mode === 'numeric') {
  18. // Numeric auto-increment PK — ids must be globally unique across processes
  19. const db = new MPackDB(dbPath, { primaryKey: '*id', compact: false });
  20. const ids = [];
  21. for (let i = 0; i < 15; i++) {
  22. ids.push(await db.insert({ worker: Number(workerId), i }));
  23. }
  24. await db.close();
  25. console.log(JSON.stringify(ids));
  26. process.exit(0);
  27. }
  28. if (mode === 'live') {
  29. // Insert with index persistence disabled, then exit WITHOUT close() (like a
  30. // crash): the parent must still see the records via its tail-scan catch-up
  31. const db = new MPackDB(dbPath, {
  32. primaryKey: 'id',
  33. indexes: ['symbol'],
  34. compact: false,
  35. indexPersistInterval: 0,
  36. indexPersistThreshold: 1e9,
  37. });
  38. for (let i = 0; i < 5; i++) {
  39. await db.insert({ id: `live-${i}`, symbol: 'LIVE' });
  40. }
  41. console.log('INSERTED');
  42. process.stdin.once('data', () => process.exit(0));
  43. }

Branches

Latest commits

  • 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