querysub 0.488.0 → 0.489.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.488.0",
3
+ "version": "0.489.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",
@@ -21,6 +21,7 @@ import { Time } from "./pathValueCore";
21
21
  import { encodeCborx, decodeCborx } from "../misc/cloneHelpers";
22
22
  import { debugGetAllCallFactories } from "socket-function/src/nodeCache";
23
23
  import { delay } from "socket-function/src/batching";
24
+ import { isDefined } from "../misc";
24
25
  export { pathValueCommitter };
25
26
 
26
27
  let pathValueSendCount = 0;
@@ -103,12 +104,14 @@ export class PathValueControllerBase {
103
104
  pathValues: PathValue[];
104
105
  initialTriggers?: { values: Set<string>; parentPaths: Set<string> },
105
106
  reason: string;
107
+ // Locks are normally stripped because watchers don't need them, but a receiving authority needs the locks to compute the valid state itself — without them it can only adopt our valid state and can never recompute.
108
+ keepLocks?: boolean;
106
109
  }) {
107
110
  let changes = config.pathValues;
108
111
  let { nodeId, initialTriggers } = config;
109
112
  pathValueSendCount += changes.length;
110
113
  let buffers = await pathValueSerializer.serialize(changes, {
111
- noLocks: true,
114
+ noLocks: !config.keepLocks,
112
115
  compress: getCompressNetwork(),
113
116
  });
114
117
  this.logSendValues({ nodeId, pathValues: changes, initialTriggers, reason: config.reason });
@@ -182,6 +185,9 @@ export class PathValueControllerBase {
182
185
  }
183
186
  }
184
187
 
188
+ // Note which values are genuinely new to us BEFORE ingesting. We only re-share new values with the other authorities below; if we already had a value we already shared it when we first received it, so re-sharing is redundant and can clobber a newer value with an older copy.
189
+ let valuesNewToUs = config.initialCreation && values.filter(value => !authorityStorage.getValueExactMaybeRejected(value.path, value.time)) || [];
190
+
185
191
  try {
186
192
  let initialTriggers = config.initialTriggers || { values: new Set(), parentPaths: new Set() };
187
193
  await pathValueCommitter.ingestRemoteValuesAndValidStates({
@@ -194,9 +200,10 @@ export class PathValueControllerBase {
194
200
  }
195
201
 
196
202
 
197
- if (config.initialCreation) {
198
- // NOTE: This will mean that all of the authorities for a value will write it to disk. So it will be written to disk multiple times. This should be fine, and it might be a good idea for redundancy, etc. And eventually, they will get compressed to one value, so it's not inefficient.
199
- await PathValueControllerBase.authorityShareValues({ pathValues: values });
203
+ if (config.initialCreation && valuesNewToUs.length > 0) {
204
+ // Always shared the latest. If we don't have it, maybe something with ingestion delayed, we should still share it so we don't lose the value. If we haven't even ingested it, then it is our latest version of the value.
205
+ valuesNewToUs = valuesNewToUs.map(value => authorityStorage.getValueExactMaybeRejected(value.path, value.time) || value);
206
+ await PathValueControllerBase.authorityShareValues({ pathValues: valuesNewToUs });
200
207
  }
201
208
  }
202
209
 
@@ -211,6 +218,7 @@ export class PathValueControllerBase {
211
218
  nodeId: otherAuthority,
212
219
  pathValues: values,
213
220
  reason: "authorityShareValues",
221
+ keepLocks: true,
214
222
  }), () => new Error(`Timeout forwarding shared values (${values.length} values) to authority ${otherAuthority}`));
215
223
  } catch (error: any) {
216
224
  console.error(error.message, { otherAuthority, count: values.length });