querysub 0.16.0 → 0.18.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.16.0",
3
+ "version": "0.18.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",
@@ -13,7 +13,7 @@ import { blue, green, magenta, red, yellow } from "socket-function/src/formattin
13
13
  import debugbreak from "debugbreak";
14
14
  import { getArchivesBackblaze, getBackblazePath } from "../-a-archives/archivesBackBlaze";
15
15
  import { PromiseObj } from "../promise";
16
- import { formatDateTime, formatTime } from "socket-function/src/formatting/format";
16
+ import { formatDateTime, formatTime, formatVeryNiceDateTime } from "socket-function/src/formatting/format";
17
17
  import { isClient, isServer } from "../config2";
18
18
  import { waitForFirstTimeSync } from "socket-function/time/trueTimeShim";
19
19
  import { decodeNodeId, decodeNodeIdAssert, getMachineId } from "../-a-auth/certs";
@@ -22,6 +22,7 @@ import { getPublicIP } from "../misc/networking";
22
22
  import dns from "dns/promises";
23
23
  import { isDefined } from "../misc";
24
24
  import { diskLog, noDiskLogPrefix } from "../diagnostics/logs/diskLogger";
25
+ import { getDebuggerUrl } from "../diagnostics/listenOnDebugger";
25
26
 
26
27
  let HEARTBEAT_INTERVAL = timeInMinute * 2;
27
28
  // Interval which we check other heartbeats
@@ -37,10 +38,16 @@ let SUICIDE_HEARTBEAT_THRESHOLD = timeInMinute * 15;
37
38
 
38
39
  let CLIENTSIDE_POLL_RATE = timeInMinute * 5;
39
40
 
40
- let API_AUDIT_RATE = timeInSecond * 5;
41
-
42
- let MEMORY_AUDIT_RATE = timeInMinute * 5;
43
- let MEMORY_AUDIT_COUNT = 3;
41
+ // We can't poll backblaze too often. One a minute starts to cost around 10 cents per month.
42
+ // So once a second would cost 6 USD per month, per service... which starts to get expensive.
43
+ let DISK_AUDIT_RATE = timeInMinute * 5;
44
+ // We CAN poll our API frequently. The overhead for calls should be far less than 1ms, and
45
+ // the bandwidth should also be effectively nothing. Maybe 2.5GB per month if we send a
46
+ // request per second, and each request is 1000 bytes (which as we use websockets, it
47
+ // probably is less than that). Which is around 2.5 cents on backblaze IF we go over
48
+ // our 1TB/month allowance.
49
+ let API_AUDIT_RATE = timeInSecond;
50
+ let API_AUDIT_COUNT = 12;
44
51
 
45
52
  let shutdown = false;
46
53
 
@@ -161,6 +168,7 @@ function addNodeIdBase(nodeId: string) {
161
168
  }
162
169
  function setNodeIds(nodeIds: string[]) {
163
170
  nodeIds = nodeIds.filter(x => x !== SPECIAL_NODE_ID_FOR_UNMOUNTED_NODE);
171
+
164
172
  diskLog("setNodeIds", { nodeIds });
165
173
  // Also try all localhost ports, if we are in dev mode
166
174
  if (isNode() && isDevDebugbreak()) {
@@ -284,29 +292,30 @@ async function runHeartbeatAuditLoop() {
284
292
  });
285
293
  }
286
294
 
