mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
Merge branch 'feat/oss-snap-identity' into feat/oss-snap-delete
# Conflicts: # docs/design/invariants.md
This commit is contained in:
commit
dcd7b3c5e5
3 files changed
+44
-20
No files matched your search
@@ -23,8 +23,11 @@ import (
|
||||
// its writes: a session that names a chunk no root named at its Begin
|
||||
// writes that chunk's entry (create, or reuse with a new tag), so the MARK
|
||||
// or the DELETE fails its condition, however late it lands. No lease
|
||||
// reasoning is needed. A candidate marked by another session is left
|
||||
// alone. Chunks a restore target names stay live: the source's snapshot
|
||||
// reasoning is needed. A candidate an earlier session marked and did not
|
||||
// delete (it died in between) is planned again: its tag carries that
|
||||
// mark, so the MARK replaces it, and the earlier session's late DELETE,
|
||||
// conditional on its own mark, fails. Every unreachable name is therefore
|
||||
// removed by the next completed cleaning. Chunks a restore target names stay live: the source's snapshot
|
||||
// root names them while it has dependents. It returns the names it
|
||||
// deleted, in index order.
|
||||
func RemoveUnreachable(ctx context.Context, st HeadStore, r *Reader, os ObjectStore, me HolderID, session string, shard uint64, candidates []ChunkName) ([]ChunkName, error) {
|
||||
@@ -42,7 +45,7 @@ func RemoveUnreachable(ctx context.Context, st HeadStore, r *Reader, os ObjectSt
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if found && meta.Mark == "" {
|
||||
if found {
|
||||
plan[c] = meta
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,17 +229,37 @@ func TestRemoveUnreachable_ASuccessorBeforeTheHeadViewStopsThePass(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
// A candidate already marked by another session is left alone.
|
||||
func TestRemoveUnreachable_LeavesAnotherSessionsMark(t *testing.T) {
|
||||
// A candidate an earlier session marked and never deleted (it died in
|
||||
// between) is reclaimed by the next cleaning, and the earlier session's
|
||||
// late delete, conditional on its own mark, fails once it is re-marked.
|
||||
func TestRemoveUnreachable_ReclaimsAnAbandonedMark(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
o, h, _, orphans := removeFixture(t)
|
||||
var p5 string
|
||||
for _, c := range orphans {
|
||||
if c.Index == 5 {
|
||||
o.objs[path.Join(volRoot, c.Path())].meta.Mark = "c0"
|
||||
p5 = path.Join(volRoot, c.Path())
|
||||
o.objs[p5].meta.Mark = "c0"
|
||||
}
|
||||
}
|
||||
removed, err := removeShard0(t, &memHead{h: h}, o, "c1", orphans)
|
||||
if err != nil || len(removed) != 1 || removed[0].Index != 7 {
|
||||
t.Fatalf("removed %v %v; want only chunk 7 (5 carries another session's mark)", removed, err)
|
||||
if err != nil || len(removed) != 2 {
|
||||
t.Fatalf("removed %v %v; want chunks 5 (abandoned mark) and 7", removed, err)
|
||||
}
|
||||
o2, _, _, orphans2 := removeFixture(t)
|
||||
var c5 ChunkName
|
||||
for _, c := range orphans2 {
|
||||
if c.Index == 5 {
|
||||
c5 = c
|
||||
o2.objs[path.Join(volRoot, c.Path())].meta.Mark = "c0"
|
||||
}
|
||||
}
|
||||
tag, _, _ := o2.Stat(ctx, c5.Path())
|
||||
if err := o2.Mark(ctx, c5.Path(), tag, "c1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := o2.DeleteMarked(ctx, c5.Path(), "c0"); !errors.Is(err, ErrPrecondition) {
|
||||
t.Fatalf("the dead session's late delete after the re-mark: %v; want ErrPrecondition", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,9 +316,9 @@ func cleaningPass(v *memVolume, session string, cands []ChunkName) error {
|
||||
// writes (BeginClean, each mark, each conditional delete, EndClean), before
|
||||
// the write applies and after it applied with its reply lost; at no point
|
||||
// does HEAD reach a missing object, and the restarted holder (a new
|
||||
// session) ends idle with every orphan of shard 0 removed and every
|
||||
// reachable object present. A mark left by the killed session is cleared
|
||||
// by nothing but a reuse, so a marked orphan stays until then.
|
||||
// session) ends idle with every orphan of shard 0 removed (also one the
|
||||
// killed session marked and did not delete) and every reachable object
|
||||
// present.
|
||||
func TestCleaningPass_InterruptAtEveryStep(t *testing.T) {
|
||||
fresh := func() (*memVolume, []ChunkName, []ChunkName) {
|
||||
o, h, live, orphans := removeFixture(t)
|
||||
@@ -341,8 +361,8 @@ func TestCleaningPass_InterruptAtEveryStep(t *testing.T) {
|
||||
for _, c := range orphans {
|
||||
p := path.Join(volRoot, c.Path())
|
||||
_, present := v.objects[p]
|
||||
if c.Index != 10001 && present && v.meta(p).Mark != "c1" {
|
||||
t.Fatalf("orphan %s still present and not held by the killed session's mark", c)
|
||||
if c.Index != 10001 && present {
|
||||
t.Fatalf("orphan %s still present after the re-run (mark %q)", c, v.meta(p).Mark)
|
||||
}
|
||||
}
|
||||
for _, c := range live {
|
||||
|
||||
@@ -537,19 +537,19 @@ stateDiagram-v2
|
||||
|
||||
| From | To | Guard | Enforced in | Protects |
|
||||
|---|---|---|---|---|
|
||||
| idle | snap(s) | caller is the holder at HEAD's epoch (epoch and server); HEAD present; snap(s) again is a replay, any other activity is refused | head.go `Head.Begin`, `runTransition` | `INV-SNAPK-HEAD-WRITE-001`, `INV-SNAPK-BEGIN-001` |
|
||||
| snap(s) | idle | holder at HEAD's epoch; activity is snap(s); over idle it succeeds without a write and means only that no activity remains | head.go `Head.Abort` | `INV-SNAPK-ABORT-001` |
|
||||
| snap(s) | idle, current = root | holder at HEAD's epoch; activity is snap(s); the previous manifest builds to HEAD's current root; the new own chunks, every segment and the root are present | commit.go `Head.Commit`, `RunCommit` | `INV-SNAPK-COMMIT-REACH-001`, `INV-SNAPK-TXN-INTERRUPT-001` |
|
||||
| idle | snap(s) | caller is the holder at HEAD's epoch (epoch, server and claim id); HEAD present; snap(s) again is a replay, any other activity is refused | head.go `Head.Begin`, `runTransition` | `INV-SNAPK-HEAD-WRITE-001`, `INV-SNAPK-BEGIN-001` |
|
||||
| snap(s) | idle | holder at HEAD's epoch (epoch, server and claim id); activity is snap(s); over idle it succeeds without a write and means only that no activity remains | head.go `Head.Abort` | `INV-SNAPK-ABORT-001` |
|
||||
| snap(s) | idle, current = root | holder at HEAD's epoch (epoch, server and claim id); activity is snap(s); the previous manifest builds to HEAD's current root; the new own chunks, every segment and the root are present | commit.go `Head.Commit`, `RunCommit` | `INV-SNAPK-COMMIT-REACH-001`, `INV-SNAPK-TXN-INTERRUPT-001` |
|
||||
| any | idle at epoch e, claim id k | e above HEAD's epoch (the same epoch, server and claim id is a replay; the same epoch and server with another claim id is refused); every older holder's lease has ended, checked after the read and before the update | claim.go `Head.Claim`, `RunClaim` (`LeaseWait.OldLeaseEnded`) | `INV-SNAPK-CLAIM-LEASE-001`, `INV-SNAPK-CLAIM-ID-001` |
|
||||
| idle | clean(c) | holder at HEAD's epoch; activity idle (clean(c) again is a replay) | clean.go `Head.BeginClean` | `INV-SNAPK-CLEAN-EXCL-001` |
|
||||
| clean(c) | idle | holder at HEAD's epoch; activity clean(c); over idle it succeeds without a write | clean.go `Head.EndClean` | `INV-SNAPK-CLEAN-EXCL-001` |
|
||||
| clean(c) | clean(c), names removed | holder at HEAD's epoch with clean(c) open (HEAD read once, after BeginClean); a name is deleted only if no root in HEAD (current or snapshot) names it in this volume's pool; each removal is a mark conditional on the plan's metadata, then a delete conditional on that mark | remove.go `RemoveUnreachable` | `INV-SNAPK-REMOVE-MARK-001` |
|
||||
| idle | clean(c) | holder at HEAD's epoch (epoch, server and claim id); activity idle (clean(c) again is a replay) | clean.go `Head.BeginClean` | `INV-SNAPK-CLEAN-EXCL-001` |
|
||||
| clean(c) | idle | holder at HEAD's epoch (epoch, server and claim id); activity clean(c); over idle it succeeds without a write | clean.go `Head.EndClean` | `INV-SNAPK-CLEAN-EXCL-001` |
|
||||
| clean(c) | clean(c), names removed | holder at HEAD's epoch (epoch, server and claim id) with clean(c) open (HEAD read once, after BeginClean); a name is deleted only if no root in HEAD (current or snapshot) names it in this volume's pool; each removal is a mark conditional on the plan's metadata, then a delete conditional on that mark | remove.go `RemoveUnreachable` | `INV-SNAPK-REMOVE-MARK-001` |
|
||||
| idle (live) | deleting | no holder (checked immediately before), no open activity, no snapshot with dependents; deleting again is a replay | delete.go `Head.MarkDeleting`, `DeleteVolume` (`HolderGone.NoHolder`) | `INV-SNAPK-DELETE-ORDER-001` |
|
||||
| deleting | deleted | after this volume is released from every source it names and its objects are deleted; deleted again is a replay; a live HEAD is refused | delete.go `Head.MarkDeleted`, `DeleteVolume` | `INV-SNAPK-DELETE-ORDER-001` |
|
||||
|
||||
## Part B. Invariant ledger
|
||||
|
||||
359 rows: 288 ACTIVE, 67 STUB, 4 ARCHIVED; 15 kept from the internal ledger, 344 new.
|
||||
360 rows: 289 ACTIVE, 67 STUB, 4 ARCHIVED; 15 kept from the internal ledger, 345 new.
|
||||
|
||||
The "Machine / transition" column refers to Part A. Notes under a table record what a row does not cover and, for kept rows, what was narrowed from the internal ledger.
|
||||
|
||||
@@ -1101,6 +1101,7 @@ Notes:
|
||||
| `INV-SNAPK-READ-MISSING-001` | A read resolves root, segment, chunk; an index the root does not name is zeros; a root, segment or chunk the root reaches but the store lacks is ErrMissing, never zeros; bytes that do not hash to their name are ErrCorrupt; a foreign chunk is read from its owner's pool. | Content-named layout (read path, no state transition) | `core/frontend/chunkstore/layout` `read.go` `Reader.Open`, `Image.Segment`, `Image.Chunk` | `TestRead_AbsentIndexIsZeros`, `TestRead_ForeignChunkFromSourcePool`, `TestRead_MissingObjectIsAnErrorNeverZeros`, `TestRead_FetchFailureAndCorruption`, `TestRead_SegmentOfAnotherShardRefused` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-REMOVE-MARK-001` | A pool name is removed only inside the holder's own cleaning, when no root in HEAD names it: tags read first, HEAD read and validated after, then a mark conditional on the tag and a delete conditional on the mark. | M9 clean → clean (RemoveUnreachable) | `core/frontend/chunkstore/layout` `remove.go` `RemoveUnreachable` | `TestRemoveUnreachable_RemovesOnlyWhatNoRootNames`, `TestCleaningPass_InterruptAtEveryStep`, `TestHolderFunctions_RefuseAStaleHolder` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-REMOVE-STOP-001` | A reuse of an object after the plan, or after the mark, makes the remover's mark or delete fail its condition, however late it lands; an unreadable root stops the pass before any write; an open snapshot refuses it. | M9 clean → clean (RemoveUnreachable) | `core/frontend/chunkstore/layout` `remove.go` `RemoveUnreachable` | `TestRemoveUnreachable_ASuccessorAfterTheHeadViewDefeatsTheMark`, `TestRemoveUnreachable_ASuccessorBeforeTheHeadViewStopsThePass`, `TestRemoveUnreachable_AReuseAfterThePlanDefeatsTheMark`, `TestRemoveUnreachable_AReuseDefeatsALateMarkOrDelete`, `TestRemoveUnreachable_NothingRemovedOnAPartialView`, `TestRemoveUnreachable_RefusedOutsideItsCleaning` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-REMOVE-CONVERGE-001` | A name a cleaning marked and did not delete (the remover died in between) is planned again by the next cleaning: the re-mark replaces the old mark, so the dead remover's late delete fails, and every unreachable name goes once a cleaning completes. | M9 clean → clean | `core/frontend/chunkstore/layout` `remove.go` `RemoveUnreachable` | `TestRemoveUnreachable_ReclaimsAnAbandonedMark`, `TestCleaningPass_InterruptAtEveryStep` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-REMOVE-GUARD-001` | A source scan requires DeleteMarked as RemoveUnreachable's only removal, each immediately after an if on its Mark's error that leaves: an unconditional delete, an ignored mark, a reused mark or another method fails. | M9 clean → clean (RemoveUnreachable) | `core/frontend/chunkstore/layout` (source scan of `remove.go`) | `TestGuard_WritersTransitionsAndRemovers`, `TestGuard_Controls` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-REUSE-001` | Writing an object for a session creates it, or reuses an existing one by a conditional update that sets the session and clears any mark; a commit names only objects its session wrote or reused, unmarked. | M9 snap → idle (Upload, Commit) | `core/frontend/chunkstore/layout` `objects.go` `EnsureObject`; `commit.go` `RunCommit` | `TestEnsureObject`, `TestRunCommit_NeedsObjectsOfItsOwnSession`, `TestSnapshotSession_InterruptAtEveryStep` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-IDENTITY-001` | A volume is identified by the random id in its VOLUME record, never by its name alone; HEAD carries the volume id and refuses to encode without it. | Content-named layout; M9 every transition | `core/frontend/chunkstore/layout` `volume.go` `Volume`, `VolumeID`; `head.go` `Head.check` | `TestVolumeID_RandomAndParsed`, `TestVolume_GoldenEncodingRoundTrip`, `TestHead_GoldenEncodingRoundTrip`, `TestHead_Refusals` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
|
||||
Reference in new issue
Block a user