mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 19:17:28 +01:00
Guard mixed snapshot stamps and surviving sibling identities
This commit is contained in:
1 parent
ee3c3e493d
commit
0a6d952817
2 files changed
+57
-1
No files matched your search
@@ -47,7 +47,7 @@ func (h Head) StampSnapshotGenerations() (Head, bool, error) {
|
||||
// DeleteSnapshotAt removes only an already admitted incarnation. Admission
|
||||
// resolves initial absence separately; a retained target that has since gone
|
||||
// or been replaced succeeds without removing anything. Existing dependent
|
||||
// and volume-state checks still apply to an actual removal.
|
||||
// checks apply to actual removal; volume-state checks also apply to no-ops.
|
||||
func (h Head) DeleteSnapshotAt(name string, gen uint64) (Head, bool, error) {
|
||||
if gen == 0 {
|
||||
return Head{}, false, ErrSnapshotGenerationMissing
|
||||
|
||||
@@ -180,3 +180,59 @@ func TestRunDeleteSnapshotAt_InterruptAtEveryStep(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestMixedLegacyStampPreservesPublishedSibling(t *testing.T) {
|
||||
h := idleHead()
|
||||
h.Version = HeadVersion1
|
||||
h.Snapshots = map[string]Snapshot{"old": {Root: RootName{}, Gen: 4}, "legacy": {Root: RootName{}}}
|
||||
next, changed, err := h.StampSnapshotGenerations()
|
||||
if err != nil || !changed {
|
||||
t.Fatalf("mixed stamp: %v %v", changed, err)
|
||||
}
|
||||
if next.Snapshots["old"].Gen != 4 || next.Snapshots["legacy"].Gen != 8 {
|
||||
t.Fatalf("published identity reminted: %+v", next.Snapshots)
|
||||
}
|
||||
if h.Snapshots["old"].Gen != 4 || h.Snapshots["legacy"].Gen != 0 {
|
||||
t.Fatal("pre-CAS input changed")
|
||||
}
|
||||
raw, err := next.Encode()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
reread, err := DecodeHead(raw, 8, h.VolumeID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
retry, changed, err := reread.StampSnapshotGenerations()
|
||||
if err != nil || changed || retry.Snapshots["old"].Gen != 4 || retry.Snapshots["legacy"].Gen != 8 {
|
||||
t.Fatalf("mixed stamp reply-loss retry: %+v %v %v", retry.Snapshots, changed, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSnapshotDeletePreservesPublishedSibling(t *testing.T) {
|
||||
h := idleHead()
|
||||
h.Version = HeadVersion1
|
||||
h.Snapshots = map[string]Snapshot{"remove": {Root: RootName{}, Gen: 7}, "keep": {Root: RootName{}, Gen: 4}}
|
||||
st := &memHead{h: &h}
|
||||
next, err := RunDeleteSnapshotAt(t.Context(), st, "remove", 7)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(next.Snapshots) != 1 || next.Snapshots["keep"].Gen != 4 {
|
||||
t.Fatalf("survivor identity lost: %+v", next.Snapshots)
|
||||
}
|
||||
if len(h.Snapshots) != 2 || h.Snapshots["keep"].Gen != 4 || h.Snapshots["remove"].Gen != 7 {
|
||||
t.Fatal("source HEAD mutated")
|
||||
}
|
||||
raw, err := next.Encode()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !bytes.Contains(raw, []byte(`"gen":4`)) {
|
||||
t.Fatalf("survivor bytes lost generation: %s", raw)
|
||||
}
|
||||
reread, err := DecodeHead(raw, next.Gen, h.VolumeID)
|
||||
if err != nil || reread.Snapshots["keep"].Gen != 4 {
|
||||
t.Fatalf("persisted survivor: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user