feat(map): add first-writer-wins claim API on SharedDirectory#27291
Draft
kian-thompson wants to merge 2 commits into
Draft
feat(map): add first-writer-wins claim API on SharedDirectory#27291kian-thompson wants to merge 2 commits into
kian-thompson wants to merge 2 commits into
Conversation
Adds DDS-level first-writer-wins claim semantics on SharedDirectory's
root, gated behind runtime option `enableDdsClaims`.
- New `IClaimable`/`ClaimResult` types (legacy beta).
- New `claim` op kind in `IDirectoryOperation` carrying { key, value };
no path because claims are root-scoped.
- New optional `claims` field in `IDirectoryNewStorageFormat`;
back-compat preserved (loaders treat absence as empty).
- Local `set`/`delete` on a claimed root key throws UsageError;
remote `set`/`delete` ops are dropped on processing.
- `clear()` preserves claimed entries.
- Detached: claim resolves synchronously to Success and persists in
attach summary.
- Disposing the DDS resolves pending claim deferreds with AlreadyClaimed.
- On reload, no client is recorded as winner; repeat trySetClaim
resolves to AlreadyClaimed (loser-on-retry per spec).
Includes 12 unit tests covering: feature flag, single-client claim,
two-client race, repeat winner/loser semantics, set/delete throws,
clear preservation, detached round-trip, summary back-compat, and
sequenced rehydration.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Hi! Thank you for opening this PR. Want me to review it? Based on the diff (593 lines, 9 files), I've queued these reviewers:
How this works
|
Contributor
|
🔗 No broken links found! ✅ Your attention to detail is admirable. linkcheck output |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds an opt-in first-writer-wins claim API on
ISharedDirectory:trySetClaim(key, value): Promise<ClaimResult>— attempts to claim a root-level key. Resolves to"Success"if this client won, or"AlreadyClaimed"if another client's claim was sequenced first. Repeated calls from the original winner also resolve"Success".isClaimed(key): boolean— returnstrueif the root-level key is currently claimed.Once a key is claimed, the value is immutable:
setanddeletefor that key throwUsageError,getreturns the claimed value, andclear()does not remove claims. Claims are persisted in the summary and survive load (on rehydrate, no client is treated as the original winner).The API is gated behind a runtime opt-in (
enableDdsClaims: trueon the data store runtime options). CallingtrySetClaimorisClaimedwithout the flag throwsUsageError. Claims are only available on the rootISharedDirectory; subdirectories intentionally do not expose them.Implementation notes:
"claim"op type with its own message handler, rollback path, resubmit path, and stashed-op replay.claimsfield in theIDirectoryNewStorageFormatsummary blob (back-compat: absent on older snapshots).Reviewer Guidance
The review process is outlined on this wiki page.
trySetClaimpromise stays pending until reconnect (or dispose). Should we add anAbortSignalparameter or a disconnected-aware result, or just document the behavior? Marking as draft pending this discussion.applyStashedOppath re-submits a fresh claim op rather than reusing the stashed op directly — feedback welcome on whether that's the right approach.packages/dds/map/src/test/mocha/directory.claims.spec.ts.