Commit Graph
988 Commits
Author SHA1 Message Date
Ping Qiu 257263e357 Merge pull request #107 from seaweedfs/feat/workspace-restore-head
durable: claim HEAD before empty-host restore and fence stale serving
2026-11-15 10:33:11 -08:00
Ping Qiu 49b726d6dd durable: remove successful write logging without weakening I/O drain (#105) 2026-11-15 10:18:02 -08:00
Ping QiuandClaude Opus 5.5 e048246c0a storage: capture-path intents (write before upload, settle after the CAS) (#122)
* storage: capture-path intent schedules (RED)

A cut that uploads writes an intent naming exactly its keys before the
first upload and deletes its own intent after the confirmed CAS; no
upload, no intent; a failed intent write uploads nothing; a failed
upload or a refused CAS deletes the intent; an unknown CAS outcome keeps
it until the next cut settles the proposal; a lost CAS response
confirmed by re-read deletes it; a failed delete is retried at the next
cut; other intents are untouched. The fake remote gains intent failure
hooks and records written intents.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* storage: the capture path writes an intent before uploading and settles it

A cut that uploads chunks now writes one intent naming exactly the keys
it will upload, at the cut's base HEAD generation with the layer's epoch
and holder. The intent is durable before the first upload; if it cannot
be written, nothing is uploaded. A cut that only drops chunks writes
none.

The cut deletes only its own intent, once its outcome is settled:
- after the HEAD CAS succeeds, or a HEAD re-read confirms its proposal;
- on a clean abort: a failed upload, a refused admission, a fence, or a
  HEAD that moved past the CAS's base.

An unknown CAS outcome keeps the intent with the pending proposal. The
next cut deletes it once that proposal is settled, whether it landed or
can never land. A failed delete never fails a settled cut; the next cut
retries it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 10:17:53 -08:00
Ping Qiu 18746f0e12 Merge pull request #119 from seaweedfs/w2/chunk-contract
storage, blockvolume, volume, sw-block: chunk control contract fixes (remote_lsn order, holder, codes, CLI errors, show)
2026-11-15 10:17:44 -08:00
Ping Qiu 55d45ef0bd Merge pull request #116 from seaweedfs/w2/chunk-cli
sw-block: ops chunk cut|snapshot|detach|snapshots|snapshot-delete|fork
2026-11-15 10:17:30 -08:00
pingqiu a9e515798f fix: restore seeded frontier and reactivate detached HEAD before serving 2026-11-15 10:05:23 -08:00
pingqiuandClaude Opus 5.5 0826d846db chunkstore: decide from one read of the entry acted on
Review of the attempt-scoped layout (one rule for both P1s: the decision
comes from ONE read of the entry acted on, and success from re-reading the
entry the operation tried to create):
- EnsureVolume decides a fork's attach from one HEAD read: absent and
  aborted both refuse (fork_incomplete), so a sweep between two reads can
  no longer pass an aborted HEAD.
- Fork decides from the HEAD it re-reads after its create: a real HEAD
  completes the fork; an aborted tombstone means the fork lost to a sweep
  (target_exists, its intent dropped, the tombstone is permanent); an
  unreadable HEAD after a refusal is retryable, never a replay.
- A snapshot completes from its own attempt entry, never by resolving the
  reusable name again; a snapshot tombstone carries no attempt stamp, so it
  is never taken for this attempt's create.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 09:55:30 -08:00
pingqiuandClaude Opus 5.5 9f597b111a chunkstore: attempt-scoped snapshot publication; fork HEAD tombstones
W5 ruling (2026-11-15 17:30Z), W2 part: a GC sweep settles a dead copy
attempt by claiming the operation's final publishing entry with an aborted
tombstone, and every attempt publishes to a target that is never freed.

- Snapshot: the name is taken by an exclusive name record
  snapnames/<name> {request, attempt}; the intent names the attempt
  (holder "snapshot:<vol>/<name>/<attempt>"); the snapshot is published by
  an exclusive create at snaps/<name>/<attempt>. A retry of the same
  request publishes to the same attempt path. List and Fork resolve names
  through the record and skip aborted or unpublished attempts.
  DeleteSnapshot marks the attempt deleting (or claims an unpublished
  attempt's path with a tombstone) and removes the name record, freeing
  the name; attempt paths are never removed, so a late insert always
  fails. Catalog.AbortSnapshot(vol, name, attempt) is the sweep's claim.
- Fork: the publishing entry is the target's HEAD. Catalog.AbortFork
  claims it with an aborted HEAD tombstone (state "aborted", gen 1, no
  chunks); a fork whose HEAD is a tombstone never attaches
  (fork_incomplete) and its replay is target_exists.
- The copy-intent deadline stays as metadata only.

A deleted snapshot no longer holds its name: it is no longer listed (even
with includeDeleting) and a fork of its name is snapshot_not_found; its
attempt entry stays for GC.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 09:43:37 -08:00
Ping Qiu 5389a441ff perf(storage): reuse already durable WAL sync generations (#106)
* test(storage): count physical WAL syncs for paired TCP Flush commands

* perf(storage): deduplicate already durable WAL generations

* test(storage): gate concurrent sync cut and conservative bypass controls

* test(nvme): verify Flush ACK survives process crash and retain barrier gates

* test(storage): join crash helper diagnostics before reading

* test(storage): reproduce recovered partial batch reusing stale sync coverage

* fix(storage): invalidate sync coverage after partial append and recovery

* docs(storage): distinguish recovery invalidation from direct-path bypass
2026-11-15 09:10:34 -08:00
Ping Qiu 87098238c5 Merge pull request #115 from seaweedfs/w2/chunk-http
volume, durable, blockvolume: /chunk/* control routes and the VOLUME attach check
2026-11-15 09:10:24 -08:00
Ping Qiu b15faeea96 Merge pull request #111 from seaweedfs/w2/catalog-fork-detach
chunkstore, storage: snapshot catalog, fork, detached HEAD and Detach
2026-11-15 09:10:11 -08:00
Ping Qiu 2c535811e4 Merge pull request #110 from seaweedfs/w2/chunkstore-list-delete-qualified
chunkstore: filer list and conditional delete, owner-qualified keys, intents seam
2026-11-15 09:09:57 -08:00
Ping Qiu 1c0892981d Merge pull request #108 from seaweedfs/w2/chunk-cut-result
storage: chunk Cut returns the installed HEAD; typed capture refusals
2026-11-15 09:09:41 -08:00
pingqiuandClaude Opus 5.5 e1da68753b chunkstore: copy intents record their deadline; the publish is bounded by it
W5 ruling (2026-11-15 17:06Z), W2 part: a snapshot or fork copy intent
records its absolute publication deadline (DeadlineNs: the read time plus
OpDeadline); the deadline is re-checked immediately before the publishing
exclusive create, and that create runs under a context bounded by the same
deadline, so it never publishes after it. GC may then expire a copy intent
by its recorded deadline (plus RPC timeout and grace) instead of by epoch.
The re-read that settles an ambiguous create keeps the caller's context.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 09:09:36 -08:00
Ping Qiu c29f7706a9 Merge pull request #114 from seaweedfs/blockc/chunk-provider-swfs-r6
durable: walstore-chunk provider with a SeaweedFS chunk remote
2026-11-15 09:09:27 -08:00
pingqiuandClaude Opus 5.5 122321b9e0 durable: a layer fenced at attach fails recovery and never serves
Integration ruling F2: when the chunk layer attaches fenced (HEAD belongs
to a newer epoch or another holder, e.g. another server serving the same
replica), RecoverVolume fails with ErrChunkLayerFenced and the volume stays
non-operational, before anything can serve; the deferred authority attach
does not enable I/O either. HEAD is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 07:44:09 -08:00
pingqiuandClaude Opus 5.5 fb939771f6 storage, chunkstore: a fresh volume starts with an initial HEAD and an empty bitmap
Integration ruling F1(a):
- Catalog.EnsureVolume (the attach check) gives a created volume its
  initial HEAD with the VOLUME entry: gen 1, epoch 0, no holder,
  remote_lsn 0, no chunks (all zero), by exclusive create. An existing HEAD
  is kept (a volume published before VOLUME entries), and a missing one is
  created on the next attach.
- A fresh local volume (FreshFromHead) without a saved bitmap starts with
  an empty bitmap bound to HEAD instead of hash mode: it took no write
  before its first attach, so its image is HEAD's. Its first cut uploads
  only the chunks written. Hash mode stays for an existing volume whose
  bitmap is lost (F1(b)'s background reconciliation is separate work).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 07:44:09 -08:00
pingqiuandClaude Opus 5.5 4c25191694 sw-block: ops chunk show
Prints one volume's VOLUME entry and HEAD from the filer (B9 W2 §0.1 and
appendix 2026-11-15 14:30Z): {volumeID, volume, head}, each null when it
does not exist; a HEAD without a state shows as active. Catalog.ReadHead
reads the HEAD; the show body lives with the other shared API bodies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 06:17:18 -08:00
pingqiuandClaude Opus 5.5 341c80b2fb sw-block, volume: errors are the JSON error body on stdout
ops chunk failures print {code,message,retryable} on stdout, the same body
the routes answer (relayed as-is for an HTTP error), with a log line on
stderr and a non-zero exit (2 for usage errors) (B9 W2 appendix,
2026-11-15 14:30Z). CLI-side failures use the routes' codes: bad_request
for usage, remote_unavailable (retryable) when blockvolume or the filer
cannot be reached, internal otherwise; catalog refusals keep their code.

Messages no longer repeat the code: CatalogError.Detail is the message
and cause without it, used by the routes and the CLI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 06:15:09 -08:00
pingqiuandClaude Opus 5.5 f947bd4063 volume, chunkstore: lsn_behind, closing 409 after detach, invalid_label, no cut stats
Contract revisions from integration (B9 W2 appendix, 2026-11-15 14:30Z, and
the rulings of 14:09Z):
- a cut behind HEAD's remote_lsn answers lsn_behind (409, not retryable);
- a detached layer answers closing with 409 (it stays closed until a new
  attach); a closed layer (process shutdown) stays closing 503;
- an invalid label is invalid_label (400), and SnapshotReplay validates
  labels and consistency with the name and request id, so a bad request is
  refused before any cut;
- the /chunk/cut body omits the cut statistics until W3 fills them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 06:12:20 -08:00
pingqiuandClaude Opus 5.5 e483d45728 blockvolume: HEAD holder is <server-id>/<replica-id>
The replica id alone made two hosts that both serve replica r1 look like
the same holder returning, so the later one was not fenced (B9 W2
appendix, 2026-11-15 14:30Z). blockvolume now passes
<server-id>/<replica-id> as the provider's ChunkHolder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 06:11:08 -08:00
pingqiuandClaude Opus 5.5 b06bf7dc45 storage: HEAD's remote_lsn never decreases
A cut whose LSN is below the base HEAD's remote_lsn is refused before any
upload (ErrChunkCaptureRefused with ErrChunkLSNBehind; the expected gen
pins that base HEAD), unless that HEAD belongs to a newer holder, which
fences as before. MemChunkRemote refuses a lowering CAS too (B9 W2
appendix, 2026-11-15 14:30Z).

Until LSN continuity across hosts exists, a fresh, migrated or forked
volume cannot cut or detach; the carry-forward must merge before or with
this check. Tests that model a host continuing from a seeded HEAD now
advance the local log to that HEAD's remote_lsn first, as the
carry-forward will.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 06:11:08 -08:00
pingqiuandClaude Opus 5.5 95b6b7d62e sw-block: ops chunk never exits 0 with its result lost
An HTTP response over the 64 MiB limit is refused (read limit+1) instead of
being relayed truncated, and every result write checks for a failed or
short write, for the route commands and the filer commands alike. There is
no retry of the operation: the error says the result was not relayed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 05:51:12 -08:00
pingqiuandClaude Opus 5.5 399d3a8ead sw-block: ops chunk cut|snapshot|detach|snapshots|snapshot-delete|fork
The walstore-chunk control plane on the command line (B9 W2 §0.1, §3):
- cut, snapshot and detach call a blockvolume's /chunk/* routes
  (--status-addr, with --chunk-control-endpoint); the request carries
  timeoutMs and the client waits a little longer;
- snapshots, snapshot-delete and fork read and write the filer directly
  (--chunk-filer, --chunk-path), so they work while the volume is offline;
- snapshot and fork generate a request id when none is given and print it
  on stderr for a retry; --label k=v repeats;
- stdout carries the operation's JSON body (the route's, or the shared
  list/delete bodies, or the fork result with remoteLSN); a failure prints
  "<code>: <message> (retryable=...)" and exits 1; usage errors exit 2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 05:35:16 -08:00
pingqiuandClaude Opus 5.5 0c5ea94830 chunkstore: the snapshot list and delete bodies as shared API types
SnapshotListItem / SnapshotListBody (exactly B9 §3.3's fields) and
SnapshotDeleteBody move from the volume routes to chunkstore, so the
sw-block CLI, which reads the filer directly, emits the same bodies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 05:35:16 -08:00
pingqiuandClaude Opus 5.5 f94b20724b durable, volume: one owned drain, one handle lookup, one JSON object per request
- StopIO keeps one pending drain per backend; every StopIO waits on it,
  so timed-out detach retries behind a held I/O no longer each leave a
  goroutine waiting for the admission lock.
- CutVolume resolves the volume's handle and layer in one critical section
  (chunkHandle) and keeps that handle: a Close that empties the volume map
  mid-call no longer leaves the minLSN check reading a missing handle.
- A /chunk/* request body must be exactly one JSON object: trailing data
  is bad_request before any operation runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 05:34:42 -08:00
pingqiuandClaude Opus 5.5 410efb6d03 volume: snapshot replay before the cut, minLSN in the provider, JSON transport errors
- Snapshot resolves its request with Catalog.SnapshotReplay first: a retry
  of a recorded request returns it and another request gets
  snapshot_exists, both without cutting (so a replay survives a detached,
  fenced or unreachable cut path).
- Cut passes minLSN to the provider, which refuses an LSN never written
  before publishing.
- outcome_unknown is reported whenever an unresolved CAS is in the error,
  also when the re-proposal was refused for authority.
- Transport errors are JSON like every /chunk/* response (ruling of
  2026-11-15): bad_request (400), method_not_allowed (405), forbidden (403).
- timeoutMs is compared with OpDeadline in milliseconds before converting,
  so a huge value selects OpDeadline instead of overflowing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 05:22:27 -08:00
pingqiuandClaude Opus 5.5 861855a021 chunkstore: SnapshotReplay resolves a snapshot request before a cut
The recorded snapshot for the same request id (Replayed), snapshot_exists
for another, or a free name, after validating the name and request id
(B9 W2 §3.2 step 1). CreateSnapshot uses it for its own pre-check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 05:22:27 -08:00
pingqiuandClaude Opus 5.5 97f460d181 durable: Detach drains admitted I/O and stays stopped; minLSN refused first
- StorageBackend gains an I/O admission boundary: Read, Write and Sync
  hold the read side of ioMu for the whole operation, gate included, and
  check the closed and operational flags once before the lock so I/O
  arriving during a drain fails at once. StopIO refuses new I/O and waits,
  bounded by ctx, for the I/O admitted before the stop.
- DetachVolume latches the volume as detached for this process (under the
  attach lock), stops and drains frontend I/O before the periodic loop
  and the final cut, so no write is acknowledged outside the detached
  image; a drain that times out fails the detach with I/O still stopped.
  RecoverVolume and the deferred authority attach no longer reopen a
  latched volume (ErrChunkLayerDetached); a retry settles the detach and a
  repeated call returns the first result.
- CutVolume takes minLSN: an LSN never written is refused before anything
  is published (MakeRemoteDurable's refusal), and the cut must reach it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 05:22:27 -08:00
pingqiuandClaude Opus 5.5 608f9efbfc blockvolume: --chunk-control-endpoint mounts the /chunk/* routes
Off by default; only with --durable-impl=walstore-chunk and a
--status-addr. The routes are served from the durable provider and the
catalog under --chunk-path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 04:54:50 -08:00
pingqiuandClaude Opus 5.5 985a825ac5 blockvolume: apply the VOLUME attach rules before the chunk layer attaches
walstore-chunk now dials one filer client for the per-volume remotes and
a catalog under the same --chunk-path, and wires the provider's attach
check to Catalog.EnsureVolume with the local geometry (B9 W2 §4.2, ruling
of 2026-11-15): the first attach creates VOLUME, and an attach is refused
with geometry_mismatch, or with fork_incomplete for a fork whose HEAD is
not written yet. It runs before any HEAD read or CAS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 04:54:24 -08:00
pingqiuandClaude Opus 5.5 8b3e0cfbce chunkstore: MemFiler, an in-memory Filer for tests outside the package
Exclusive create, conditional update and delete on extended attributes,
and name-ordered listing of one directory's children, like
storage.MemChunkRemote for the chunk remote. The volume control adapter's
test uses it instead of its own copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 04:54:14 -08:00
pingqiuandClaude Opus 5.5 4f2e85fea0 volume: /chunk/* control routes on the status listener
POST /chunk/cut, /chunk/snapshot, /chunk/snapshot/delete, /chunk/detach and
GET /chunk/snapshots (B9 W2 §2.1-§2.2, §3.1-§3.4, §3.6), mounted only
after EnableChunkControlEndpoint and wired by SetChunkControl:
- loopback-only like the listener; JSON request bodies (unknown fields are
  refused) and ?volume= for the list; volume_not_served for another volume
  and not_chunk_volume until a control is wired;
- success bodies carry exactly the spec's field names (§3.1-§3.4, §3.6);
- failures answer {"code","message","retryable"} with the §2.2 code and
  status, plus the 2026-11-15 rulings: awaiting_assignment (409, retryable)
  for a layer that waits for the master's assignment, not_primary not
  retryable, internal (500) for anything unmapped; transport errors
  (method, client, malformed request) stay plain text as on the rest of
  the listener;
- long operations run under min(timeoutMs, OpDeadline).

NewChunkControl serves the routes from the durable provider (cut, detach)
and the catalog (snapshots): Snapshot validates the name and request id
before it cuts, then stores the HEAD that cut installed; Cut with minLSN
fails unless the cut reaches it. The cut statistics fields read zero until
W3 fills them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 04:51:55 -08:00
pingqiuandClaude Opus 5.5 7581a5b51a durable: CutVolume and DetachVolume
CutVolume takes one quiesced cut and returns what it installed (cut LSN,
HEAD, statistics). DetachVolume is a clean stop's final cut (B9 W2 §3.6):
under the volume's attach lock it stops frontend I/O and the periodic
cuts, then publishes the one detached-HEAD cut, and returns it with the
last written LSN. A repeated call returns the first result; a failure
leaves I/O stopped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 04:50:59 -08:00
pingqiuandClaude Opus 5.5 70853854f3 durable: an attach-time check hook ahead of the chunk layer attach
ProviderConfig.ChunkAttachCheck runs before every chunk layer attach, ahead
of any remote read or CAS (and so ahead of a takeover CAS), with the
volume's local geometry (blocks, block size, chunk blocks). A non-nil error
refuses the attach and the volume stays non-operational. blockvolume wires
it to the VOLUME entry's attach rules (B9 W2 §4.2, ruling of 2026-11-15).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 04:50:46 -08:00
pingqiuandClaude Opus 5.5 9d7156dc8d storage, durable: typed causes for the chunk control codes
The causes the /chunk/* routes report as B9 codes are now reachable with
errors.Is:
- storage: ErrChunkLayerClosed (closing), ErrChunkBaseInstalling
  (base_installing, inside ErrChunkCaptureRefused), ErrChunkRemoteUnavailable
  (an upload failure), and ErrChunkHeadPrecondition on every CAS that did
  not apply because HEAD moved, whatever error the CAS returned;
- durable: ErrChunkNotPrimary and ErrChunkEpochStale as the causes of the
  provider's capture admission refusals.

Messages are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 04:50:28 -08:00
pingqiuandClaude Opus 5.5 53e5262fda storage: re-check capture admission before re-proposing a held CAS
Re-proposing an unresolved CAS at its base is a new publication. It now
passes the capture admission again right before the CAS is sent, after
the blocking HEAD read: a demotion or lineage change during that read sends
no CAS, keeps the CAS unresolved, and returns the refusal (with
errChunkCASOutcomeUnknown still in the chain). Once authority is back, the
same proposal settles at the same base.

The fake remote gains onGetHead, a hook that runs inside each HEAD read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 04:47:55 -08:00
pingqiuandClaude Opus 5.5 2d598a4dbd storage: gofmt the chunk layer's state fields
The r4 field pendingBase left the rest of the block misaligned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 04:38:07 -08:00
pingqiuandClaude Opus 5.5 24cbab0f27 chunkstore: each attempt deletes only its own intent
Snapshot and fork attempts stamp the entry they create with their intent id
(swb.attempt). An attempt deletes its own intent only when its own create is
confirmed (applied, or found by the re-read with its attempt id) or refused
by the filer's "already exists" answer, or when it never sent the create
(deadline). Any other failure leaves the create unsettled and the intent in
place, even when the re-read finds another attempt's entry: the held create
may land after that entry is removed. No attempt, and no replay, deletes
another attempt's intent (W5 rule); tag-wide settleIntents is removed.

The fake filer gains held creates (deferCreate) and releaseDeferredCreates,
which applies them later only if the name is still free.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 04:26:56 -08:00
pingqiuandClaude Opus 5.5 fe9df65af8 storage: settle a held cut CAS by re-proposing it at the same base
A cut or detach CAS whose outcome is unknown while HEAD still reads its
base generation may still be applied by the server later. Reading HEAD
alone no longer settles it: the capture keeps the proposal pending, and the
next cut, durability point or Detach re-issues the same proposal at the same
base. Whichever lands first, HEAD ends at that proposal and the other fails
its precondition, so a delayed detach can never land after a no-op cut.

The fake remote gains a held CAS mode (casDeferred) and releaseDeferredCAS,
which applies held CAS calls later only if HEAD is still at their base.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 04:26:56 -08:00
pingqiuandClaude Opus 5.5 d0e3107c57 storage, chunkstore: HEAD state/detachedBy per the schema ruling; one-CAS Detach
Follows the HEAD schema ruling (2026-11-15), replacing the boolean
detached flag of the previous revision:

- HEAD carries a canonical "state": "active" | "detached" (a document
  without it reads as active), and "detachedBy": {holder, epoch, gen}
  only when detached; a reader refuses a detachedBy that is not the
  HEAD's own holder, epoch and generation.
- Detach is one detach cut: its CAS publishes the final cut with state
  detached and detachedBy = {holder, epoch, the generation that CAS
  installs}. It always CASes, also with nothing new. Afterwards cuts are
  refused (ErrChunkLayerDetached); a repeated Detach returns the result.
- Every normal cut publishes state active and no detachedBy, so a new
  holder's cut over a detached HEAD clears it.
- An unresolved detach CAS is settled like any unresolved CAS, before the
  next capture or Detach: applied means detached, not applied continues,
  a newer holder fences, unreadable is ErrChunkCASOutcomeUnknown. This
  replaces the separate pending-mark state.
- A fork's HEAD is published with state active.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 04:20:41 -08:00
pingqiuandClaude Opus 5.5 681becfff0 chunkstore, storage: settle intents and fork replays; settle a pending detach
Review fixes for the snapshot catalog, fork and Detach:

- Intents stay until the operation's outcome is settled. An exclusive
  create that fails is resolved by re-reading the entry: our entry
  confirms the publish; another entry means our create can never land
  (clean abort); a failed re-read or no entry leaves the outcome unknown
  (it may still land), so the intents are kept and the call reports
  outcome_unknown. A retry with the same request id settles it and
  removes every intent of the operation (by its holder tag).
- Fork records its operation in the target's VOLUME (request id, source,
  snapshot, source gen, the SHA-256 of the snapshot's HEAD document and
  the original result). A retry resolves the target first: a completed
  fork replays the recorded result without reading the source (also
  after the source snapshot is deleting, or the target advanced); a
  request id reused with other parameters is target_exists; an
  incomplete fork resumes only if the snapshot still has the bound image.
- An unresolved Detach mark (CAS outcome and re-read both failed) becomes
  a pending detach that every later capture, durability point and Detach
  settles first: applied means detached, not applied continues, a newer
  holder fences, still unreadable is ErrChunkCASOutcomeUnknown. A cut can
  no longer succeed at the pre-mark generation. Unresolved capture CAS
  outcomes now also wrap ErrChunkCASOutcomeUnknown.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 04:20:41 -08:00
pingqiuandClaude Opus 5.5 1ec7b9975b chunkstore, storage: snapshot catalog, fork, detached HEAD and Detach
Control-plane metadata and operations over the filer (B9 W2 spec §3-§5):

- Catalog (core/frontend/chunkstore/catalog.go):
  - VOLUME entry <base>/<vol>/VOLUME: identity, geometry, origin and
    parent, write-once. EnsureVolume applies the attach rules (create a
    missing one; geometry_mismatch; fork_incomplete for a fork without
    HEAD).
  - CreateSnapshot stores the HEAD a cut installed as snaps/<name>
    (o_excl; the same request id replays, another is snapshot_exists),
    under an intent naming its keys until the entry is written, and
    refuses the write past OpDeadline.
  - ListSnapshots pages in name order (deleting ones hidden unless asked);
    DeleteSnapshot only marks deleting (conditional on state and gen);
    ListVolumes lists volume directories for GC.
  - Fork: VOLUME (origin fork, parent) then HEAD at gen 1, epoch 0, no
    holder, the snapshot's remote_lsn (LSNs carry forward), every ref
    owner-qualified as "@<owner>/<key>" (an already qualified ref keeps
    its owner), under an intent on the target; replays by request id.
  - Typed errors with the spec's codes (CatalogError, CodeOf).
- HEAD gains Detached (JSON "detached", omitted when false). The chunk
  layer's Detach takes a final cut, then CASes the same image once more
  with Detached set; afterwards cuts are refused (ErrChunkLayerDetached)
  and a repeated Detach returns the first result. A normal cut always
  publishes Detached = false.

No entry carries filer chunks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 04:20:41 -08:00
pingqiuandClaude Opus 5.5 ade97bcb8f durable: intent calls on the close-bound remote use pointer receivers
On #114 the close-bound remote holds a mutex for the attach context, so
the intent wrappers take a pointer like every other bound call; a value
receiver copied the lock (go vet copylocks).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 04:20:33 -08:00
pingqiuandClaude Opus 5.5 eba04ab67d storage, chunkstore: enforce the chunk key domain before persistence
Review fix for the intents seam: an intent document is JSON, which would
silently replace invalid UTF-8 in a key, while a key binding preserves the
bytes, so a protected key could list back as a different key. The chunk
key domain is now non-empty valid UTF-8, refused at Put and, for every
key, at PutIntent by the SeaweedFS remote, MemChunkRemote and the test
fake before anything is written (storage.ValidChunkKey,
ErrChunkKeyInvalid; chunkstore wraps it in ErrInvalidKey). Unicode and
owner-qualified keys round-trip byte-identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 04:20:06 -08:00
pingqiuandClaude Opus 5.5 008b96307b chunkstore: filer list and conditional delete, owner-qualified keys, intents
Remote plumbing for the chunk control plane (snapshot, fork, GC):

- Filer gains ListEntries (one page, name order, a missing directory lists
  as empty) and DeleteEntry with expected_extended (never deletes data;
  a failed condition, including a missing entry, is ErrPrecondition). The
  filer proto subset adds ListEntries with seaweed-mono's field numbers;
  regenerated with the same protoc and plugin versions.
- ChunkRemote resolves owner-qualified keys "@<owner>/<key>" in the owner
  volume's keys/ directory, so a fork can name its parent's chunks with
  one HEAD write. Put refuses them: a volume writes only its own keys.
  The owner must be one plain path element (CheckVolumeID).
- storage.ChunkRemote gains the W5 intents seam: PutIntent returns a
  per-call id "<gen>-<nonce>", DeleteIntent removes only that id, and
  ListIntents lists every live intent or fails (never skips one). The
  SeaweedFS remote stores them at <root>/intents/<id>; MemChunkRemote,
  the storage test fake and the provider's close-bound wrapper implement
  them too. The capture path calling them is separate work.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 04:20:06 -08:00
pingqiuandClaude Opus 5.5 4c810b007c storage: carry-forward LSN note; witness the injected takeover race
Review follow-ups for the chunk Cut change:
- the ChunkCutResult comment now states the W4 ruling: a volume's LSNs
  carry forward across hosts (a new host starts at HEAD.RemoteLSN + 1, a
  fork after its snapshot's RemoteLSN), so RemoteLSN never decreases;
- the tagged takeover race test accepts a failed attach only when the
  old holder's competing CAS was actually injected before the takeover
  CAS, and only when the new holder published nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 04:19:47 -08:00
pingqiuandClaude Opus 5.5 dfcc9e7126 storage: chunk Cut returns the installed HEAD; typed capture refusals
Cut(ctx) takes the same quiesced cut as Capture and returns the HEAD its
own CAS installed (or the current HEAD for a cut with nothing new), so a
snapshot can copy exactly the image of cut H even when other cuts follow.
Capture keeps returning H through Cut. A ChunkCutStats struct is declared
for the periodic-cut work to fill.

A capture refused by the owner's CaptureAllowed check now wraps the
owner's error with %w, so callers can tell "not primary" from "lineage
changed" with errors.Is.

Also adds the RED tests for the takeover CAS at attach, behind the
chunk_takeover_red build tag, for the work that implements it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 04:19:47 -08:00
pingqiuandClaude Opus 5.5 fdb339f091 durable: schedule for a stale authority wait past its tick check
The authority wait of recovery A passes its per-tick generation check
and is parked (test-local one-shot projection barrier) inside its
projection read. Recovery B then fails on the real WAL integrity fault.
Released with authority, A must not start a remote attach, publish a
layer or admit I/O; only the re-check under the per-volume
serialization stops it. Repaired recovery C converges. Tests only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 04:10:17 -08:00
pingqiuandClaude Opus 5.5 c1a986a63e durable: walstore-chunk authority wait is bound to its recovery generation
A deferred authority wait kept acting after a newer RecoverVolume. If
that newer recovery failed, the old wait still attached the layer and
set the backend operational once authority arrived, overriding the
failed recovery.

Each RecoverVolume of a walstore-chunk volume now takes the next
recovery generation (under the per-volume serialization), and an
authority wait carries the generation that registered it. A wait whose
generation is no longer the latest exits. It checks on every tick, and
again under the per-volume serialization right before attaching, so it
never attaches or touches the backend for a superseded recovery. After
a failed recovery the backend stays refused until a later recovery
succeeds; that recovery attaches directly or starts its own wait.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 03:32:47 -08:00