@optimystic/db-p2p 0.25.1 → 0.27.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/dist/src/cluster/certified-claims.d.ts +17 -3
- package/dist/src/cluster/certified-claims.d.ts.map +1 -1
- package/dist/src/cluster/certified-claims.js +5 -3
- package/dist/src/cluster/certified-claims.js.map +1 -1
- package/dist/src/cluster/cluster-repo.d.ts +57 -92
- package/dist/src/cluster/cluster-repo.d.ts.map +1 -1
- package/dist/src/cluster/cluster-repo.js +149 -201
- package/dist/src/cluster/cluster-repo.js.map +1 -1
- package/dist/src/cluster/commit-proof.d.ts +16 -0
- package/dist/src/cluster/commit-proof.d.ts.map +1 -1
- package/dist/src/cluster/commit-proof.js +32 -1
- package/dist/src/cluster/commit-proof.js.map +1 -1
- package/dist/src/cluster/quorum-restore.d.ts +81 -28
- package/dist/src/cluster/quorum-restore.d.ts.map +1 -1
- package/dist/src/cluster/quorum-restore.js +148 -51
- package/dist/src/cluster/quorum-restore.js.map +1 -1
- package/dist/src/cluster/race-resolution.d.ts +89 -0
- package/dist/src/cluster/race-resolution.d.ts.map +1 -0
- package/dist/src/cluster/race-resolution.js +140 -0
- package/dist/src/cluster/race-resolution.js.map +1 -0
- package/dist/src/cluster/reconcile-block.d.ts +9 -4
- package/dist/src/cluster/reconcile-block.d.ts.map +1 -1
- package/dist/src/cluster/reconcile-block.js +28 -11
- package/dist/src/cluster/reconcile-block.js.map +1 -1
- package/dist/src/cluster/record-operations.d.ts +25 -0
- package/dist/src/cluster/record-operations.d.ts.map +1 -0
- package/dist/src/cluster/record-operations.js +56 -0
- package/dist/src/cluster/record-operations.js.map +1 -0
- package/dist/src/cohort-topic/host.d.ts +133 -51
- package/dist/src/cohort-topic/host.d.ts.map +1 -1
- package/dist/src/cohort-topic/host.js +290 -83
- package/dist/src/cohort-topic/host.js.map +1 -1
- package/dist/src/libp2p-node-base.d.ts +13 -4
- package/dist/src/libp2p-node-base.d.ts.map +1 -1
- package/dist/src/libp2p-node-base.js +5 -5
- package/dist/src/libp2p-node-base.js.map +1 -1
- package/dist/src/repo/cluster-coordinator.d.ts +9 -0
- package/dist/src/repo/cluster-coordinator.d.ts.map +1 -1
- package/dist/src/repo/cluster-coordinator.js +13 -2
- package/dist/src/repo/cluster-coordinator.js.map +1 -1
- package/dist/src/repo/coordinator-repo.d.ts +34 -2
- package/dist/src/repo/coordinator-repo.d.ts.map +1 -1
- package/dist/src/repo/coordinator-repo.js +57 -3
- package/dist/src/repo/coordinator-repo.js.map +1 -1
- package/dist/src/storage/block-latch.d.ts +5 -4
- package/dist/src/storage/block-latch.d.ts.map +1 -1
- package/dist/src/storage/block-latch.js +5 -4
- package/dist/src/storage/block-latch.js.map +1 -1
- package/dist/src/storage/block-storage.d.ts +1 -1
- package/dist/src/storage/block-storage.d.ts.map +1 -1
- package/dist/src/storage/block-storage.js +11 -3
- package/dist/src/storage/block-storage.js.map +1 -1
- package/dist/src/storage/cached-raw-storage.d.ts +17 -1
- package/dist/src/storage/cached-raw-storage.d.ts.map +1 -1
- package/dist/src/storage/cached-raw-storage.js +8 -1
- package/dist/src/storage/cached-raw-storage.js.map +1 -1
- package/dist/src/storage/cached-store-driver.d.ts +7 -0
- package/dist/src/storage/cached-store-driver.d.ts.map +1 -1
- package/dist/src/storage/cached-store-driver.js +20 -0
- package/dist/src/storage/cached-store-driver.js.map +1 -1
- package/dist/src/storage/i-block-storage.d.ts +45 -2
- package/dist/src/storage/i-block-storage.d.ts.map +1 -1
- package/dist/src/storage/i-block-storage.js +29 -0
- package/dist/src/storage/i-block-storage.js.map +1 -1
- package/dist/src/storage/i-raw-storage.d.ts +16 -0
- package/dist/src/storage/i-raw-storage.d.ts.map +1 -1
- package/dist/src/storage/kv-raw-storage.d.ts +5 -1
- package/dist/src/storage/kv-raw-storage.d.ts.map +1 -1
- package/dist/src/storage/kv-raw-storage.js +8 -1
- package/dist/src/storage/kv-raw-storage.js.map +1 -1
- package/dist/src/storage/raw-store-driver.d.ts +15 -0
- package/dist/src/storage/raw-store-driver.d.ts.map +1 -1
- package/dist/src/storage/shared-cache-pool.d.ts +5 -0
- package/dist/src/storage/shared-cache-pool.d.ts.map +1 -1
- package/dist/src/storage/shared-cache-pool.js +6 -1
- package/dist/src/storage/shared-cache-pool.js.map +1 -1
- package/dist/src/storage/storage-repo.d.ts.map +1 -1
- package/dist/src/storage/storage-repo.js +141 -99
- package/dist/src/storage/storage-repo.js.map +1 -1
- package/dist/src/storage/with-read-cache.d.ts +9 -5
- package/dist/src/storage/with-read-cache.d.ts.map +1 -1
- package/dist/src/storage/with-read-cache.js +16 -6
- package/dist/src/storage/with-read-cache.js.map +1 -1
- package/package.json +2 -2
- package/{README.md → readme.md} +2 -2
- package/src/cluster/certified-claims.ts +22 -9
- package/src/cluster/cluster-repo.ts +199 -212
- package/src/cluster/commit-proof.ts +38 -2
- package/src/cluster/quorum-restore.ts +183 -56
- package/src/cluster/race-resolution.ts +158 -0
- package/src/cluster/reconcile-block.ts +34 -11
- package/src/cluster/record-operations.ts +59 -0
- package/src/cohort-topic/host.ts +423 -118
- package/src/libp2p-node-base.ts +18 -9
- package/src/repo/cluster-coordinator.ts +1039 -1027
- package/src/repo/coordinator-repo.ts +1937 -1855
- package/src/storage/block-latch.ts +5 -4
- package/src/storage/block-storage.ts +11 -3
- package/src/storage/cached-raw-storage.ts +21 -1
- package/src/storage/cached-store-driver.ts +23 -0
- package/src/storage/i-block-storage.ts +47 -2
- package/src/storage/i-raw-storage.ts +17 -0
- package/src/storage/kv-raw-storage.ts +8 -1
- package/src/storage/raw-store-driver.ts +26 -0
- package/src/storage/shared-cache-pool.ts +6 -1
- package/src/storage/storage-repo.ts +143 -103
- package/src/storage/with-read-cache.ts +16 -6
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Introspection of a `RepoMessage`'s own operations — what a record touches and which action it
|
|
3
|
+
* names. Pure functions of their arguments, with no dependency on cluster member state, so the
|
|
4
|
+
* conflict/race path and the membership admission gate can share one definition of each.
|
|
5
|
+
*/
|
|
6
|
+
import type { RepoMessage } from "@optimystic/db-core";
|
|
7
|
+
import { blockIdsForTransforms } from "@optimystic/db-core";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Every block id the message's own operations name. Two consumers, deliberately sharing one
|
|
11
|
+
* definition: conflict detection (which writes must serialize against each other) and the membership
|
|
12
|
+
* admission gate's binding check in `cluster-repo.ts` (the set a legitimate `coordinatingBlockIds[0]`
|
|
13
|
+
* must come from — the check inside `deriveExpectedClusterView`, which makes a record naming anything
|
|
14
|
+
* else inadmissible). If the two ever disagreed, a coordinator could name a block the record is not
|
|
15
|
+
* judged to touch — so keep exactly one definition of this function and import it, never copy it.
|
|
16
|
+
*/
|
|
17
|
+
export function getAffectedBlockIds(operations: RepoMessage['operations']): string[] {
|
|
18
|
+
const blockIds = new Set<string>();
|
|
19
|
+
|
|
20
|
+
for (const operation of operations) {
|
|
21
|
+
if ('get' in operation) {
|
|
22
|
+
operation.get.blockIds.forEach(id => blockIds.add(id));
|
|
23
|
+
} else if ('pend' in operation) {
|
|
24
|
+
// Use blockIdsForTransforms to correctly extract block IDs from Transforms structure
|
|
25
|
+
blockIdsForTransforms(operation.pend.transforms).forEach(id => blockIds.add(id));
|
|
26
|
+
} else if ('commit' in operation) {
|
|
27
|
+
operation.commit.blockIds.forEach(id => blockIds.add(id));
|
|
28
|
+
} else if ('cancel' in operation) {
|
|
29
|
+
operation.cancel.actionRef.blockIds.forEach(id => blockIds.add(id));
|
|
30
|
+
} else if ('invalidate' in operation) {
|
|
31
|
+
// The invalidation writes compensating revisions to these blocks; surfacing them lets
|
|
32
|
+
// conflict detection serialize a concurrent commit racing the invalidation on a block.
|
|
33
|
+
operation.invalidate.blockIds.forEach(id => blockIds.add(id));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return Array.from(blockIds);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The action id the message names, or `undefined` if it names none. `pend`, `commit` and `cancel`
|
|
42
|
+
* each carry one; `get` and `invalidate` do not — an `invalidate` deliberately does NOT surface its
|
|
43
|
+
* `invalidatedActionId`, which names the action being reversed rather than this message's own, and
|
|
44
|
+
* would otherwise tell `operationsConflict` that an invalidation and the pend it reverses are "the
|
|
45
|
+
* same action" and need not serialize. `RepoMessage.operations` is a one-element tuple, so the scan
|
|
46
|
+
* is a formality; it returns on the first operation that carries an id either way.
|
|
47
|
+
*/
|
|
48
|
+
export function getActionId(operations: RepoMessage['operations']): string | undefined {
|
|
49
|
+
for (const operation of operations) {
|
|
50
|
+
if ('pend' in operation) {
|
|
51
|
+
return operation.pend.actionId;
|
|
52
|
+
} else if ('commit' in operation) {
|
|
53
|
+
return operation.commit.actionId;
|
|
54
|
+
} else if ('cancel' in operation) {
|
|
55
|
+
return operation.cancel.actionRef.actionId;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|