@peerbit/shared-log 10.3.22 → 10.3.23-e3e1b7f
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/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +22 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/ranges.d.ts +11 -0
- package/dist/src/ranges.d.ts.map +1 -1
- package/dist/src/ranges.js +24 -21
- package/dist/src/ranges.js.map +1 -1
- package/package.json +70 -70
- package/src/index.ts +28 -0
- package/src/ranges.ts +40 -26
package/src/ranges.ts
CHANGED
|
@@ -2392,6 +2392,45 @@ export const matchEntriesInRangeQuery = (range: {
|
|
|
2392
2392
|
return new Or(ors);
|
|
2393
2393
|
};
|
|
2394
2394
|
|
|
2395
|
+
export const createAssignedRangesQuery = (
|
|
2396
|
+
changes: {
|
|
2397
|
+
range: {
|
|
2398
|
+
start1: number | bigint;
|
|
2399
|
+
end1: number | bigint;
|
|
2400
|
+
start2: number | bigint;
|
|
2401
|
+
end2: number | bigint;
|
|
2402
|
+
mode: ReplicationIntent;
|
|
2403
|
+
};
|
|
2404
|
+
}[],
|
|
2405
|
+
options?: { strict?: boolean },
|
|
2406
|
+
) => {
|
|
2407
|
+
let ors: Query[] = [];
|
|
2408
|
+
let onlyStrict = true;
|
|
2409
|
+
// TODO what if the ranges are many many?
|
|
2410
|
+
for (const change of changes) {
|
|
2411
|
+
const matchRange = matchEntriesInRangeQuery(change.range);
|
|
2412
|
+
ors.push(matchRange);
|
|
2413
|
+
if (change.range.mode === ReplicationIntent.NonStrict) {
|
|
2414
|
+
onlyStrict = false;
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
|
|
2418
|
+
// entry is assigned to a range boundary, meaning it is due to be inspected
|
|
2419
|
+
if (!options?.strict) {
|
|
2420
|
+
if (!onlyStrict || changes.length === 0) {
|
|
2421
|
+
ors.push(
|
|
2422
|
+
new BoolQuery({
|
|
2423
|
+
key: "assignedToRangeBoundary",
|
|
2424
|
+
value: true,
|
|
2425
|
+
}),
|
|
2426
|
+
);
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
|
|
2430
|
+
// entry is not sufficiently replicated, and we are to still keep it
|
|
2431
|
+
return new Or(ors);
|
|
2432
|
+
};
|
|
2433
|
+
|
|
2395
2434
|
export type ReplicationChanges<
|
|
2396
2435
|
T extends ReplicationRangeIndexable<any> = ReplicationRangeIndexable<any>,
|
|
2397
2436
|
> = ReplicationChange<T>[];
|
|
@@ -2564,35 +2603,10 @@ export const toRebalance = <R extends "u32" | "u64">(
|
|
|
2564
2603
|
rebalanceHistory: Cache<string>,
|
|
2565
2604
|
): AsyncIterable<EntryReplicated<R>> => {
|
|
2566
2605
|
const change = mergeReplicationChanges(changeOrChanges, rebalanceHistory);
|
|
2567
|
-
|
|
2568
|
-
const assignedRangesQuery = (changes: ReplicationChanges) => {
|
|
2569
|
-
let ors: Query[] = [];
|
|
2570
|
-
let onlyStrict = true;
|
|
2571
|
-
for (const change of changes) {
|
|
2572
|
-
const matchRange = matchEntriesInRangeQuery(change.range);
|
|
2573
|
-
ors.push(matchRange);
|
|
2574
|
-
if (change.range.mode === ReplicationIntent.NonStrict) {
|
|
2575
|
-
onlyStrict = false;
|
|
2576
|
-
}
|
|
2577
|
-
}
|
|
2578
|
-
|
|
2579
|
-
// entry is assigned to a range boundary, meaning it is due to be inspected
|
|
2580
|
-
if (!onlyStrict || changes.length === 0) {
|
|
2581
|
-
ors.push(
|
|
2582
|
-
new BoolQuery({
|
|
2583
|
-
key: "assignedToRangeBoundary",
|
|
2584
|
-
value: true,
|
|
2585
|
-
}),
|
|
2586
|
-
);
|
|
2587
|
-
}
|
|
2588
|
-
|
|
2589
|
-
// entry is not sufficiently replicated, and we are to still keep it
|
|
2590
|
-
return new Or(ors);
|
|
2591
|
-
};
|
|
2592
2606
|
return {
|
|
2593
2607
|
[Symbol.asyncIterator]: async function* () {
|
|
2594
2608
|
const iterator = index.iterate({
|
|
2595
|
-
query:
|
|
2609
|
+
query: createAssignedRangesQuery(change),
|
|
2596
2610
|
});
|
|
2597
2611
|
|
|
2598
2612
|
while (iterator.done() !== true) {
|