querysub 0.30.0 → 0.32.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.30.0",
3
+ "version": "0.32.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",
@@ -49,6 +49,9 @@ let DISK_AUDIT_RATE = timeInMinute * 5;
49
49
  let API_AUDIT_RATE = timeInSecond;
50
50
  let API_AUDIT_COUNT = 12;
51
51
 
52
+
53
+ let DEAD_NODE_POLL_COOLDOWN = timeInMinute * 5;
54
+
52
55
  let shutdown = false;
53
56
 
54
57
  const archives = lazy(() => getArchives("nodes/"));
@@ -292,12 +295,26 @@ async function runHeartbeatAuditLoop() {
292
295
  });
293
296
  }
294
297
 
298
+ let deadNodes = new Map<string, number>();
295
299
  async function fastMemorySync() {
296
- let checkNodes = shuffle(Array.from(allNodeIds2).filter(x => x !== getOurNodeId()), Date.now()).slice(0, API_AUDIT_COUNT);
300
+ let aliveNodes = new Set(Array.from(allNodeIds2).filter(x => x !== getOurNodeId()));
301
+ let deadThreshold = Date.now() - DEAD_NODE_POLL_COOLDOWN;
302
+ for (let [nodeId, time] of Array.from(deadNodes)) {
303
+ if (time < deadThreshold) {
304
+ deadNodes.delete(nodeId);
305
+ } else {
306
+ aliveNodes.delete(nodeId);
307
+ }
308
+ }
309
+ let checkNodes = shuffle(Array.from(aliveNodes), Date.now()).slice(0, API_AUDIT_COUNT);
297
310
  let otherNodesAll = await Promise.all(
298
- checkNodes.map(async nodeId =>
299
- await timeoutToUndefinedSilent(200, NodeDiscoveryController.nodes[nodeId].getAllNodeIds()) || []
300
- )
311
+ checkNodes.map(async nodeId => {
312
+ let nodes = await timeoutToUndefinedSilent(200, NodeDiscoveryController.nodes[nodeId].getAllNodeIds());
313
+ if (!nodes) {
314
+ deadNodes.set(nodeId, Date.now());
315
+ }
316
+ return nodes || [];
317
+ })
301
318
  );
302
319
  let otherNodes = Array.from(new Set(otherNodesAll.flat()));
303
320
  // This would log WAY too much, because we poll a lot, because we want to minimize downtime
@@ -59,7 +59,7 @@ export async function replaceFunctions(config: {
59
59
 
60
60
  for (let previous of previousFunctions) {
61
61
  if (!currentFunctionNames.has(getFunctionName(previous))) {
62
- messages.push({ text: `Removing ${red(debugFunction(previous))}`, order: 3 });
62
+ messages.push({ text: `Removing\t ${red(debugFunction(previous))}`, order: 3 });
63
63
  base[previous.ModuleId].Sources[previous.FunctionId] = undefined;
64
64
  }
65
65
  }
@@ -487,24 +487,14 @@ export async function getCallWrites(config: {
487
487
  let { call, debugName } = config;
488
488
  const { functionSpec } = await proxyWatcher.commitFunction({
489
489
  watchFunction: function getModuleConfig() {
490
- //let moduleConfig = atomicObjectRead(functionSchema()[call.DomainName].PathFunctionRunner[call.ModuleId].Module);
491
- // if (!(call.DomainName in functionSchema())) {
492
- // throw new Error(`Domain not found ${call.DomainName}`);
493
- // }
494
490
  let domainObject = functionSchema()[call.DomainName];
495
- // if (!(call.ModuleId in domainObject.PathFunctionRunner)) {
496
- // throw new Error(`Module not found ${call.DomainName}.${call.ModuleId}`);
497
- // }
498
491
  let moduleObject = domainObject.PathFunctionRunner[call.ModuleId];
499
- if (!(call.FunctionId in moduleObject.Sources) && Querysub.isAllSynced()) {
500
- throw new Error(`Function not found in database ${call.DomainName}.${call.ModuleId}.${call.FunctionId}, have ${JSON.stringify(Object.keys(moduleObject.Sources))}`);
501
- }
502
492
  let functionSpec = atomicObjectRead(moduleObject.Sources[call.FunctionId]);
503
493
  return { functionSpec };
504
494
  }
505
495
  });
506
496
  if (!functionSpec) {
507
- throw new Error(`Function not found ${call.DomainName}.${call.ModuleId}.${call.FunctionId}`);
497
+ throw new Error(`Function not found in database ${call.DomainName}.${call.ModuleId}.${call.FunctionId}`);
508
498
  }
509
499
 
510
500
  await addModuleToLoader(functionSpec);