287
- async function fastMemorySync(retries = 3) {
288
- let checkNode = shuffle(Array.from(allNodeIds2).filter(x => x !== getOurNodeId()), Date.now()).slice(0, MEMORY_AUDIT_COUNT).at(0);
289
- if (!checkNode) return;
290
- let otherNodes = await errorToUndefinedSilent(NodeDiscoveryController.nodes[checkNode].getAllNodeIds());
291
- if (!otherNodes) {
292
- if (retries > 0) {
293
- await fastMemorySync(retries - 1);
294
- }
295
- return;
296
- }
295
+ async function fastMemorySync() {
296
+ let checkNodes = shuffle(Array.from(allNodeIds2).filter(x => x !== getOurNodeId()), Date.now()).slice(0, API_AUDIT_COUNT);
297
+ let otherNodesAll = await Promise.all(
298
+ checkNodes.map(async nodeId =>
299
+ await timeoutToUndefinedSilent(200, NodeDiscoveryController.nodes[nodeId].getAllNodeIds()) || []
300
+ )
301
+ );
302
+ let otherNodes = Array.from(new Set(otherNodesAll.flat()));
303
+ // This would log WAY too much, because we poll a lot, because we want to minimize downtime
304
+ //console.log(magenta(`Fast memory sync at ${formatVeryNiceDateTime(Date.now())}, nodes found ${otherNodes.length}`), getDebuggerUrl());
305
+
297
306
  // If they are missing nodes that's fine. We constantly have extra nodes, and have to function correctly
298
307
  // with extra nodes. However, if we are missing nodes, we'd prefer to have them quickly, so we should
299
308
  // sync now.
300
309
  let missingNodes = otherNodes.filter(nodeId => !allNodeIds2.has(nodeId));
301
310
  if (missingNodes.length > 0) {
302
- console.log(yellow(`Node list is missing nodes, resyncing node`), { checkNode, missingNodes, otherNodes });
311
+ console.log(yellow(`Node list is missing nodes, resyncing node`), { missingNodes, otherNodes });
303
312
  await syncArchives();
304
313
  }
305
314
  }
306
315
 
307
316
  async function runMemoryAuditLoop() {
308
317
  await onNodeDiscoveryReady();
309
- runInfinitePoll(MEMORY_AUDIT_RATE, syncArchives);
318
+ runInfinitePoll(DISK_AUDIT_RATE, syncArchives);
310
319
  runInfinitePoll(API_AUDIT_RATE, fastMemorySync);
311
320
  }
312
321
 
@@ -473,6 +482,7 @@ const tellEveryoneNodesChanges = throttleFunction(1000, function tellEveryoneNod
473
482
 
474
483
  class NodeDiscoveryControllerBase {
475
484
  public async addNode(nodeId: string) {
485
+ console.log(magenta(`Received addNode`), { nodeId });
476
486
  addNodeId(nodeId);
477
487
  }
478
488
  public async resyncNodes() {
@@ -483,7 +493,7 @@ class NodeDiscoveryControllerBase {
483
493
  }
484
494
 
485
495
  public async getAllNodeIds(): Promise<string[]> {
486
- return Array.from(allNodeIds2);
496
+ return Array.from(allNodeIds2).filter(x => !x.startsWith("127-0-0-1."));
487
497
  }
488
498
  public async getNodeId() {
489
499
  console.log(`Returning node id ${SocketFunction.mountedNodeId}`);
@@ -949,7 +949,9 @@ class PathControllerBase {
949
949
  }
950
950
 
951
951
  public async broadcastReadReady(time: number) {
952
- onReadyReady(IdentityController_getCurrentReconnectNodeIdAssert(), time);
952
+ let nodeIdCaller = IdentityController_getCurrentReconnectNodeIdAssert();
953
+ console.log(magenta(`Received ready broadcast`), { nodeIdCaller });
954
+ onReadyReady(nodeIdCaller, time);
953
955
  }
954
956
  }
955
957
  const PathController = SocketFunction.register(
@@ -170,7 +170,10 @@ export class RemoteWatcher {
170
170
  // us to circumvent earlier watchers, causing us to watch out of order, causing reads
171
171
  // to come back out of order, causing watching functions to trigger out of order!
172
172
  let remoteAuthorityId = this.remoteWatchPaths.get(path);
173
- if (remoteAuthorityId !== undefined) continue;
173
+ if (remoteAuthorityId !== undefined) {
174
+ this.disconnectedPaths.delete(path);
175
+ continue;
176
+ }
174
177
 
175
178
  let authorityId = pathValueAuthority2.getSingleReadNodeSync(path);
176
179
  if (!authorityId) {