querysub 0.681.0 → 0.682.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "querysub",
3
- "version": "0.681.0",
3
+ "version": "0.682.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "note1": "note on node-forge fork, see https://github.com/digitalbazaar/forge/issues/744 for details",
@@ -209,7 +209,7 @@ export function createArchiveLocker2(config: {
209
209
  readFiles: (files: FileInfo[]) => Promise<(Buffer | undefined)[]>,
210
210
  ) => Promise<ArchiveTransaction[]>
211
211
  ): Promise<"accepted" | "rejected"> {
212
- let files = await locker.getFiles();
212
+ let files = await locker.getFiles({ forTransaction: true });
213
213
  await saveSnapshot({ files: files.map(a => a.file) });
214
214
  let readFiles = async (files: FileInfo[]) => {
215
215
  let pendingFiles = files.slice();
@@ -494,21 +494,23 @@ class TransactionLocker {
494
494
  let time = Date.now();
495
495
  let files = await this.storage.getKeys(config);
496
496
  this.perf.checkpoint("getKeys");
497
- if (this.lastFilesRead && this.lastFilesReadTime) {
498
- let prevFiles = new Set(this.lastFilesRead.map(a => a.file));
499
- let suspiciousThreshold = this.lastFilesReadTime - ARCHIVE_PROPAGATION_TIME * 10;
500
- let newFiles = files.filter(a => !prevFiles.has(a.file));
501
- let veryBadFiles = newFiles.filter(x => x.createTime < suspiciousThreshold);
502
- if (veryBadFiles.length > 0) {
503
- console.error(`Old read was not exhaustive, because we just found files which existed well before it, but that it did not read. This likely means our propagation assumptions are wrong, and propagation is much slower than anticipated. OR, getKeys is flakey and randomly misses files? Either way, this will BREAK THE DATABASE! Any node experiencing this might start deleting valid database files, which is very bad!`, {
504
- newlyAppearingOldFiles: veryBadFiles.map(x => x.file),
505
- prevFiles: this.lastFilesRead.map(x => x.file),
506
- newFiles: files.map(x => x.file),
507
- });
497
+ if (!config?.fallbacks) {
498
+ if (this.lastFilesRead && this.lastFilesReadTime) {
499
+ let prevFiles = new Set(this.lastFilesRead.map(a => a.file));
500
+ let suspiciousThreshold = this.lastFilesReadTime - ARCHIVE_PROPAGATION_TIME * 10;
501
+ let newFiles = files.filter(a => !prevFiles.has(a.file));
502
+ let veryBadFiles = newFiles.filter(x => x.createTime < suspiciousThreshold);
503
+ if (veryBadFiles.length > 0) {
504
+ console.error(`Old read was not exhaustive, because we just found files which existed well before it, but that it did not read. This likely means our propagation assumptions are wrong, and propagation is much slower than anticipated. OR, getKeys is flakey and randomly misses files? Either way, this will BREAK THE DATABASE! Any node experiencing this might start deleting valid database files, which is very bad!`, {
505
+ newlyAppearingOldFiles: veryBadFiles.map(x => x.file),
506
+ prevFiles: this.lastFilesRead.map(x => x.file),
507
+ newFiles: files.map(x => x.file),
508
+ });
509
+ }
508
510
  }
511
+ this.lastFilesRead = files;
512
+ this.lastFilesReadTime = time;
509
513
  }
510
- this.lastFilesRead = files;
511
- this.lastFilesReadTime = time;
512
514
 
513
515
  let transactions: (Transaction & {
514
516
  seqNum: number;
@@ -794,7 +796,7 @@ class TransactionLocker {
794
796
  /** Only returns data files (no transaction files, or confirmations).
795
797
  * - Might run a transaction
796
798
  */
797
- public async getFiles(): Promise<FileInfo[]> {
799
+ public async getFiles(config?: { forTransaction?: boolean }): Promise<FileInfo[]> {
798
800
  let time = Date.now();
799
801
  let storageAlivePromise = errorToUndefinedSilent(this.storage.getSyncStatus());
800
802
  try {
@@ -805,7 +807,7 @@ class TransactionLocker {
805
807
  return obj.dataFiles;
806
808
  } catch (e) {
807
809
  let duration0 = Date.now() - time;
808
- if (await storageAlivePromise) {
810
+ if (config?.forTransaction || await storageAlivePromise) {
809
811
  throw e;
810
812
  }
811
813
  let duration = Date.now() - time;