chunkstore: refuse snapshots of a restore until it is independent

A snapshot taken while a restore still names its source's chunks would keep that
lineage for its whole retention. CreateSnapshot on an Origin restore volume is
refused (restore_incomplete) until RESTORE-INDEPENDENT exists; a refused request
leaves no name or attempt. Test covers before, after own chunks without the
marker, and after the marker (the snapshot then names no foreign ref).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-20 19:58:03 -08:00
1 parent 566471971a
commit 796ef439e7
2 files changed
+38

No files matched your search

@@ -864,6 +864,16 @@ func (c *Catalog) CreateSnapshot(ctx context.Context, vol string, req SnapshotRe
if !ok {
return SnapshotInfo{}, catErr(CodeNotChunkVolume, false, nil, "volume %s has no VOLUME entry", vol)
}
if v.Origin == OriginRestore {
// A restore is independent only once its marker exists: a snapshot
// taken before would keep naming the source's chunks for its whole
// retention, so it is refused until then (DESIGN-r2 open question a).
if _, independent, err := c.ReadIndependence(ctx, vol); err != nil {
return SnapshotInfo{}, err
} else if !independent {
return SnapshotInfo{}, catErr(CodeRestoreIncomplete, false, nil, "volume %s is still being restored: snapshots are refused until it is independent", vol)
}
}
// Take the name: this request's record, or an earlier attempt's of it.
attempt, err := c.claimName(ctx, vol, root, req, head.Gen)
@@ -263,3 +263,31 @@ func TestRestore_WithoutLiveHeadNeverAttaches(t *testing.T) {
t.Fatalf("marker on an aborted restore: %v, want %s", err, CodeRestoreIncomplete)
}
}
// DESIGN-r2 open question (a), ruled: snapshots of a restore are refused until it is independent.
func TestRestore_SnapshotsRefusedUntilIndependent(t *testing.T) {
f, b, c, _ := restoreFixture(t)
ctx := context.Background()
r2, _ := NewChunkRemote(f, b, catBase+"/v2")
h2, _ := r2.GetHead(ctx)
if _, err := c.CreateSnapshot(ctx, "v2", SnapshotRequest{Name: "early", RequestID: "e"}, h2); CodeOf(err) != CodeRestoreIncomplete {
t.Fatalf("snapshot of a restore in progress: %v, want %s", err, CodeRestoreIncomplete)
}
if _, ok, err := c.SnapshotReplay(ctx, "v2", SnapshotRequest{Name: "early", RequestID: "e"}); err != nil || ok {
t.Fatalf("a refused snapshot must leave nothing: ok=%v err=%v", ok, err)
}
h := ownAll(t, f, b, "v2")
if _, err := c.CreateSnapshot(ctx, "v2", SnapshotRequest{Name: "late", RequestID: "l"}, h); CodeOf(err) != CodeRestoreIncomplete {
t.Fatalf("own chunks but no marker yet: %v, want %s", err, CodeRestoreIncomplete)
}
if _, err := c.MarkIndependent(ctx, "v2"); err != nil {
t.Fatal(err)
}
s, err := c.CreateSnapshot(ctx, "v2", SnapshotRequest{Name: "late", RequestID: "l"}, h)
if err != nil {
t.Fatalf("snapshot after the marker: %v", err)
}
if ForeignRefs(s.Head(), "v2") != 0 {
t.Fatalf("a snapshot of an independent restore names %d foreign refs", ForeignRefs(s.Head(), "v2"))
}
}