mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
Merge remote-tracking branch 'origin/main' into feat/phase0-auth
# Conflicts: # docs/design/invariants.md
This commit is contained in:
commit
cecff27f4e
20 files changed
+1287
-104
No files matched your search
+9
-4
@@ -22,10 +22,9 @@ concurrency:
|
||||
jobs:
|
||||
trace:
|
||||
name: spec trace
|
||||
# Same-repository PRs use the project's self-hosted runners, as the test
|
||||
# workflow does; fork PRs stay on a GitHub-hosted runner, whose shared queue
|
||||
# can wait for hours. No PR code runs here either way.
|
||||
runs-on: ${{ github.event.pull_request.head.repo.full_name == github.repository && 'tp04-seaweed-block' || 'ubuntu-latest' }}
|
||||
# A GitHub-hosted runner: this check runs no PR code and needs no project
|
||||
# host, so it does not queue behind the self-hosted test jobs.
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
steps:
|
||||
- name: Checkout base
|
||||
@@ -37,6 +36,12 @@ jobs:
|
||||
fetch-depth: 0
|
||||
persist-credentials: false
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
cache: false
|
||||
|
||||
- name: Check spec trace
|
||||
env:
|
||||
BASE: ${{ github.event.pull_request.base.sha }}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
package chunkstore
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// deleteSites is every non-test function in core/ and cmd/ that deletes a
|
||||
// filer entry (DeleteEntry) or builds a volume directory name (VolumeDir),
|
||||
// with what it deletes or where the name comes from. Nothing removes a
|
||||
// deleted HEAD, a VOLUME or a volume directory, and a volume directory is
|
||||
// named only from a reference (a root's owner name and id) or from the
|
||||
// master's volume record, never from a name given plus an id read from
|
||||
// that same directory. A new site fails until it is classified here.
|
||||
var deleteSites = map[string]string{
|
||||
"core/frontend/chunkstore/catalog.go Catalog.dropIntent -> DeleteEntry": "an intent entry (old store)",
|
||||
"core/frontend/chunkstore/catalog.go Catalog.DeleteSnapshot -> DeleteEntry": "a snapshot name entry, conditional on its attempt (old store)",
|
||||
"core/frontend/chunkstore/chunk_remote.go ChunkRemote.DeleteIntent -> DeleteEntry": "an intent entry (old store)",
|
||||
"core/frontend/chunkstore/retention.go Catalog.freeName -> DeleteEntry": "a snapshot name entry, conditional on its attempt (old store)",
|
||||
"core/frontend/chunkstore/swfs.go SWFS.DeleteEntry -> DeleteEntry": "the filer client itself",
|
||||
"core/frontend/chunkstore/layout/read.go Image.Chunk -> VolumeDir": "a foreign chunk's directory from the reference's owner name and id",
|
||||
}
|
||||
|
||||
func TestDeleteAndDirectorySites_Enumeration(t *testing.T) {
|
||||
root := filepath.Join("..", "..", "..")
|
||||
found := map[string]bool{}
|
||||
for _, top := range []string{"core", "cmd"} {
|
||||
err := filepath.Walk(filepath.Join(root, top), func(p string, fi os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if fi.IsDir() || !strings.HasSuffix(p, ".go") || strings.HasSuffix(p, "_test.go") || strings.Contains(p, "filerpb") {
|
||||
return nil
|
||||
}
|
||||
file, err := parser.ParseFile(token.NewFileSet(), p, nil, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rel, _ := filepath.Rel(root, p)
|
||||
rel = filepath.ToSlash(rel)
|
||||
for _, d := range file.Decls {
|
||||
fn, ok := d.(*ast.FuncDecl)
|
||||
if !ok || fn.Body == nil {
|
||||
continue
|
||||
}
|
||||
name := fn.Name.Name
|
||||
if fn.Recv != nil && len(fn.Recv.List) == 1 {
|
||||
switch x := fn.Recv.List[0].Type.(type) {
|
||||
case *ast.Ident:
|
||||
name = x.Name + "." + name
|
||||
case *ast.StarExpr:
|
||||
name = x.X.(*ast.Ident).Name + "." + name
|
||||
}
|
||||
}
|
||||
ast.Inspect(fn.Body, func(n ast.Node) bool {
|
||||
c, ok := n.(*ast.CallExpr)
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
var callee string
|
||||
switch x := c.Fun.(type) {
|
||||
case *ast.SelectorExpr:
|
||||
callee = x.Sel.Name
|
||||
case *ast.Ident:
|
||||
callee = x.Name
|
||||
}
|
||||
if callee == "DeleteEntry" || callee == "VolumeDir" {
|
||||
key := rel + " " + strings.TrimPrefix(name, "*") + " -> " + callee
|
||||
found[key] = true
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
var added, gone []string
|
||||
for k := range found {
|
||||
if _, ok := deleteSites[k]; !ok {
|
||||
added = append(added, k)
|
||||
}
|
||||
}
|
||||
for k := range deleteSites {
|
||||
if !found[k] {
|
||||
gone = append(gone, k)
|
||||
}
|
||||
}
|
||||
sort.Strings(added)
|
||||
sort.Strings(gone)
|
||||
if len(added) != 0 || len(gone) != 0 {
|
||||
t.Fatalf("delete or directory-naming sites changed: classify each (it must not remove a HEAD, a VOLUME or a volume directory, and a directory name must come from a reference or the master's record).\nnew: %v\ngone: %v", added, gone)
|
||||
}
|
||||
}
|
||||
@@ -24,31 +24,32 @@ import (
|
||||
// one; a change that treats an absent HEAD as unknown flips those probes.
|
||||
var headReaders = map[string]string{
|
||||
// chunkstore: the two raw reads every other reader goes through
|
||||
"core/frontend/chunkstore/catalog.go ReadHead -> LookupEntry": "ok=false, no error (probe ReadHead)",
|
||||
"core/frontend/chunkstore/chunk_remote.go getHeadRoot -> LookupEntry": "zero HEAD, no error (probe GetHead)",
|
||||
"core/frontend/chunkstore/catalog.go headExists -> LookupEntry": "false (probe EnsureVolume)",
|
||||
"core/frontend/chunkstore/chunk_remote.go GetHead -> getHeadRoot": "zero HEAD, no error (probe GetHead)",
|
||||
"core/frontend/chunkstore/chunk_remote.go GetHeadRoot -> getHeadRoot": "zero HEAD, no error (probe GetHeadRoot)",
|
||||
"core/frontend/chunkstore/chunk_remote.go CASHead -> getHeadRoot": "GAP: expected gen 0 creates a HEAD over existing keys (probe CASHead)",
|
||||
"core/frontend/chunkstore/catalog.go ensureInitialHead -> headExists": "GAP: creates an empty gen-1 HEAD over existing keys (probe EnsureVolume)",
|
||||
"core/frontend/chunkstore/catalog.go EnsureVolume -> ReadHead": "GAP: attaches the recreated empty HEAD (probe EnsureVolume)",
|
||||
"core/frontend/chunkstore/catalog.go fork -> ReadHead": "replay falls through and publishes the fork-time HEAD (probe ForkReplay)",
|
||||
"core/frontend/chunkstore/catalog.go AbortFork -> ReadHead": "GAP: exclusive-creates an aborted HEAD (probe AbortFork)",
|
||||
"core/frontend/chunkstore/gc.go run -> GetHead": "GAP: zero HEAD roots nothing; the volume's keys become candidates (probe GCMark)",
|
||||
"core/frontend/chunkstore/gc_copy.go SweepCopies -> ReadHead": "after AbortFork: settles from the HEAD it created (probe AbortFork)",
|
||||
"core/frontend/chunkstore/restore.go MarkIndependent -> ReadHead": "refuses (not a restore / no HEAD) (probe MarkIndependent)",
|
||||
"core/frontend/chunkstore/share_guard.go beginShare -> ReadHead": "refuses outcome_unknown: the HEAD to share is no longer current",
|
||||
"core/frontend/chunkstore/usage.go Usage -> ReadHead": "GAP: reports an empty image, no error (probe Usage)",
|
||||
"core/frontend/chunkstore/verify.go readHead -> LookupEntry": "finding ROOT_INVALID (probe Verify)",
|
||||
"core/frontend/chunkstore/layout/remove.go RemoveUnreachable -> ReadHead": "refuses ErrHeadAbsent and writes nothing to the objects (probe LayoutRemoval)",
|
||||
"core/frontend/chunkstore/layout/head.go runTransition -> ReadHead": "refuses ErrHeadAbsent and writes nothing; no layout transition creates a HEAD (probe LayoutTransition)",
|
||||
"core/frontend/chunkstore/verify.go run -> LookupEntry": "finding ROOT_INVALID (probe Verify)",
|
||||
"core/frontend/chunkstore/volume_delete.go DeleteVolume -> ReadHead": "operator delete writes a deleting HEAD from nothing and completes (probe DeleteVolume)",
|
||||
"core/frontend/chunkstore/volume_delete.go markHeadDeleting -> ReadHead": "zero HEAD: creates the deleting HEAD (probe DeleteVolume)",
|
||||
"core/frontend/chunkstore/volume_delete.go commitHeadPurging -> ReadHead": "reads the HEAD markHeadDeleting wrote (probe DeleteVolume)",
|
||||
"core/frontend/chunkstore/volume_delete.go finishHeadDeleted -> ReadHead": "reads the HEAD markHeadDeleting wrote (probe DeleteVolume)",
|
||||
"core/frontend/chunkstore/volume_delete.go revertHeadDeleting -> ReadHead": "reads the HEAD markHeadDeleting wrote (probe DeleteVolume)",
|
||||
"core/frontend/chunkstore/volume_delete.go volumeGone -> ReadHead": "absent HEAD = not gone (probe DeleteVolume)",
|
||||
"core/frontend/chunkstore/catalog.go ReadHead -> LookupEntry": "ok=false, no error (probe ReadHead)",
|
||||
"core/frontend/chunkstore/chunk_remote.go getHeadRoot -> LookupEntry": "zero HEAD, no error (probe GetHead)",
|
||||
"core/frontend/chunkstore/catalog.go headExists -> LookupEntry": "false (probe EnsureVolume)",
|
||||
"core/frontend/chunkstore/chunk_remote.go GetHead -> getHeadRoot": "zero HEAD, no error (probe GetHead)",
|
||||
"core/frontend/chunkstore/chunk_remote.go GetHeadRoot -> getHeadRoot": "zero HEAD, no error (probe GetHeadRoot)",
|
||||
"core/frontend/chunkstore/chunk_remote.go CASHead -> getHeadRoot": "GAP: expected gen 0 creates a HEAD over existing keys (probe CASHead)",
|
||||
"core/frontend/chunkstore/catalog.go ensureInitialHead -> headExists": "GAP: creates an empty gen-1 HEAD over existing keys (probe EnsureVolume)",
|
||||
"core/frontend/chunkstore/catalog.go EnsureVolume -> ReadHead": "GAP: attaches the recreated empty HEAD (probe EnsureVolume)",
|
||||
"core/frontend/chunkstore/catalog.go fork -> ReadHead": "replay falls through and publishes the fork-time HEAD (probe ForkReplay)",
|
||||
"core/frontend/chunkstore/catalog.go AbortFork -> ReadHead": "GAP: exclusive-creates an aborted HEAD (probe AbortFork)",
|
||||
"core/frontend/chunkstore/gc.go run -> GetHead": "GAP: zero HEAD roots nothing; the volume's keys become candidates (probe GCMark)",
|
||||
"core/frontend/chunkstore/gc_copy.go SweepCopies -> ReadHead": "after AbortFork: settles from the HEAD it created (probe AbortFork)",
|
||||
"core/frontend/chunkstore/restore.go MarkIndependent -> ReadHead": "refuses (not a restore / no HEAD) (probe MarkIndependent)",
|
||||
"core/frontend/chunkstore/share_guard.go beginShare -> ReadHead": "refuses outcome_unknown: the HEAD to share is no longer current",
|
||||
"core/frontend/chunkstore/usage.go Usage -> ReadHead": "GAP: reports an empty image, no error (probe Usage)",
|
||||
"core/frontend/chunkstore/verify.go readHead -> LookupEntry": "finding ROOT_INVALID (probe Verify)",
|
||||
"core/frontend/chunkstore/layout/delete.go OperatorReleaseDependent -> ReadHead": "reads the source's HEAD (absent: refuses ErrHeadAbsent) and the target's: a target without HEAD (never created, or a restore that died between its VOLUME and its HEAD) gets a deleted HEAD written exclusively before the release (probe LayoutOperatorRelease)",
|
||||
"core/frontend/chunkstore/layout/remove.go RemoveUnreachable -> ReadHead": "refuses ErrHeadAbsent and writes nothing to the objects (probe LayoutRemoval)",
|
||||
"core/frontend/chunkstore/layout/head.go runTransition -> ReadHead": "refuses ErrHeadAbsent and writes nothing; no layout transition creates a HEAD (probe LayoutTransition)",
|
||||
"core/frontend/chunkstore/verify.go run -> LookupEntry": "finding ROOT_INVALID (probe Verify)",
|
||||
"core/frontend/chunkstore/volume_delete.go DeleteVolume -> ReadHead": "operator delete writes a deleting HEAD from nothing and completes (probe DeleteVolume)",
|
||||
"core/frontend/chunkstore/volume_delete.go markHeadDeleting -> ReadHead": "zero HEAD: creates the deleting HEAD (probe DeleteVolume)",
|
||||
"core/frontend/chunkstore/volume_delete.go commitHeadPurging -> ReadHead": "reads the HEAD markHeadDeleting wrote (probe DeleteVolume)",
|
||||
"core/frontend/chunkstore/volume_delete.go finishHeadDeleted -> ReadHead": "reads the HEAD markHeadDeleting wrote (probe DeleteVolume)",
|
||||
"core/frontend/chunkstore/volume_delete.go revertHeadDeleting -> ReadHead": "reads the HEAD markHeadDeleting wrote (probe DeleteVolume)",
|
||||
"core/frontend/chunkstore/volume_delete.go volumeGone -> ReadHead": "absent HEAD = not gone (probe DeleteVolume)",
|
||||
// above the chunk store: they read through storage.ChunkRemote GetHead /
|
||||
// GetHeadRoot, so an absent HEAD reaches them as the zero HEAD (probe GetHead)
|
||||
"cmd/sw-block/chunk.go chunkShow -> ReadHead": "ok=false: reports no HEAD (probe ReadHead)",
|
||||
@@ -278,6 +279,35 @@ func TestHeadReaders_AbsentHeadProbes(t *testing.T) {
|
||||
t.Fatalf("layout removal over an absent HEAD wrote %d times to the objects", pool.writes)
|
||||
}
|
||||
})
|
||||
t.Run("LayoutOperatorRelease", func(t *testing.T) {
|
||||
tid, err := layout.NewVolumeID()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
vb, err := layout.Volume{ID: tid, Name: "t", Format: layout.VolumeFormat}.Encode()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
withVolume := func(context.Context, string) ([]byte, bool, error) { return vb, true, nil }
|
||||
r, err := layout.NewReader("/swblock/chunks", "t", withVolume)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
src := &presentLayoutHead{}
|
||||
withVol := &absentLayoutHead{}
|
||||
if _, err := layout.OperatorReleaseDependent(ctx, src, withVol, r, tid); err != nil || withVol.created == nil || withVol.created.State != layout.StateDeleted {
|
||||
t.Fatalf("operator release of a target with VOLUME and no HEAD: %v, tombstone %+v; want a deleted HEAD written, then the release", err, withVol.created)
|
||||
}
|
||||
none, _ := layout.NewReader("/swblock/chunks", "t", func(context.Context, string) ([]byte, bool, error) { return nil, false, nil })
|
||||
tomb := &absentLayoutHead{}
|
||||
if _, err := layout.OperatorReleaseDependent(ctx, src, tomb, none, tid); err != nil || tomb.created == nil || tomb.created.State != layout.StateDeleted || tomb.created.VolumeID != tid {
|
||||
t.Fatalf("operator release of a target never created: %v, tombstone %+v; want a deleted HEAD of the target's id written before the release", err, tomb.created)
|
||||
}
|
||||
absent := &absentLayoutHead{}
|
||||
if _, err := layout.OperatorReleaseDependent(ctx, absent, &absentLayoutHead{}, r, tid); !errors.Is(err, layout.ErrHeadAbsent) || absent.updates != 0 {
|
||||
t.Fatalf("operator release with the source HEAD absent: %v; want ErrHeadAbsent", err)
|
||||
}
|
||||
})
|
||||
t.Run("ForkReplay", func(t *testing.T) {
|
||||
f, b := headReaderForkFixture(t)
|
||||
c, err := NewCatalog(manifestFilerBlobs{f, gcBlobs{b}}, catBase)
|
||||
@@ -300,8 +330,17 @@ func TestHeadReaders_AbsentHeadProbes(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// absentLayoutHead is a layout HEAD store whose HEAD is absent.
|
||||
type absentLayoutHead struct{ updates int }
|
||||
// absentLayoutHead is a layout HEAD store whose HEAD is absent; it records
|
||||
// a tombstone created in it.
|
||||
type absentLayoutHead struct {
|
||||
updates int
|
||||
created *layout.Head
|
||||
}
|
||||
|
||||
func (a *absentLayoutHead) CreateDeletedHead(_ context.Context, h layout.Head) error {
|
||||
a.created = &h
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *absentLayoutHead) ReadHead(context.Context) (layout.Head, bool, error) {
|
||||
return layout.Head{}, false, nil
|
||||
@@ -329,3 +368,21 @@ func (p *countingPool) Mark(context.Context, string, layout.ObjectMeta, string)
|
||||
return nil
|
||||
}
|
||||
func (p *countingPool) DeleteMarked(context.Context, string, string) error { p.writes++; return nil }
|
||||
func (p *countingPool) DeleteOfVolume(context.Context, string, layout.VolumeID) error {
|
||||
p.writes++
|
||||
return nil
|
||||
}
|
||||
|
||||
// presentLayoutHead is a layout HEAD store whose HEAD is present (a live,
|
||||
// idle volume); it counts updates.
|
||||
type presentLayoutHead struct{ updates int }
|
||||
|
||||
func (p *presentLayoutHead) ReadHead(context.Context) (layout.Head, bool, error) {
|
||||
id, _ := layout.NewVolumeID()
|
||||
return layout.Head{Gen: 1, VolumeID: id, Epoch: 1, Holder: "h", ClaimID: "k", Activity: layout.Activity{Kind: layout.ActIdle}}, true, nil
|
||||
}
|
||||
|
||||
func (p *presentLayoutHead) UpdateHead(context.Context, uint64, layout.Head) error {
|
||||
p.updates++
|
||||
return nil
|
||||
}
|
||||
@@ -28,6 +28,9 @@ func (h Head) Claim(me HolderID) (next Head, changed bool, err error) {
|
||||
if me.Epoch == 0 || me.Holder == "" || me.ClaimID == "" {
|
||||
return Head{}, false, errors.New("layout: Claim needs an epoch, a holder and a claim id")
|
||||
}
|
||||
if h.State != StateLive {
|
||||
return Head{}, false, fmt.Errorf("%w: HEAD is %s", ErrVolumeDeleting, h.State)
|
||||
}
|
||||
switch {
|
||||
case me.Epoch < h.Epoch:
|
||||
return Head{}, false, fmt.Errorf("%w: HEAD epoch %d, caller %d", ErrStaleEpoch, h.Epoch, me.Epoch)
|
||||
|
||||
@@ -14,8 +14,8 @@ func (h Head) BeginClean(me HolderID, session string) (next Head, changed bool,
|
||||
if session == "" {
|
||||
return Head{}, false, errors.New("layout: BeginClean needs a session id")
|
||||
}
|
||||
if !h.heldBy(me) {
|
||||
return Head{}, false, fmt.Errorf("%w: HEAD epoch %d holder %q, caller epoch %d holder %q", ErrNotHolder, h.Epoch, h.Holder, me.Epoch, me.Holder)
|
||||
if err := h.holderErr(me); err != nil {
|
||||
return Head{}, false, err
|
||||
}
|
||||
switch {
|
||||
case h.Activity == Activity{Kind: ActClean, Session: session}:
|
||||
@@ -36,8 +36,8 @@ func (h Head) EndClean(me HolderID, session string) (next Head, changed bool, er
|
||||
if session == "" {
|
||||
return Head{}, false, errors.New("layout: EndClean needs a session id")
|
||||
}
|
||||
if !h.heldBy(me) {
|
||||
return Head{}, false, fmt.Errorf("%w: HEAD epoch %d holder %q, caller epoch %d holder %q", ErrNotHolder, h.Epoch, h.Holder, me.Epoch, me.Holder)
|
||||
if err := h.holderErr(me); err != nil {
|
||||
return Head{}, false, err
|
||||
}
|
||||
switch {
|
||||
case h.Activity.Kind == ActIdle:
|
||||
|
||||
@@ -66,8 +66,8 @@ func (h Head) Commit(me HolderID, session string, root RootName, position uint64
|
||||
if session == "" {
|
||||
return Head{}, false, errors.New("layout: Commit needs a session id")
|
||||
}
|
||||
if !h.heldBy(me) {
|
||||
return Head{}, false, fmt.Errorf("%w: HEAD epoch %d holder %q, caller epoch %d holder %q", ErrNotHolder, h.Epoch, h.Holder, me.Epoch, me.Holder)
|
||||
if err := h.holderErr(me); err != nil {
|
||||
return Head{}, false, err
|
||||
}
|
||||
if h.Activity.Kind == ActIdle && h.Current != nil && *h.Current == root && h.Position == position {
|
||||
if s, ok := h.Snapshots[snapshot]; snapshot == "" || ok && s.Root == root {
|
||||
|
||||
@@ -0,0 +1,291 @@
|
||||
package layout
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// HEAD states: a live volume, one being deleted, one deleted.
|
||||
const (
|
||||
StateLive = ""
|
||||
StateDeleting = "deleting"
|
||||
StateDeleted = "deleted"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrVolumeDeleting: the volume is being deleted or is deleted; no
|
||||
// holder transition and no claim applies.
|
||||
ErrVolumeDeleting = errors.New("layout: volume is being deleted")
|
||||
// ErrHasDependents: a snapshot still has restore targets naming its
|
||||
// chunks; the volume cannot be deleted.
|
||||
ErrHasDependents = errors.New("layout: a snapshot has dependents")
|
||||
// ErrHolderActive: a transaction is open on the volume.
|
||||
ErrHolderActive = errors.New("layout: a holder is acting on the volume")
|
||||
// ErrTargetLive: the operator asked to release a dependent whose
|
||||
// target still exists and may still name the source's chunks.
|
||||
ErrTargetLive = errors.New("layout: the dependent's target is live")
|
||||
)
|
||||
|
||||
// TargetStore is a restore target's HEAD entry as the operator's
|
||||
// remove-dependent sees it: read, and one exclusive create of a deleted
|
||||
// HEAD (a tombstone) in the target's never-reused directory; ErrExists if
|
||||
// a HEAD is already there.
|
||||
type TargetStore interface {
|
||||
ReadHead(ctx context.Context) (h Head, found bool, err error)
|
||||
CreateDeletedHead(ctx context.Context, h Head) error
|
||||
}
|
||||
|
||||
// DeleteAuthority is the master's side of a volume delete. Reserve durably
|
||||
// records the volume's delete reservation, after which the master grants
|
||||
// no line for it, ever (re-running it is a replay). NoLiveLease returns nil
|
||||
// only when no line of the volume holds a live lease, granted but
|
||||
// unclaimed lines included. After Reserve, "no live lease" can never
|
||||
// become false again, so DeleteVolume checks it between its HEAD read and
|
||||
// the conditional update that marks HEAD deleting: a claim landing in
|
||||
// between changes HEAD and the update fails.
|
||||
type DeleteAuthority interface {
|
||||
Reserve(ctx context.Context) error
|
||||
NoLiveLease(ctx context.Context) error
|
||||
}
|
||||
|
||||
// MarkDeleting is the first step of a volume delete: live -> deleting,
|
||||
// refused while a transaction is open or any snapshot has dependents.
|
||||
// Deleting or deleted again is a replay.
|
||||
func (h Head) MarkDeleting() (next Head, changed bool, err error) {
|
||||
switch h.State {
|
||||
case StateDeleting, StateDeleted:
|
||||
return h, false, nil
|
||||
}
|
||||
if h.Activity.Kind != ActIdle {
|
||||
return Head{}, false, fmt.Errorf("%w: %s(%s)", ErrHolderActive, h.Activity.Kind, h.Activity.Session)
|
||||
}
|
||||
for n, s := range h.Snapshots {
|
||||
if len(s.Dependents) > 0 {
|
||||
return Head{}, false, fmt.Errorf("%w: snapshot %q has %d", ErrHasDependents, n, len(s.Dependents))
|
||||
}
|
||||
}
|
||||
next = h.clone()
|
||||
next.State = StateDeleting
|
||||
return next, true, nil
|
||||
}
|
||||
|
||||
// MarkDeleted is the last step: deleting -> deleted. Deleted again is a
|
||||
// replay; a live HEAD is refused (the delete never began).
|
||||
func (h Head) MarkDeleted() (next Head, changed bool, err error) {
|
||||
switch h.State {
|
||||
case StateDeleted:
|
||||
return h, false, nil
|
||||
case StateLive:
|
||||
return Head{}, false, fmt.Errorf("layout: HEAD is live; a delete marks it deleting first")
|
||||
}
|
||||
next = h.clone()
|
||||
next.State = StateDeleted
|
||||
return next, true, nil
|
||||
}
|
||||
|
||||
// ReleaseDependent removes the target volume id from the dependents of
|
||||
// every snapshot of this (source) HEAD: the step a target being deleted
|
||||
// makes on each source. It does not look at the target; the operator's
|
||||
// command goes through OperatorReleaseDependent, which does. A HEAD with
|
||||
// no such dependent is a replay.
|
||||
func (h Head) ReleaseDependent(target VolumeID) (next Head, changed bool, err error) {
|
||||
if target.IsZero() {
|
||||
return Head{}, false, errors.New("layout: ReleaseDependent needs a target volume id")
|
||||
}
|
||||
next = h.clone()
|
||||
for n, s := range next.Snapshots {
|
||||
kept := s.Dependents[:0]
|
||||
for _, d := range s.Dependents {
|
||||
if !bytes.Equal(d.TargetID[:], target[:]) {
|
||||
kept = append(kept, d)
|
||||
}
|
||||
}
|
||||
if len(kept) != len(s.Dependents) {
|
||||
s.Dependents = kept
|
||||
next.Snapshots[n] = s
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
if !changed {
|
||||
return h, false, nil
|
||||
}
|
||||
return next, true, nil
|
||||
}
|
||||
|
||||
// RunMarkDeleting applies MarkDeleting by one conditional update.
|
||||
//
|
||||
// The authority's no-live-lease check runs after the read and before the
|
||||
// update, as the claim's lease wait does.
|
||||
func RunMarkDeleting(ctx context.Context, st HeadStore, auth DeleteAuthority) (Head, error) {
|
||||
if auth == nil {
|
||||
return Head{}, errors.New("layout: MarkDeleting needs the master's delete authority")
|
||||
}
|
||||
return runTransition(ctx, st, func(h Head) (Head, bool, error) {
|
||||
next, changed, err := h.MarkDeleting()
|
||||
if err != nil || !changed {
|
||||
return next, changed, err
|
||||
}
|
||||
if err := auth.NoLiveLease(ctx); err != nil {
|
||||
return Head{}, false, fmt.Errorf("%w: %v", ErrHolderActive, err)
|
||||
}
|
||||
return next, true, nil
|
||||
})
|
||||
}
|
||||
|
||||
// RunMarkDeleted applies MarkDeleted by one conditional update.
|
||||
func RunMarkDeleted(ctx context.Context, st HeadStore) (Head, error) {
|
||||
return runTransition(ctx, st, func(h Head) (Head, bool, error) { return h.MarkDeleted() })
|
||||
}
|
||||
|
||||
// RunReleaseDependent applies ReleaseDependent to a source's HEAD by one
|
||||
// conditional update. Its callers know the target is gone: DeleteVolume
|
||||
// (the target's HEAD is deleting) and OperatorReleaseDependent (checked).
|
||||
func RunReleaseDependent(ctx context.Context, source HeadStore, target VolumeID) (Head, error) {
|
||||
return runTransition(ctx, source, func(h Head) (Head, bool, error) { return h.ReleaseDependent(target) })
|
||||
}
|
||||
|
||||
// DeleteVolume runs a volume delete in its order, every prefix safe and
|
||||
// the whole re-runnable: the master's delete reservation (no line is
|
||||
// granted for the volume from then on), then HEAD deleting (refused while
|
||||
// any line holds a live lease, checked between the HEAD read and its
|
||||
// conditional update, or while a snapshot has dependents; no holder
|
||||
// transition, claim or removal applies from here), then this volume released from every source it depends on,
|
||||
// then every object of its pool, segments and roots deleted, each
|
||||
// conditional on belonging to this volume (a late delete of this run never
|
||||
// removes the object of a volume created again under the name), then HEAD
|
||||
// deleted. A source left out keeps an extra dependent, which over-protects
|
||||
// and is released by the operator's command.
|
||||
func DeleteVolume(ctx context.Context, st HeadStore, auth DeleteAuthority, id VolumeID, sources []HeadStore, os ObjectStore, objects []string) error {
|
||||
if auth == nil || os == nil {
|
||||
return errors.New("layout: delete needs the master's delete authority and an object store")
|
||||
}
|
||||
for _, rel := range objects {
|
||||
if !isObjectPath(rel) {
|
||||
return fmt.Errorf("%w: %q is not a pool, segment or root object; HEAD, VOLUME and the directory stay", ErrMalformed, rel)
|
||||
}
|
||||
}
|
||||
if err := auth.Reserve(ctx); err != nil {
|
||||
return fmt.Errorf("layout: delete reservation: %w", err)
|
||||
}
|
||||
if _, err := RunMarkDeleting(ctx, st, auth); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, src := range sources {
|
||||
if _, err := RunReleaseDependent(ctx, src, id); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, rel := range objects {
|
||||
if err := os.DeleteOfVolume(ctx, rel, id); err != nil {
|
||||
if errors.Is(err, ErrPrecondition) {
|
||||
continue // the name holds another volume's object now
|
||||
}
|
||||
return fmt.Errorf("layout: delete %s: %w", rel, err)
|
||||
}
|
||||
}
|
||||
_, err := RunMarkDeleted(ctx, st)
|
||||
return err
|
||||
}
|
||||
|
||||
// OperatorReleaseDependent is the operator's remove-dependent command: it
|
||||
// releases the target from the source's dependents only when the target
|
||||
// exists and is deleted or no longer names the source, read first: its
|
||||
// HEAD is deleting or deleted; its directory's VOLUME carries another id;
|
||||
// or its HEAD is live and no root in it (current or snapshot) names a
|
||||
// chunk of the source. A target without HEAD (never created, or a restore
|
||||
// that died between its VOLUME and its HEAD) first gets a deleted HEAD
|
||||
// written exclusively in its never-reused directory, so the restore that
|
||||
// registered it can never create it later, and is then released. A live
|
||||
// target that still names the source, and one whose HEAD appeared before
|
||||
// the tombstone, are refused (ErrTargetLive); the source is not written
|
||||
// then.
|
||||
func OperatorReleaseDependent(ctx context.Context, source HeadStore, target TargetStore, r *Reader, targetID VolumeID) (Head, error) {
|
||||
sh, found, err := source.ReadHead(ctx)
|
||||
if err != nil {
|
||||
return Head{}, err
|
||||
}
|
||||
if !found {
|
||||
return Head{}, ErrHeadAbsent
|
||||
}
|
||||
id, err := r.VolumeID(ctx, r.vol)
|
||||
hasVolume := err == nil
|
||||
if err != nil && !errors.Is(err, ErrMissing) {
|
||||
return Head{}, err
|
||||
}
|
||||
th, hasHead, err := target.ReadHead(ctx)
|
||||
if err != nil {
|
||||
return Head{}, err
|
||||
}
|
||||
switch {
|
||||
case hasHead && (th.State == StateDeleting || th.State == StateDeleted):
|
||||
case hasVolume && id != targetID:
|
||||
case !hasHead:
|
||||
// No HEAD (never created, or a restore that died between its VOLUME
|
||||
// and its HEAD): a deleted HEAD written exclusively in the target's
|
||||
// never-reused directory makes sure the restore can never create it
|
||||
// later; only then is the dependent released. If a HEAD appeared
|
||||
// first, the restore got there: refused, a re-run decides.
|
||||
tomb := Head{VolumeID: targetID, Activity: Activity{Kind: ActIdle}, State: StateDeleted}
|
||||
if err := target.CreateDeletedHead(ctx, tomb); err != nil {
|
||||
if errors.Is(err, ErrExists) {
|
||||
return Head{}, fmt.Errorf("%w: %s appeared while being tombstoned; run again", ErrTargetLive, r.vol)
|
||||
}
|
||||
return Head{}, err
|
||||
}
|
||||
default:
|
||||
names, err := namesVolume(ctx, r, th, sh.VolumeID)
|
||||
if err != nil {
|
||||
return Head{}, err
|
||||
}
|
||||
if names {
|
||||
return Head{}, fmt.Errorf("%w: %s still names chunks of the source", ErrTargetLive, r.vol)
|
||||
}
|
||||
}
|
||||
return RunReleaseDependent(ctx, source, targetID)
|
||||
}
|
||||
|
||||
// namesVolume reports whether any root in h names a chunk owned by owner.
|
||||
// Every shard of every root is read; an unreadable one is an error, never
|
||||
// "names nothing".
|
||||
func namesVolume(ctx context.Context, r *Reader, h Head, owner VolumeID) (bool, error) {
|
||||
roots := map[RootName]bool{}
|
||||
if h.Current != nil {
|
||||
roots[*h.Current] = true
|
||||
}
|
||||
for _, s := range h.Snapshots {
|
||||
roots[s.Root] = true
|
||||
}
|
||||
for rn := range roots {
|
||||
img, err := r.Open(ctx, rn)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
for shard := range img.root.Segments {
|
||||
seg, _, err := img.Segment(ctx, shard)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
for _, ref := range seg.Chunks {
|
||||
if ref.OwnerID == owner {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// isObjectPath reports whether rel names a content-named object of the
|
||||
// volume (a chunk, a segment or a root): the only entries a volume delete
|
||||
// removes. HEAD (which stays, deleted), VOLUME and the directory are not.
|
||||
func isObjectPath(rel string) bool {
|
||||
for _, dir := range []string{PoolDir + "/", SegDir + "/", RootDir + "/"} {
|
||||
if strings.HasPrefix(rel, dir) && len(rel) > len(dir) && !strings.Contains(rel, "..") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,477 @@
|
||||
package layout
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func deletingHead() Head {
|
||||
h := idleHead()
|
||||
h.State = StateDeleting
|
||||
return h
|
||||
}
|
||||
|
||||
func TestMarkDeleting_Closure(t *testing.T) {
|
||||
next, changed, err := idleHead().MarkDeleting()
|
||||
if err != nil || !changed || next.State != StateDeleting {
|
||||
t.Fatalf("MarkDeleting from live: %+v %t %v", next, changed, err)
|
||||
}
|
||||
for _, h := range []Head{deletingHead(), func() Head { h := idleHead(); h.State = StateDeleted; return h }()} {
|
||||
if again, changed, err := h.MarkDeleting(); err != nil || changed || again.State != h.State {
|
||||
t.Fatalf("MarkDeleting over %s: %+v %t %v; want a replay", h.State, again, changed, err)
|
||||
}
|
||||
}
|
||||
if _, _, err := snapHead("s1").MarkDeleting(); !errors.Is(err, ErrHolderActive) {
|
||||
t.Fatalf("MarkDeleting with a snapshot open: %v; want ErrHolderActive", err)
|
||||
}
|
||||
withDeps := idleHead()
|
||||
rn := RootName{Hash: Sum([]byte("r"))}
|
||||
withDeps.Snapshots = map[string]Snapshot{"daily": {Root: rn, Dependents: deps(rn, "t1")}}
|
||||
if _, _, err := withDeps.MarkDeleting(); !errors.Is(err, ErrHasDependents) {
|
||||
t.Fatalf("MarkDeleting with a dependent: %v; want ErrHasDependents", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMarkDeleted_Closure(t *testing.T) {
|
||||
next, changed, err := deletingHead().MarkDeleted()
|
||||
if err != nil || !changed || next.State != StateDeleted {
|
||||
t.Fatalf("MarkDeleted from deleting: %+v %t %v", next, changed, err)
|
||||
}
|
||||
if _, changed, err := next.MarkDeleted(); err != nil || changed {
|
||||
t.Fatalf("MarkDeleted over deleted: %t %v; want a replay", changed, err)
|
||||
}
|
||||
if _, _, err := idleHead().MarkDeleted(); err == nil {
|
||||
t.Fatal("MarkDeleted over a live HEAD succeeded")
|
||||
}
|
||||
}
|
||||
|
||||
func TestReleaseDependent_Closure(t *testing.T) {
|
||||
rn := RootName{Hash: Sum([]byte("r"))}
|
||||
old := RootName{Hash: Sum([]byte("old"))}
|
||||
h := idleHead()
|
||||
h.Snapshots = map[string]Snapshot{"daily": {Root: rn, Dependents: deps(rn, "t1", "t2")}, "weekly": {Root: old, Dependents: deps(old, "t1")}}
|
||||
next, changed, err := h.ReleaseDependent(idFor("t1"))
|
||||
if err != nil || !changed {
|
||||
t.Fatalf("ReleaseDependent: %+v %t %v", next, changed, err)
|
||||
}
|
||||
if d := next.Snapshots["daily"].Dependents; len(d) != 1 || d[0].Target != "t2" || len(next.Snapshots["weekly"].Dependents) != 0 {
|
||||
t.Fatalf("dependents after releasing t1: %+v", next.Snapshots)
|
||||
}
|
||||
if len(h.Snapshots["daily"].Dependents) != 2 {
|
||||
t.Fatal("ReleaseDependent changed its receiver")
|
||||
}
|
||||
if _, changed, err := next.ReleaseDependent(idFor("t1")); err != nil || changed {
|
||||
t.Fatalf("ReleaseDependent of an absent target: %t %v; want a replay", changed, err)
|
||||
}
|
||||
// A volume created again under t2's name has another id and releases nothing.
|
||||
if _, changed, err := next.ReleaseDependent(idFor("t2 again")); err != nil || changed {
|
||||
t.Fatalf("ReleaseDependent of another volume under the same name: %t %v; want nothing released", changed, err)
|
||||
}
|
||||
if _, _, err := h.ReleaseDependent(VolumeID{}); err == nil {
|
||||
t.Fatal("ReleaseDependent of the zero id accepted")
|
||||
}
|
||||
}
|
||||
|
||||
// Once deleting, no holder transition, no claim and no removal applies.
|
||||
func TestDeleting_RefusesEveryHolderStep(t *testing.T) {
|
||||
h := deletingHead()
|
||||
rn := RootName{Hash: Sum([]byte("r"))}
|
||||
for name, step := range map[string]func() error{
|
||||
"Begin": func() error { _, _, err := h.Begin(me, "s"); return err },
|
||||
"Abort": func() error { _, _, err := h.Abort(me, "s"); return err },
|
||||
"Commit": func() error { _, _, err := h.Commit(me, "s", rn, 1, ""); return err },
|
||||
"BeginClean": func() error { _, _, err := h.BeginClean(me, "c"); return err },
|
||||
"EndClean": func() error { _, _, err := h.EndClean(me, "c"); return err },
|
||||
"Claim": func() error { _, _, err := h.Claim(newer); return err },
|
||||
} {
|
||||
if err := step(); !errors.Is(err, ErrVolumeDeleting) {
|
||||
t.Errorf("%s over a deleting HEAD: %v; want ErrVolumeDeleting", name, err)
|
||||
}
|
||||
}
|
||||
o, rh, _, orphans := removeFixture(t)
|
||||
rh.State = StateDeleting
|
||||
if _, err := removeShard0(t, &memHead{h: rh}, o, "c1", orphans); !errors.Is(err, ErrVolumeDeleting) || len(o.writes) != 0 {
|
||||
t.Fatalf("removal over a deleting HEAD: %v, %d writes", err, len(o.writes))
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunMarkDeleting_InterruptAtEveryStep(t *testing.T) {
|
||||
interruptHead(t, idleHead(), func(st HeadStore) error {
|
||||
_, err := RunMarkDeleting(context.Background(), st, &fakeMaster{})
|
||||
return err
|
||||
},
|
||||
func(t *testing.T, h Head) {
|
||||
if h.State != StateDeleting {
|
||||
t.Fatalf("state %q", h.State)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestRunMarkDeleted_InterruptAtEveryStep(t *testing.T) {
|
||||
interruptHead(t, deletingHead(), func(st HeadStore) error { _, err := RunMarkDeleted(context.Background(), st); return err },
|
||||
func(t *testing.T, h Head) {
|
||||
if h.State != StateDeleted {
|
||||
t.Fatalf("state %q", h.State)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestRunReleaseDependent_InterruptAtEveryStep(t *testing.T) {
|
||||
rn := RootName{Hash: Sum([]byte("r"))}
|
||||
h := idleHead()
|
||||
h.Snapshots = map[string]Snapshot{"daily": {Root: rn, Dependents: deps(rn, "t1", "t2")}}
|
||||
interruptHead(t, h, func(st HeadStore) error {
|
||||
_, err := RunReleaseDependent(context.Background(), st, idFor("t1"))
|
||||
return err
|
||||
},
|
||||
func(t *testing.T, h Head) {
|
||||
if d := h.Snapshots["daily"].Dependents; len(d) != 1 || d[0].Target != "t2" {
|
||||
t.Fatalf("dependents %+v", d)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// fakeMaster is the master's delete authority: a reservation after which
|
||||
// it grants no line, and the lines holding a live lease.
|
||||
type fakeMaster struct {
|
||||
reserved bool
|
||||
leases int
|
||||
err error // NoLiveLease's answer while leases is 0, when set
|
||||
onReserve func() // runs after Reserve recorded the reservation
|
||||
}
|
||||
|
||||
func (m *fakeMaster) Reserve(context.Context) error {
|
||||
m.reserved = true
|
||||
if f := m.onReserve; f != nil {
|
||||
m.onReserve = nil
|
||||
f()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *fakeMaster) NoLiveLease(context.Context) error {
|
||||
if m.leases > 0 {
|
||||
return fmt.Errorf("%d lines hold a live lease", m.leases)
|
||||
}
|
||||
return m.err
|
||||
}
|
||||
|
||||
// grant grants a line (a live lease), refused after the reservation.
|
||||
func (m *fakeMaster) grant() error {
|
||||
if m.reserved {
|
||||
return errors.New("volume reserved for delete")
|
||||
}
|
||||
m.leases++
|
||||
return nil
|
||||
}
|
||||
|
||||
// deleteWorld: volume t (a restore target of src's snapshot "daily") with
|
||||
// two objects in its pool; src's HEAD lists t as a dependent.
|
||||
type deleteWorld struct {
|
||||
t, src *memHead
|
||||
objs map[string][]byte
|
||||
rels []string
|
||||
}
|
||||
|
||||
func newDeleteWorld() *deleteWorld {
|
||||
rn := RootName{Hash: Sum([]byte("src root"))}
|
||||
src := idleHead()
|
||||
src.VolumeID = idFor("src")
|
||||
src.Snapshots = map[string]Snapshot{"daily": {Root: rn, Dependents: deps(rn, "t")}}
|
||||
tgt := idleHead()
|
||||
tgt.VolumeID = idFor("t")
|
||||
rels := []string{NameChunk(1, []byte("x")).Path(), NameChunk(2, []byte("y")).Path()}
|
||||
objs := map[string][]byte{}
|
||||
for _, r := range rels {
|
||||
objs[path.Join(volRoot, r)] = []byte("o")
|
||||
}
|
||||
return &deleteWorld{t: &memHead{h: &tgt}, src: &memHead{h: &src}, objs: objs, rels: rels}
|
||||
}
|
||||
|
||||
// objects returns the target's objects as an object store of volume t.
|
||||
func (w *deleteWorld) objects() *memObjects {
|
||||
o := newMemObjects(volRoot)
|
||||
o.volume = idFor("t")
|
||||
for p, b := range w.objs {
|
||||
o.objs[p] = &memObject{data: b, meta: ObjectMeta{Session: "s0", Volume: o.volume}}
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
// A late delete of a finished volume delete never removes the object of a
|
||||
// volume created again under the name: the delete is conditional on the
|
||||
// entry's volume id, and the new volume's entry carries another.
|
||||
func TestDeleteVolume_ALateDeleteSparesTheNameReused(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
w := newDeleteWorld()
|
||||
o := w.objects()
|
||||
if err := DeleteVolume(ctx, w.t, &fakeMaster{}, idFor("t"), []HeadStore{w.src}, o, w.rels); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
o.volume = idFor("t again") // the name holds a new volume, which writes the same content name
|
||||
if err := o.Create(ctx, w.rels[0], []byte("o"), "n1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := o.DeleteOfVolume(ctx, w.rels[0], idFor("t")); !errors.Is(err, ErrPrecondition) {
|
||||
t.Fatalf("the old run's late delete: %v; want ErrPrecondition", err)
|
||||
}
|
||||
if !o.has(w.rels[0]) {
|
||||
t.Fatal("the old run's late delete removed the new volume's object")
|
||||
}
|
||||
}
|
||||
|
||||
// A delete is refused while a holder acts and while the volume has
|
||||
// dependents of its own; otherwise it runs in order and ends deleted with
|
||||
// its pool empty and itself released from its source.
|
||||
func TestDeleteVolume(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
w := newDeleteWorld()
|
||||
o := w.objects()
|
||||
if err := DeleteVolume(ctx, w.t, &fakeMaster{leases: 1}, idFor("t"), []HeadStore{w.src}, o, w.rels); !errors.Is(err, ErrHolderActive) || w.t.updates != 0 {
|
||||
t.Fatalf("delete while held: %v (%d HEAD writes)", err, w.t.updates)
|
||||
}
|
||||
if err := DeleteVolume(ctx, w.src, &fakeMaster{}, idFor("src"), nil, o, nil); !errors.Is(err, ErrHasDependents) {
|
||||
t.Fatalf("delete of a volume with a dependent: %v; want ErrHasDependents", err)
|
||||
}
|
||||
if err := DeleteVolume(ctx, w.t, &fakeMaster{}, idFor("t"), []HeadStore{w.src}, o, w.rels); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if w.t.h.State != StateDeleted || len(o.objs) != 0 || len(w.src.h.Snapshots["daily"].Dependents) != 0 {
|
||||
t.Fatalf("after the delete: state %q, %d objects, source dependents %+v", w.t.h.State, len(o.objs), w.src.h.Snapshots["daily"].Dependents)
|
||||
}
|
||||
if err := DeleteVolume(ctx, w.t, &fakeMaster{}, idFor("t"), []HeadStore{w.src}, o, w.rels); err != nil {
|
||||
t.Fatalf("a further re-run: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Interrupt at every step of the volume delete (HEAD deleting, the release
|
||||
// on the source, each object, HEAD deleted), before the write applies and
|
||||
// after it applied with its reply lost. After every kill no step past the
|
||||
// kill has run out of order (the pool is touched only once HEAD is
|
||||
// deleting and the source released); the re-run ends deleted, the pool
|
||||
// empty and the source released.
|
||||
func TestDeleteVolume_InterruptAtEveryStep(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
order := []string{"t HEAD", "src HEAD", "object", "object", "t HEAD"}
|
||||
for k := range order {
|
||||
for _, after := range []bool{false, true} {
|
||||
t.Run(fmt.Sprintf("step%d %s/after=%t", k+1, order[k], after), func(t *testing.T) {
|
||||
w := newDeleteWorld()
|
||||
o := w.objects()
|
||||
nth := 0
|
||||
for _, kind := range order[:k+1] {
|
||||
if kind == order[k] {
|
||||
nth++
|
||||
}
|
||||
}
|
||||
switch order[k] {
|
||||
case "t HEAD":
|
||||
w.t.killAt, w.t.after = nth, after
|
||||
case "src HEAD":
|
||||
w.src.killAt, w.src.after = nth, after
|
||||
case "object":
|
||||
o.killAt, o.after = nth, after
|
||||
}
|
||||
if err := DeleteVolume(ctx, w.t, &fakeMaster{}, idFor("t"), []HeadStore{w.src}, o, w.rels); !errors.Is(err, errKilled) {
|
||||
t.Fatalf("killed run: %v", err)
|
||||
}
|
||||
if len(o.objs) < len(w.rels) && (w.t.h.State == StateLive || len(w.src.h.Snapshots["daily"].Dependents) != 0) {
|
||||
t.Fatal("the pool was touched before HEAD was deleting and the source released")
|
||||
}
|
||||
if len(w.src.h.Snapshots["daily"].Dependents) == 0 && w.t.h.State == StateLive {
|
||||
t.Fatal("the source released the target before its HEAD was deleting")
|
||||
}
|
||||
w.t.restart()
|
||||
w.src.restart()
|
||||
o.dead, o.killAt = false, 0
|
||||
if err := DeleteVolume(ctx, w.t, &fakeMaster{}, idFor("t"), []HeadStore{w.src}, o, w.rels); err != nil {
|
||||
t.Fatalf("re-run: %v", err)
|
||||
}
|
||||
if w.t.h.State != StateDeleted || len(o.objs) != 0 || len(w.src.h.Snapshots["daily"].Dependents) != 0 {
|
||||
t.Fatalf("after the re-run: state %q, %d objects, source dependents %+v", w.t.h.State, len(o.objs), w.src.h.Snapshots["daily"].Dependents)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// operatorCase: source src (id of "src") lists target t as a dependent;
|
||||
// t's VOLUME, HEAD and root objects are as the case sets them. When the
|
||||
// target names chunks, namesSource decides whether one of them is src's.
|
||||
func operatorCase(t *testing.T, tgtHead *Head, tgtVolume *VolumeID, namesSource bool) (*memHead, *memHead, *Reader) {
|
||||
t.Helper()
|
||||
w := newDeleteWorld()
|
||||
objs := map[string][]byte{}
|
||||
put := func(rel string, b []byte) { objs[path.Join(removeBase, "t", rel)] = b }
|
||||
if tgtVolume != nil {
|
||||
b, err := Volume{ID: *tgtVolume, Name: "t", Format: VolumeFormat}.Encode()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
put(VolumeName, b)
|
||||
}
|
||||
if tgtHead != nil {
|
||||
m := manifest(Ref{Owner: "t", OwnerID: idFor("t"), Chunk: NameChunk(1, []byte("own"))})
|
||||
if namesSource {
|
||||
m[2] = Ref{Owner: "src", OwnerID: idFor("src"), Chunk: NameChunk(2, []byte("from src"))}
|
||||
}
|
||||
root, segs, err := Build(m)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for n, b := range segs {
|
||||
put(n.Path(), b)
|
||||
}
|
||||
rn, rb, err := NameRoot(root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
put(rn.Path(), rb)
|
||||
h := *tgtHead
|
||||
h.Current = &rn
|
||||
tgtHead = &h
|
||||
}
|
||||
r, err := NewReader(removeBase, "t", func(_ context.Context, p string) ([]byte, bool, error) {
|
||||
b, ok := objs[p]
|
||||
return b, ok, nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return w.src, &memHead{h: tgtHead}, r
|
||||
}
|
||||
|
||||
// The operator's remove-dependent releases a target only when the target
|
||||
// exists and is deleted or no longer names the source: its HEAD deleting
|
||||
// or deleted, its name holding another volume (another VOLUME id), or a
|
||||
// live HEAD none of whose roots names a chunk of the source. A live target
|
||||
// that still names the source is refused and the source is unchanged. A
|
||||
// target without HEAD (never created, or a restore that died between its
|
||||
// VOLUME and its HEAD) gets a deleted HEAD written exclusively in its
|
||||
// never-reused directory, so the restore can never create it later, and
|
||||
// only then is released.
|
||||
func TestOperatorReleaseDependent(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
live := idleHead()
|
||||
live.VolumeID = idFor("t")
|
||||
deleting := live
|
||||
deleting.State = StateDeleting
|
||||
tid, other := idFor("t"), idFor("t again")
|
||||
for name, tc := range map[string]struct {
|
||||
head *Head
|
||||
volume *VolumeID
|
||||
namesSource bool
|
||||
release bool
|
||||
want error
|
||||
}{
|
||||
"live target naming the source": {&live, &tid, true, false, ErrTargetLive},
|
||||
"live target no longer naming it": {&live, &tid, false, true, nil},
|
||||
"restore died between its creates": {nil, &tid, false, true, nil},
|
||||
"target never created": {nil, nil, false, true, nil},
|
||||
"target deleting": {&deleting, &tid, true, true, nil},
|
||||
"name holds another volume": {nil, &other, false, true, nil},
|
||||
} {
|
||||
src, tgt, r := operatorCase(t, tc.head, tc.volume, tc.namesSource)
|
||||
before := src.updates
|
||||
_, err := OperatorReleaseDependent(ctx, src, tgt, r, tid)
|
||||
released := len(src.h.Snapshots["daily"].Dependents) == 0
|
||||
if tc.head == nil && (tc.volume == nil || *tc.volume == tid) && (tgt.h == nil || tgt.h.State != StateDeleted || tgt.h.VolumeID != tid) {
|
||||
t.Errorf("%s: target HEAD %+v; want a deleted HEAD (tombstone) of the target's id written before the release", name, tgt.h)
|
||||
}
|
||||
if tc.release && (err != nil || !released) {
|
||||
t.Errorf("%s: %v, released %t; want released", name, err, released)
|
||||
}
|
||||
if !tc.release && (!errors.Is(err, tc.want) || released || src.updates != before) {
|
||||
t.Errorf("%s: %v, released %t; want %v and the source unchanged", name, err, released, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the restore creates the target's HEAD between the operator's read and
|
||||
// its tombstone, the exclusive create fails and nothing is released.
|
||||
func TestOperatorReleaseDependent_TombstoneLosesToTheRestore(t *testing.T) {
|
||||
src, tgt, r := operatorCase(t, nil, nil, false)
|
||||
live := idleHead()
|
||||
live.VolumeID = idFor("t")
|
||||
created := &raceTarget{memHead: tgt, appear: &live}
|
||||
before := src.updates
|
||||
if _, err := OperatorReleaseDependent(context.Background(), src, created, r, idFor("t")); !errors.Is(err, ErrTargetLive) || src.updates != before {
|
||||
t.Fatalf("tombstone after the restore created the HEAD: %v (%d source writes); want ErrTargetLive and none", err, src.updates-before)
|
||||
}
|
||||
}
|
||||
|
||||
// raceTarget makes a HEAD appear right before the tombstone's create.
|
||||
type raceTarget struct {
|
||||
*memHead
|
||||
appear *Head
|
||||
}
|
||||
|
||||
func (r *raceTarget) CreateDeletedHead(ctx context.Context, h Head) error {
|
||||
if r.appear != nil {
|
||||
n := r.appear.clone()
|
||||
r.memHead.h, r.appear = &n, nil
|
||||
}
|
||||
return r.memHead.CreateDeletedHead(ctx, h)
|
||||
}
|
||||
|
||||
// A volume delete removes only content-named objects: HEAD (which stays,
|
||||
// deleted), VOLUME and the directory are refused before any write.
|
||||
func TestDeleteVolume_RemovesOnlyObjects(t *testing.T) {
|
||||
for _, bad := range []string{HeadName, VolumeName, "", "pool/", "pool/../HEAD", "other/x"} {
|
||||
w := newDeleteWorld()
|
||||
o := w.objects()
|
||||
if err := DeleteVolume(context.Background(), w.t, &fakeMaster{}, idFor("t"), []HeadStore{w.src}, o, append(append([]string(nil), w.rels...), bad)); !errors.Is(err, ErrMalformed) || w.t.updates != 0 || len(o.writes) != 0 {
|
||||
t.Errorf("delete listing %q: %v (%d HEAD writes, %d object writes); want ErrMalformed and nothing written", bad, err, w.t.updates, len(o.writes))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The delete's premise is held by the master, not read once: a grant and
|
||||
// claim before the reservation is seen as a live lease and refuses; a
|
||||
// grant after it is refused by the master; a claim landing between the
|
||||
// HEAD read and the update fails the update. In every case no object is
|
||||
// deleted from a volume a holder acts on.
|
||||
func TestDeleteVolume_AGrantRaceNeverDeletesALiveVolume(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
claim := func(h *memHead) { h.h.Epoch, h.h.Holder, h.h.ClaimID = h.h.Epoch+1, "srv-new", "k-new"; h.h.Gen++ }
|
||||
t.Run("granted and claimed before the reservation", func(t *testing.T) {
|
||||
w := newDeleteWorld()
|
||||
o := w.objects()
|
||||
m := &fakeMaster{}
|
||||
if err := m.grant(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
claim(w.t)
|
||||
if err := DeleteVolume(ctx, w.t, m, idFor("t"), []HeadStore{w.src}, o, w.rels); !errors.Is(err, ErrHolderActive) || len(o.writes) != 0 || w.t.h.State != StateLive {
|
||||
t.Fatalf("delete of a volume with a granted line: %v, %d object writes, HEAD %s; want ErrHolderActive, nothing deleted", err, len(o.writes), w.t.h.State)
|
||||
}
|
||||
})
|
||||
t.Run("grant attempted after the reservation", func(t *testing.T) {
|
||||
w := newDeleteWorld()
|
||||
o := w.objects()
|
||||
m := &fakeMaster{}
|
||||
var grantErr error
|
||||
m.onReserve = func() {
|
||||
if grantErr = m.grant(); grantErr == nil {
|
||||
claim(w.t)
|
||||
}
|
||||
}
|
||||
if err := DeleteVolume(ctx, w.t, m, idFor("t"), []HeadStore{w.src}, o, w.rels); err != nil {
|
||||
t.Fatalf("delete: %v", err)
|
||||
}
|
||||
if grantErr == nil {
|
||||
t.Fatal("the master granted a line after the delete reservation")
|
||||
}
|
||||
})
|
||||
t.Run("a claim between the HEAD read and the update", func(t *testing.T) {
|
||||
w := newDeleteWorld()
|
||||
o := w.objects()
|
||||
w.t.afterRead = func() { claim(w.t) }
|
||||
if err := DeleteVolume(ctx, w.t, &fakeMaster{}, idFor("t"), []HeadStore{w.src}, o, w.rels); err == nil || len(o.writes) != 0 || w.t.h.State != StateLive {
|
||||
t.Fatalf("delete with a claim after its HEAD read: %v, %d object writes, HEAD %s; want the update refused, nothing deleted", err, len(o.writes), w.t.h.State)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -123,10 +123,15 @@ func owners(m map[string]bool) []string {
|
||||
// - Lease, claim half: OldLeaseEnded is used only in RunClaim, and
|
||||
// RunClaim, when it is declared, uses it.
|
||||
// - Every declared exported Run function goes through runTransition.
|
||||
// - Release of a dependent: RunReleaseDependent is used only by
|
||||
// DeleteVolume (its own HEAD is deleting) and OperatorReleaseDependent,
|
||||
// which reads the target's HEAD before it releases.
|
||||
// - Pool: a name starting with Delete or Remove is used only in
|
||||
// RemoveUnreachable, and there every delete is preceded, in the same
|
||||
// loop body, by the remover's own lease check (StillHeld); see
|
||||
// removerOrderFindings.
|
||||
// RemoveUnreachable, where every delete is preceded, in the same loop
|
||||
// body, by the remover's own lease check (StillHeld), and in
|
||||
// DeleteVolume, whose steps run in the delete's order: no holder, HEAD
|
||||
// deleting, the dependents released, the objects deleted, HEAD
|
||||
// deleted; see removerOrderFindings and deleteOrderFindings.
|
||||
//
|
||||
// These are syntactic checks of this package's own files: they see any
|
||||
// use of these names, but not a store effect reached through a name they
|
||||
@@ -161,16 +166,37 @@ func guardFindings(code map[string]map[string]bool, decl, tests map[string]bool)
|
||||
if decl["RunClaim"] && !code["OldLeaseEnded"]["RunClaim"] {
|
||||
bad = append(bad, "RunClaim is declared and does not wait for the old lease")
|
||||
}
|
||||
for _, fn := range owners(code["NoLiveLease"]) {
|
||||
if fn != "RunMarkDeleting" {
|
||||
bad = append(bad, fn+" uses NoLiveLease; only RunMarkDeleting checks it, between its HEAD read and update")
|
||||
}
|
||||
}
|
||||
if decl["RunMarkDeleting"] && !code["NoLiveLease"]["RunMarkDeleting"] {
|
||||
bad = append(bad, "RunMarkDeleting is declared and does not check the master's live leases")
|
||||
}
|
||||
for fn := range decl {
|
||||
if strings.HasPrefix(fn, "Run") && !code["runTransition"][fn] {
|
||||
bad = append(bad, fn+" is declared and does not go through runTransition")
|
||||
}
|
||||
}
|
||||
for _, fn := range owners(code["CreateDeletedHead"]) {
|
||||
if fn != "OperatorReleaseDependent" {
|
||||
bad = append(bad, fn+" uses CreateDeletedHead: only the operator's release writes a tombstone, for a target never created")
|
||||
}
|
||||
}
|
||||
for _, fn := range owners(code["RunReleaseDependent"]) {
|
||||
if fn != "DeleteVolume" && fn != "OperatorReleaseDependent" {
|
||||
bad = append(bad, fn+" uses RunReleaseDependent: only DeleteVolume (target deleting) and OperatorReleaseDependent (target checked) release")
|
||||
}
|
||||
}
|
||||
if decl["OperatorReleaseDependent"] && !code["ReadHead"]["OperatorReleaseDependent"] {
|
||||
bad = append(bad, "OperatorReleaseDependent does not read the target's HEAD before releasing")
|
||||
}
|
||||
for name, by := range code {
|
||||
if strings.HasPrefix(name, "Delete") || strings.HasPrefix(name, "Remove") {
|
||||
for _, fn := range owners(by) {
|
||||
if fn != "RemoveUnreachable" {
|
||||
bad = append(bad, fn+" uses "+name+": only RemoveUnreachable removes, after its lease re-check")
|
||||
if fn != "RemoveUnreachable" && fn != "DeleteVolume" {
|
||||
bad = append(bad, fn+" uses "+name+": only RemoveUnreachable (mark-gated) and DeleteVolume (after HEAD deleting and the dependents released) remove")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -285,6 +311,57 @@ func removerOrderFindings(t *testing.T, srcs map[string]string) []string {
|
||||
return bad
|
||||
}
|
||||
|
||||
// deleteOrderFindings checks DeleteVolume's order in the sources: among its
|
||||
// top-level statements, the first use of each step comes after the
|
||||
// previous step's: Reserve, RunMarkDeleting, RunReleaseDependent,
|
||||
// DeleteOfVolume, RunMarkDeleted.
|
||||
func deleteOrderFindings(t *testing.T, srcs map[string]string) []string {
|
||||
t.Helper()
|
||||
steps := []string{"Reserve", "RunMarkDeleting", "RunReleaseDependent", "DeleteOfVolume", "RunMarkDeleted"}
|
||||
var bad []string
|
||||
for fname, src := range srcs {
|
||||
file, err := parser.ParseFile(token.NewFileSet(), fname, src, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, d := range file.Decls {
|
||||
fn, ok := d.(*ast.FuncDecl)
|
||||
if !ok || fn.Body == nil || fn.Name.Name != "DeleteVolume" {
|
||||
continue
|
||||
}
|
||||
first := map[string]int{}
|
||||
for i, st := range fn.Body.List {
|
||||
ast.Inspect(st, func(n ast.Node) bool {
|
||||
var name string
|
||||
switch x := n.(type) {
|
||||
case *ast.SelectorExpr:
|
||||
name = x.Sel.Name
|
||||
case *ast.Ident:
|
||||
name = x.Name
|
||||
}
|
||||
if _, seen := first[name]; !seen && name != "" {
|
||||
first[name] = i
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
for k, step := range steps {
|
||||
at, ok := first[step]
|
||||
if !ok {
|
||||
bad = append(bad, "DeleteVolume has no "+step)
|
||||
continue
|
||||
}
|
||||
if k > 0 {
|
||||
if prev, ok := first[steps[k-1]]; ok && prev >= at {
|
||||
bad = append(bad, "DeleteVolume runs "+step+" before "+steps[k-1]+" has run")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return bad
|
||||
}
|
||||
|
||||
// declared returns the names of the functions the sources declare.
|
||||
func declared(t *testing.T, srcs map[string]string) map[string]bool {
|
||||
t.Helper()
|
||||
@@ -310,6 +387,9 @@ func TestGuard_WritersTransitionsAndRemovers(t *testing.T) {
|
||||
if bad := append(guardFindings(code, declared(t, src), tests), removerOrderFindings(t, src)...); len(bad) != 0 {
|
||||
t.Fatalf("guard: %s", strings.Join(bad, "\n"))
|
||||
}
|
||||
if bad := deleteOrderFindings(t, src); len(bad) != 0 {
|
||||
t.Fatalf("guard: %s", strings.Join(bad, "\n"))
|
||||
}
|
||||
st := reflect.TypeOf((*HeadStore)(nil)).Elem()
|
||||
var methods []string
|
||||
for i := 0; i < st.NumMethod(); i++ {
|
||||
@@ -341,17 +421,60 @@ func TestGuard_Controls(t *testing.T) {
|
||||
"untested transition": {src: `func RunZz(ctx context.Context, st HeadStore) (Head, error) { return runTransition(ctx, st, nil) }`, want: "has no TestZz_Closure"},
|
||||
"lease wait outside claim": {src: `func w(ctx context.Context, l LeaseWait) error { return l.OldLeaseEnded(ctx, 1) }`, want: "only RunClaim claims"},
|
||||
"remover outside RemoveUnreachable": {src: `type p interface{ DeleteObject(context.Context, string) error }
|
||||
func w(ctx context.Context, x p) error { return x.DeleteObject(ctx, "o") }`, want: "only RemoveUnreachable removes"},
|
||||
func w(ctx context.Context, x p) error { return x.DeleteObject(ctx, "o") }`, want: "only RemoveUnreachable (mark-gated) and DeleteVolume"},
|
||||
"claim without lease wait": {src: `func RunClaim(ctx context.Context, st HeadStore, lease LeaseWait, me HolderID) (Head, error) {
|
||||
return runTransition(ctx, st, func(h Head) (Head, bool, error) { return h, false, nil })
|
||||
}`, want: "does not wait for the old lease", file: "claim.go"},
|
||||
"transition not through runTransition": {src: `func RunZz(ctx context.Context, st HeadStore) (Head, error) { h, _, err := st.ReadHead(ctx); return h, err }`, want: "does not go through runTransition"},
|
||||
"unconditional delete": {file: "remove.go", src: removeVariant(t, "unconditional"), want: "its only removal is DeleteMarked"},
|
||||
"ignored mark": {file: "remove.go", src: removeVariant(t, "ignored"), want: "without a mark gate immediately before it"},
|
||||
"one mark, two deletes": {file: "remove.go", src: removeVariant(t, "second"), want: "without a mark gate immediately before it"},
|
||||
"unlisted removal method": {file: "remove.go", src: removeVariant(t, "other"), want: "without a mark gate immediately before it"},
|
||||
"delete removes the pool before releasing dependents": {file: "delete.go", src: `type p interface{ DeleteOfVolume(context.Context, string, VolumeID) error }
|
||||
type g interface{ Reserve(context.Context) error; NoLiveLease(context.Context) error }
|
||||
func RunMarkDeleting(ctx context.Context, st HeadStore, x g) (Head, error) { _ = x.NoLiveLease(ctx); return runTransition(ctx, st, nil) }
|
||||
func RunMarkDeleted(ctx context.Context, st HeadStore) (Head, error) { return runTransition(ctx, st, nil) }
|
||||
func RunReleaseDependent(ctx context.Context, st HeadStore, id VolumeID) (Head, error) { return runTransition(ctx, st, nil) }
|
||||
func DeleteVolume(ctx context.Context, st HeadStore, x g, id VolumeID, srcs []HeadStore, pool p, objs []string) error {
|
||||
_ = x.Reserve(ctx)
|
||||
_, _ = RunMarkDeleting(ctx, st, x)
|
||||
for _, o := range objs {
|
||||
_ = pool.DeleteOfVolume(ctx, o, id)
|
||||
}
|
||||
for _, s := range srcs {
|
||||
_, _ = RunReleaseDependent(ctx, s, id)
|
||||
}
|
||||
_, _ = RunMarkDeleted(ctx, st)
|
||||
return nil
|
||||
}`, want: "runs DeleteOfVolume before RunReleaseDependent"},
|
||||
"delete without the reservation": {file: "delete.go", src: `type p interface{ DeleteOfVolume(context.Context, string, VolumeID) error }
|
||||
type g interface{ NoLiveLease(context.Context) error }
|
||||
func RunMarkDeleting(ctx context.Context, st HeadStore, x g) (Head, error) { _ = x.NoLiveLease(ctx); return runTransition(ctx, st, nil) }
|
||||
func RunMarkDeleted(ctx context.Context, st HeadStore) (Head, error) { return runTransition(ctx, st, nil) }
|
||||
func RunReleaseDependent(ctx context.Context, st HeadStore, id VolumeID) (Head, error) { return runTransition(ctx, st, nil) }
|
||||
func DeleteVolume(ctx context.Context, st HeadStore, x g, id VolumeID, srcs []HeadStore, pool p, objs []string) error {
|
||||
_, _ = RunMarkDeleting(ctx, st, x)
|
||||
for _, s := range srcs {
|
||||
_, _ = RunReleaseDependent(ctx, s, id)
|
||||
}
|
||||
for _, o := range objs {
|
||||
_ = pool.DeleteOfVolume(ctx, o, id)
|
||||
}
|
||||
_, _ = RunMarkDeleted(ctx, st)
|
||||
return nil
|
||||
}`, want: "DeleteVolume has no Reserve"},
|
||||
"mark deleting without the live-lease check": {file: "delete.go", src: `func RunMarkDeleting(ctx context.Context, st HeadStore) (Head, error) {
|
||||
return runTransition(ctx, st, func(h Head) (Head, bool, error) { return h.MarkDeleting() })
|
||||
}`, want: "does not check the master's live leases"},
|
||||
"live-lease check outside mark deleting": {src: `type g interface{ NoLiveLease(context.Context) error }
|
||||
func w(ctx context.Context, x g) error { return x.NoLiveLease(ctx) }`, want: "only RunMarkDeleting checks it"},
|
||||
"release outside delete and the operator's check": {src: `func w(ctx context.Context, st HeadStore, id VolumeID) { _, _ = RunReleaseDependent(ctx, st, id) }`, want: "only DeleteVolume (target deleting) and OperatorReleaseDependent"},
|
||||
"operator release without reading the target": {file: "delete.go", src: `func OperatorReleaseDependent(ctx context.Context, source HeadStore, id VolumeID) (Head, error) {
|
||||
return RunReleaseDependent(ctx, source, id)
|
||||
}`, want: "does not read the target's HEAD"},
|
||||
"unconditional delete": {file: "remove.go", src: removeVariant(t, "unconditional"), want: "its only removal is DeleteMarked"},
|
||||
"ignored mark": {file: "remove.go", src: removeVariant(t, "ignored"), want: "without a mark gate immediately before it"},
|
||||
"one mark, two deletes": {file: "remove.go", src: removeVariant(t, "second"), want: "without a mark gate immediately before it"},
|
||||
"unlisted removal method": {file: "remove.go", src: removeVariant(t, "other"), want: "without a mark gate immediately before it"},
|
||||
"tombstone outside the operator's release": {src: `func w(ctx context.Context, t TargetStore, h Head) { _ = t.CreateDeletedHead(ctx, h) }`, want: "only the operator's release writes a tombstone"},
|
||||
"remover method value": {src: `type p interface{ RemoveName(string) }
|
||||
func w(x p) { f := x.RemoveName; f("o") }`, want: "only RemoveUnreachable removes"},
|
||||
func w(x p) { f := x.RemoveName; f("o") }`, want: "only RemoveUnreachable (mark-gated) and DeleteVolume"},
|
||||
} {
|
||||
srcs := packageSources(t, false)
|
||||
file := c.file
|
||||
@@ -359,7 +482,7 @@ func w(x p) { f := x.RemoveName; f("o") }`, want: "only RemoveUnreachable remove
|
||||
file = "zz_control.go"
|
||||
}
|
||||
srcs[file] = "package layout\n\nimport \"context\"\n\nvar _ context.Context\n\n" + c.src + "\n"
|
||||
bad := append(guardFindings(refs(t, srcs), declared(t, srcs), tests), removerOrderFindings(t, srcs)...)
|
||||
bad := append(append(guardFindings(refs(t, srcs), declared(t, srcs), tests), removerOrderFindings(t, srcs)...), deleteOrderFindings(t, srcs)...)
|
||||
if !strings.Contains(strings.Join(bad, "\n"), c.want) {
|
||||
t.Errorf("control %q: findings %q; want one containing %q", name, bad, c.want)
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ type Head struct {
|
||||
Current *RootName // nil: no image committed yet
|
||||
Position uint64
|
||||
Snapshots map[string]Snapshot
|
||||
State string // StateLive, StateDeleting or StateDeleted
|
||||
}
|
||||
|
||||
type headDoc struct {
|
||||
@@ -74,6 +75,7 @@ type headDoc struct {
|
||||
Current string `json:"current,omitempty"`
|
||||
Position uint64 `json:"position"`
|
||||
Snapshots map[string]snapDoc `json:"snapshots,omitempty"`
|
||||
State string `json:"state,omitempty"`
|
||||
}
|
||||
|
||||
type snapDoc struct {
|
||||
@@ -101,6 +103,11 @@ func (h Head) check() error {
|
||||
if h.VolumeID.IsZero() {
|
||||
return fmt.Errorf("%w: HEAD without a volume id", ErrMalformed)
|
||||
}
|
||||
switch h.State {
|
||||
case StateLive, StateDeleting, StateDeleted:
|
||||
default:
|
||||
return fmt.Errorf("%w: HEAD state %q", ErrMalformed, h.State)
|
||||
}
|
||||
for field, v := range map[string]string{"holder": h.Holder, "session": h.Activity.Session, "claim id": h.ClaimID} {
|
||||
if err := validName(field, v); err != nil {
|
||||
return err
|
||||
@@ -118,11 +125,16 @@ func (h Head) check() error {
|
||||
default:
|
||||
return fmt.Errorf("%w: activity %q", ErrMalformed, h.Activity.Kind)
|
||||
}
|
||||
if h.Epoch == 0 || h.Holder == "" {
|
||||
return fmt.Errorf("%w: HEAD without epoch or holder", ErrMalformed)
|
||||
}
|
||||
if h.ClaimID == "" {
|
||||
return fmt.Errorf("%w: HEAD holder %q without a claim id", ErrMalformed, h.Holder)
|
||||
// A deleted HEAD written as a tombstone for a restore target never
|
||||
// created has no holder; every other HEAD has an epoch, a holder and
|
||||
// the claim id of its claim.
|
||||
if h.State != StateDeleted || h.Holder != "" {
|
||||
if h.Epoch == 0 || h.Holder == "" {
|
||||
return fmt.Errorf("%w: HEAD without epoch or holder", ErrMalformed)
|
||||
}
|
||||
if h.ClaimID == "" {
|
||||
return fmt.Errorf("%w: HEAD holder %q without a claim id", ErrMalformed, h.Holder)
|
||||
}
|
||||
}
|
||||
if len(h.Snapshots) > MaxSnapshots {
|
||||
return fmt.Errorf("%w: %d snapshots, at most %d", ErrMalformed, len(h.Snapshots), MaxSnapshots)
|
||||
@@ -160,7 +172,7 @@ func (h Head) Encode() ([]byte, error) {
|
||||
if err := h.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
d := headDoc{VolumeID: h.VolumeID.String(), Epoch: h.Epoch, Holder: h.Holder, ClaimID: h.ClaimID, Activity: h.Activity, Position: h.Position}
|
||||
d := headDoc{VolumeID: h.VolumeID.String(), Epoch: h.Epoch, Holder: h.Holder, ClaimID: h.ClaimID, Activity: h.Activity, Position: h.Position, State: h.State}
|
||||
if h.Current != nil {
|
||||
d.Current = h.Current.String()
|
||||
}
|
||||
@@ -196,7 +208,7 @@ func DecodeHead(b []byte, gen uint64, volume VolumeID) (Head, error) {
|
||||
if err != nil {
|
||||
return Head{}, err
|
||||
}
|
||||
h := Head{Gen: gen, VolumeID: vid, Epoch: d.Epoch, Holder: d.Holder, ClaimID: d.ClaimID, Activity: d.Activity, Position: d.Position}
|
||||
h := Head{Gen: gen, VolumeID: vid, Epoch: d.Epoch, Holder: d.Holder, ClaimID: d.ClaimID, Activity: d.Activity, Position: d.Position, State: d.State}
|
||||
if d.Current != "" {
|
||||
rn, err := ParseRootName(d.Current)
|
||||
if err != nil {
|
||||
@@ -261,6 +273,19 @@ func (h Head) heldBy(me HolderID) bool {
|
||||
return h.Epoch == me.Epoch && h.Holder == me.Holder && h.ClaimID == me.ClaimID
|
||||
}
|
||||
|
||||
// holderErr is the refusal of a holder transition: the volume is being
|
||||
// deleted or is deleted (ErrVolumeDeleting), or the caller is not the
|
||||
// holder at HEAD's epoch (ErrNotHolder); nil when it may act.
|
||||
func (h Head) holderErr(me HolderID) error {
|
||||
if h.State != StateLive {
|
||||
return fmt.Errorf("%w: HEAD is %s", ErrVolumeDeleting, h.State)
|
||||
}
|
||||
if !h.heldBy(me) {
|
||||
return fmt.Errorf("%w: HEAD epoch %d holder %q claim %q, caller epoch %d holder %q claim %q", ErrNotHolder, h.Epoch, h.Holder, h.ClaimID, me.Epoch, me.Holder, me.ClaimID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Begin is transition 2: activity idle -> snap(session), by the holder at
|
||||
// HEAD's epoch. Begin of the session already open is a replay: it returns
|
||||
// HEAD unchanged and changed=false. Any other open activity is ErrBusy.
|
||||
@@ -268,8 +293,8 @@ func (h Head) Begin(me HolderID, session string) (next Head, changed bool, err e
|
||||
if session == "" {
|
||||
return Head{}, false, errors.New("layout: Begin needs a session id")
|
||||
}
|
||||
if !h.heldBy(me) {
|
||||
return Head{}, false, fmt.Errorf("%w: HEAD epoch %d holder %q, caller epoch %d holder %q", ErrNotHolder, h.Epoch, h.Holder, me.Epoch, me.Holder)
|
||||
if err := h.holderErr(me); err != nil {
|
||||
return Head{}, false, err
|
||||
}
|
||||
switch {
|
||||
case h.Activity == Activity{Kind: ActSnap, Session: session}:
|
||||
@@ -329,8 +354,8 @@ func (h Head) Abort(me HolderID, session string) (next Head, changed bool, err e
|
||||
if session == "" {
|
||||
return Head{}, false, errors.New("layout: Abort needs a session id")
|
||||
}
|
||||
if !h.heldBy(me) {
|
||||
return Head{}, false, fmt.Errorf("%w: HEAD epoch %d holder %q, caller epoch %d holder %q", ErrNotHolder, h.Epoch, h.Holder, me.Epoch, me.Holder)
|
||||
if err := h.holderErr(me); err != nil {
|
||||
return Head{}, false, err
|
||||
}
|
||||
switch {
|
||||
case h.Activity.Kind == ActIdle:
|
||||
|
||||
@@ -207,6 +207,29 @@ func (m *memHead) UpdateHead(_ context.Context, gen uint64, next Head) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateDeletedHead writes a deleted HEAD exclusively (a tombstone).
|
||||
func (m *memHead) CreateDeletedHead(_ context.Context, h Head) error {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
if m.dead {
|
||||
return errKilled
|
||||
}
|
||||
if m.h != nil {
|
||||
return ErrExists
|
||||
}
|
||||
if h.State != StateDeleted {
|
||||
return errors.New("only a deleted HEAD is created")
|
||||
}
|
||||
if _, err := h.Encode(); err != nil {
|
||||
return err
|
||||
}
|
||||
n := h.clone()
|
||||
n.Gen = 1
|
||||
m.h = &n
|
||||
m.updates++
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *memHead) restart() { m.mu.Lock(); m.dead = false; m.killAt = 0; m.mu.Unlock() }
|
||||
|
||||
func TestRunBegin(t *testing.T) {
|
||||
|
||||
@@ -7,11 +7,14 @@ import (
|
||||
)
|
||||
|
||||
// ObjectMeta is what an object entry (chunk, segment, root) carries besides
|
||||
// its bytes: the session of its last writer and a removal mark (the
|
||||
// session of a cleaning that planned to remove it; empty when unmarked).
|
||||
// its bytes: the session of its last writer, a removal mark (the session
|
||||
// of a cleaning that planned to remove it; empty when unmarked) and the id
|
||||
// of the volume it belongs to (content names repeat across volumes and
|
||||
// across a volume's re-creation under its name).
|
||||
type ObjectMeta struct {
|
||||
Session string
|
||||
Mark string
|
||||
Volume VolumeID // the volume the entry belongs to, stamped by the store at Create
|
||||
}
|
||||
|
||||
// ErrExists is returned by ObjectStore.Create when the entry exists.
|
||||
@@ -24,7 +27,8 @@ type ObjectStore interface {
|
||||
// Stat returns an entry's metadata; a missing entry is found=false.
|
||||
Stat(ctx context.Context, rel string) (meta ObjectMeta, found bool, err error)
|
||||
// Create writes a new entry exclusively (data first, entry after),
|
||||
// with session as its writer; ErrExists if the entry exists.
|
||||
// with session as its writer and the store's volume id; ErrExists if
|
||||
// the entry exists.
|
||||
Create(ctx context.Context, rel string, data []byte, session string) error
|
||||
// Reuse sets session as the writer and clears the mark, only if the
|
||||
// entry's metadata is still expect (ErrPrecondition otherwise).
|
||||
@@ -35,6 +39,9 @@ type ObjectStore interface {
|
||||
// DeleteMarked deletes the entry only if it carries mark
|
||||
// (ErrPrecondition otherwise); a missing entry succeeds.
|
||||
DeleteMarked(ctx context.Context, rel string, mark string) error
|
||||
// DeleteOfVolume deletes the entry only if it belongs to volume
|
||||
// (ErrPrecondition otherwise); a missing entry succeeds.
|
||||
DeleteOfVolume(ctx context.Context, rel string, volume VolumeID) error
|
||||
}
|
||||
|
||||
// maxEnsureRounds bounds EnsureObject's retries when another writer moves
|
||||
|
||||
@@ -18,6 +18,7 @@ type memObject struct {
|
||||
// point counted over its writes (Create, Reuse, Mark, DeleteMarked).
|
||||
type memObjects struct {
|
||||
root string
|
||||
volume VolumeID // stamped on every entry the store creates
|
||||
objs map[string]*memObject
|
||||
fail string
|
||||
asked []string
|
||||
@@ -84,7 +85,7 @@ func (m *memObjects) Create(_ context.Context, rel string, data []byte, session
|
||||
if _, ok := m.objs[m.full(rel)]; ok {
|
||||
return ErrExists
|
||||
}
|
||||
m.objs[m.full(rel)] = &memObject{data: append([]byte(nil), data...), meta: ObjectMeta{Session: session}}
|
||||
m.objs[m.full(rel)] = &memObject{data: append([]byte(nil), data...), meta: ObjectMeta{Session: session, Volume: m.volume}}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -95,7 +96,7 @@ func (m *memObjects) Reuse(_ context.Context, rel string, expect ObjectMeta, ses
|
||||
if !ok || o.meta != expect {
|
||||
return ErrPrecondition
|
||||
}
|
||||
o.meta = ObjectMeta{Session: session}
|
||||
o.meta = ObjectMeta{Session: session, Volume: o.meta.Volume}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -125,9 +126,23 @@ func (m *memObjects) DeleteMarked(_ context.Context, rel string, mark string) er
|
||||
})
|
||||
}
|
||||
|
||||
func (m *memObjects) DeleteOfVolume(_ context.Context, rel string, volume VolumeID) error {
|
||||
return m.write("delete-of-volume", rel, func() error {
|
||||
o, ok := m.objs[m.full(rel)]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
if o.meta.Volume != volume {
|
||||
return ErrPrecondition
|
||||
}
|
||||
delete(m.objs, m.full(rel))
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// put stores an object directly (fixture setup, no kill point).
|
||||
func (m *memObjects) put(rel string, data []byte, session string) {
|
||||
m.objs[m.full(rel)] = &memObject{data: append([]byte(nil), data...), meta: ObjectMeta{Session: session}}
|
||||
m.objs[m.full(rel)] = &memObject{data: append([]byte(nil), data...), meta: ObjectMeta{Session: session, Volume: m.volume}}
|
||||
}
|
||||
|
||||
func (m *memObjects) has(rel string) bool { _, ok := m.objs[m.full(rel)]; return ok }
|
||||
|
||||
@@ -147,8 +147,9 @@ func (img *Image) Resolve(ctx context.Context, index uint64) (ref Ref, zero bool
|
||||
}
|
||||
|
||||
// Chunk resolves index and reads its bytes from the pool of the volume
|
||||
// that owns it, after checking that volume's VOLUME id is the one the
|
||||
// reference carries (ErrIdentity otherwise). A chunk the root names but the
|
||||
// that owns it, in that volume's directory (VolumeDir of the reference's
|
||||
// owner name and id), after checking the directory's VOLUME id is the one
|
||||
// the reference carries (ErrIdentity otherwise). A chunk the root names but the
|
||||
// owner's pool lacks is ErrMissing.
|
||||
func (img *Image) Chunk(ctx context.Context, index uint64) (Chunk, error) {
|
||||
ref, zero, err := img.Resolve(ctx, index)
|
||||
@@ -158,14 +159,15 @@ func (img *Image) Chunk(ctx context.Context, index uint64) (Chunk, error) {
|
||||
if zero {
|
||||
return Chunk{Zero: true}, nil
|
||||
}
|
||||
id, err := img.r.VolumeID(ctx, ref.Owner)
|
||||
dir := VolumeDir(ref.Owner, ref.OwnerID)
|
||||
id, err := img.r.VolumeID(ctx, dir)
|
||||
if err != nil {
|
||||
return Chunk{}, err
|
||||
}
|
||||
if id != ref.OwnerID {
|
||||
return Chunk{}, fmt.Errorf("%w: chunk %d names %s id %s, VOLUME has %s", ErrIdentity, index, ref.Owner, ref.OwnerID, id)
|
||||
}
|
||||
b, err := img.r.get(ctx, ref.Owner, ref.Chunk.Path(), ref.Chunk.Hash)
|
||||
b, err := img.r.get(ctx, dir, ref.Chunk.Path(), ref.Chunk.Hash)
|
||||
if err != nil {
|
||||
return Chunk{}, err
|
||||
}
|
||||
|
||||
@@ -27,6 +27,12 @@ func (s *objStore) fetch(_ context.Context, p string) ([]byte, bool, error) {
|
||||
|
||||
const base = "/swblock/chunks"
|
||||
|
||||
// The test volumes' directories: <name>-<first 8 hex of the volume id>.
|
||||
var (
|
||||
tDir = VolumeDir("t", idFor("t"))
|
||||
srcDir = VolumeDir("src", idFor("src"))
|
||||
)
|
||||
|
||||
// readFixture: volume "t" (a restore target) whose root names chunk 3
|
||||
// ("own") in its own pool, chunk 10002 ("src data") in the pool of "src",
|
||||
// and nothing else; every object is written.
|
||||
@@ -36,29 +42,29 @@ func readFixture(t *testing.T) (*objStore, RootName, map[uint64]Ref) {
|
||||
put := func(vol, rel string, b []byte) { s.obj[path.Join(base, vol, rel)] = b }
|
||||
own := NameChunk(3, []byte("own"))
|
||||
foreign := NameChunk(10002, []byte("src data"))
|
||||
put("t", own.Path(), []byte("own"))
|
||||
put("src", foreign.Path(), []byte("src data"))
|
||||
put(tDir, own.Path(), []byte("own"))
|
||||
put(srcDir, foreign.Path(), []byte("src data"))
|
||||
m := map[uint64]Ref{3: {Owner: "t", OwnerID: idFor("t"), Chunk: own}, 10002: {Owner: "src", OwnerID: idFor("src"), Chunk: foreign}}
|
||||
putVolume(t, put, "t")
|
||||
putVolume(t, put, "src")
|
||||
putVolume(t, put, "t", tDir)
|
||||
putVolume(t, put, "src", srcDir)
|
||||
root, segs, err := Build(m)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for n, b := range segs {
|
||||
put("t", n.Path(), b)
|
||||
put(tDir, n.Path(), b)
|
||||
}
|
||||
rn, rb, err := NameRoot(root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
put("t", rn.Path(), rb)
|
||||
put(tDir, rn.Path(), rb)
|
||||
return s, rn, m
|
||||
}
|
||||
|
||||
func newReader(t *testing.T, s *objStore) *Reader {
|
||||
t.Helper()
|
||||
r, err := NewReader(base, "t", s.fetch)
|
||||
r, err := NewReader(base, tDir, s.fetch)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -106,7 +112,7 @@ func TestRead_AbsentIndexIsZeros(t *testing.T) {
|
||||
func TestRead_ForeignChunkFromSourcePool(t *testing.T) {
|
||||
s, rn, m := readFixture(t)
|
||||
// A same-named object in t's own pool must not be what is read.
|
||||
s.obj[path.Join(base, "t", m[10002].Chunk.Path())] = []byte("decoy")
|
||||
s.obj[path.Join(base, tDir, m[10002].Chunk.Path())] = []byte("decoy")
|
||||
r := newReader(t, s)
|
||||
img, err := r.Open(context.Background(), rn)
|
||||
if err != nil {
|
||||
@@ -117,7 +123,7 @@ func TestRead_ForeignChunkFromSourcePool(t *testing.T) {
|
||||
if err != nil || c.Zero || !bytes.Equal(c.Data, []byte("src data")) || c.Ref.Owner != "src" {
|
||||
t.Fatalf("chunk 10002: %+v %v", c, err)
|
||||
}
|
||||
want := path.Join(base, "src", m[10002].Chunk.Path())
|
||||
want := path.Join(base, srcDir, m[10002].Chunk.Path())
|
||||
if got := s.asked[len(s.asked)-1]; got != want {
|
||||
t.Fatalf("read %s; want the source pool path %s", got, want)
|
||||
}
|
||||
@@ -129,7 +135,7 @@ func TestRead_MissingObjectIsAnErrorNeverZeros(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
t.Run("root", func(t *testing.T) {
|
||||
s, rn, _ := readFixture(t)
|
||||
delete(s.obj, path.Join(base, "t", rn.Path()))
|
||||
delete(s.obj, path.Join(base, tDir, rn.Path()))
|
||||
if _, err := newReader(t, s).Open(ctx, rn); !errors.Is(err, ErrMissing) {
|
||||
t.Fatalf("open of a missing root: %v; want ErrMissing", err)
|
||||
}
|
||||
@@ -140,7 +146,7 @@ func TestRead_MissingObjectIsAnErrorNeverZeros(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
delete(s.obj, path.Join(base, "t", img.root.Segments[1].Path()))
|
||||
delete(s.obj, path.Join(base, tDir, img.root.Segments[1].Path()))
|
||||
for _, idx := range []uint64{10002, 10003} { // named, and not named, in that shard
|
||||
c, err := img.Chunk(ctx, idx)
|
||||
if !errors.Is(err, ErrMissing) || c.Zero {
|
||||
@@ -150,7 +156,7 @@ func TestRead_MissingObjectIsAnErrorNeverZeros(t *testing.T) {
|
||||
})
|
||||
t.Run("own chunk", func(t *testing.T) {
|
||||
s, rn, m := readFixture(t)
|
||||
delete(s.obj, path.Join(base, "t", m[3].Chunk.Path()))
|
||||
delete(s.obj, path.Join(base, tDir, m[3].Chunk.Path()))
|
||||
img, err := newReader(t, s).Open(ctx, rn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -161,7 +167,7 @@ func TestRead_MissingObjectIsAnErrorNeverZeros(t *testing.T) {
|
||||
})
|
||||
t.Run("foreign chunk", func(t *testing.T) {
|
||||
s, rn, m := readFixture(t)
|
||||
delete(s.obj, path.Join(base, "src", m[10002].Chunk.Path()))
|
||||
delete(s.obj, path.Join(base, srcDir, m[10002].Chunk.Path()))
|
||||
img, err := newReader(t, s).Open(ctx, rn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -182,14 +188,14 @@ func TestRead_FetchFailureAndCorruption(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s.fail = path.Join(base, "t", m[3].Chunk.Path())
|
||||
s.fail = path.Join(base, tDir, m[3].Chunk.Path())
|
||||
if _, err := img.Chunk(ctx, 3); err == nil || errors.Is(err, ErrMissing) {
|
||||
t.Fatalf("failed fetch: %v; want an error that is not ErrMissing", err)
|
||||
}
|
||||
s.fail = ""
|
||||
for name, p := range map[string]string{
|
||||
"chunk": path.Join(base, "t", m[3].Chunk.Path()),
|
||||
"segment": path.Join(base, "t", img.root.Segments[0].Path()),
|
||||
"chunk": path.Join(base, tDir, m[3].Chunk.Path()),
|
||||
"segment": path.Join(base, tDir, img.root.Segments[0].Path()),
|
||||
} {
|
||||
s2, rn2, _ := readFixture(t)
|
||||
s2.obj[p] = append(append([]byte(nil), s2.obj[p]...), 'x')
|
||||
@@ -202,7 +208,7 @@ func TestRead_FetchFailureAndCorruption(t *testing.T) {
|
||||
}
|
||||
}
|
||||
s3, rn3, _ := readFixture(t)
|
||||
rp := path.Join(base, "t", rn3.Path())
|
||||
rp := path.Join(base, tDir, rn3.Path())
|
||||
s3.obj[rp] = append(append([]byte(nil), s3.obj[rp]...), 0)
|
||||
if _, err := newReader(t, s3).Open(ctx, rn3); !errors.Is(err, ErrCorrupt) {
|
||||
t.Errorf("root altered: %v; want ErrCorrupt", err)
|
||||
@@ -220,13 +226,13 @@ func TestRead_SegmentOfAnotherShardRefused(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
lie := SegName{Shard: 0, Hash: sn.Hash}
|
||||
s.obj[path.Join(base, "t", lie.Path())] = sb
|
||||
s.obj[path.Join(base, tDir, lie.Path())] = sb
|
||||
root := Root{Segments: map[uint64]SegName{0: lie}}
|
||||
rn, rb, err := NameRoot(root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s.obj[path.Join(base, "t", rn.Path())] = rb
|
||||
s.obj[path.Join(base, tDir, rn.Path())] = rb
|
||||
img, err := newReader(t, s).Open(ctx, rn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -247,13 +253,13 @@ func TestNewReader_RefusesBadInput(t *testing.T) {
|
||||
}
|
||||
|
||||
// putVolume writes vol's VOLUME record with its test id.
|
||||
func putVolume(t *testing.T, put func(vol, rel string, b []byte), vol string) {
|
||||
func putVolume(t *testing.T, put func(dir, rel string, b []byte), name, dir string) {
|
||||
t.Helper()
|
||||
b, err := Volume{ID: idFor(vol), Name: vol, Format: VolumeFormat}.Encode()
|
||||
b, err := Volume{ID: idFor(name), Name: name, Format: VolumeFormat}.Encode()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
put(vol, VolumeName, b)
|
||||
put(dir, VolumeName, b)
|
||||
}
|
||||
|
||||
// A foreign chunk is read only if its owner's VOLUME carries the id the
|
||||
@@ -267,7 +273,7 @@ func TestRead_ForeignChunkNeedsTheOwnersVolumeID(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s.obj[path.Join(base, "src", VolumeName)] = b
|
||||
s.obj[path.Join(base, srcDir, VolumeName)] = b
|
||||
img, err := newReader(t, s).Open(ctx, rn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -277,11 +283,11 @@ func TestRead_ForeignChunkNeedsTheOwnersVolumeID(t *testing.T) {
|
||||
t.Fatalf("chunk of a re-created source: %v; want ErrIdentity", err)
|
||||
}
|
||||
for _, p := range s.asked {
|
||||
if p == path.Join(base, "src", m[10002].Chunk.Path()) {
|
||||
if p == path.Join(base, srcDir, m[10002].Chunk.Path()) {
|
||||
t.Fatal("the chunk was fetched from a source whose id does not match")
|
||||
}
|
||||
}
|
||||
delete(s.obj, path.Join(base, "src", VolumeName))
|
||||
delete(s.obj, path.Join(base, srcDir, VolumeName))
|
||||
img, _ = newReader(t, s).Open(ctx, rn)
|
||||
if _, err := img.Chunk(ctx, 10002); !errors.Is(err, ErrMissing) {
|
||||
t.Fatalf("chunk of a source without VOLUME: %v; want ErrMissing", err)
|
||||
|
||||
@@ -56,8 +56,8 @@ func RemoveUnreachable(ctx context.Context, st HeadStore, r *Reader, os ObjectSt
|
||||
if !found {
|
||||
return nil, ErrHeadAbsent
|
||||
}
|
||||
if !h.heldBy(me) {
|
||||
return nil, fmt.Errorf("%w: HEAD epoch %d holder %q", ErrNotHolder, h.Epoch, h.Holder)
|
||||
if err := h.holderErr(me); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if h.Activity != (Activity{Kind: ActClean, Session: session}) {
|
||||
return nil, fmt.Errorf("%w: HEAD has %s(%s), not clean(%s)", ErrNoSession, h.Activity.Kind, h.Activity.Session, session)
|
||||
|
||||
@@ -103,6 +103,21 @@ func (v *memVolume) Create(_ context.Context, rel string, data []byte, session s
|
||||
})
|
||||
}
|
||||
|
||||
func (v *memVolume) DeleteOfVolume(_ context.Context, rel string, volume VolumeID) error {
|
||||
p := path.Join(volRoot, rel)
|
||||
return v.objWrite("delete-of-volume "+rel, func() error {
|
||||
if _, ok := v.objects[p]; !ok {
|
||||
return nil
|
||||
}
|
||||
if v.meta(p).Volume != volume {
|
||||
return ErrPrecondition
|
||||
}
|
||||
delete(v.objects, p)
|
||||
delete(v.metas, p)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (v *memVolume) Reuse(_ context.Context, rel string, expect ObjectMeta, session string) error {
|
||||
p := path.Join(volRoot, rel)
|
||||
return v.objWrite("reuse "+rel, func() error {
|
||||
|
||||
@@ -15,8 +15,8 @@ import (
|
||||
// Every pure transition refuses a caller that is not the holder at HEAD's
|
||||
// epoch: an older epoch of the same server, and the same epoch held by
|
||||
// another server, in idle, snap and clean. The table must name every
|
||||
// method of Head that returns (Head, bool, error), so a new transition
|
||||
// fails here until it is added.
|
||||
// method of Head that takes a HolderID and returns (Head, bool, error), so
|
||||
// a new holder transition fails here until it is added.
|
||||
func TestTransitions_RefuseAStaleHolder(t *testing.T) {
|
||||
rn := RootName{Hash: Sum([]byte("r"))}
|
||||
steps := map[string]func(Head, HolderID) error{
|
||||
@@ -46,7 +46,8 @@ func TestTransitions_RefuseAStaleHolder(t *testing.T) {
|
||||
var missing []string
|
||||
for i := 0; i < headT.NumMethod(); i++ {
|
||||
m := headT.Method(i).Type
|
||||
if m.NumOut() == 3 && m.Out(0) == headT && m.Out(1) == boolT && m.Out(2) == errT {
|
||||
holderT := reflect.TypeOf(HolderID{})
|
||||
if m.NumOut() == 3 && m.Out(0) == headT && m.Out(1) == boolT && m.Out(2) == errT && m.NumIn() > 1 && m.In(1) == holderT {
|
||||
if _, ok := steps[headT.Method(i).Name]; !ok {
|
||||
missing = append(missing, headT.Method(i).Name)
|
||||
}
|
||||
|
||||
@@ -12,6 +12,10 @@ import (
|
||||
// identity: written once, never changed.
|
||||
const VolumeName = "VOLUME"
|
||||
|
||||
// HeadName is the entry, under the volume root, that holds the volume's
|
||||
// HEAD; it is never removed (a deleted volume keeps its deleted HEAD).
|
||||
const HeadName = "HEAD"
|
||||
|
||||
// VolumeID is a volume's identity: random, chosen when the volume is
|
||||
// created. A volume's name is a path and can be created again after a
|
||||
// delete; its id cannot, so a volume created again satisfies no reference
|
||||
@@ -47,6 +51,14 @@ func ParseVolumeID(s string) (VolumeID, error) {
|
||||
return id, nil
|
||||
}
|
||||
|
||||
// VolumeDir is the directory of a volume under the store's base:
|
||||
// <name>-<first 8 hex of the volume id>. It is created exclusively and
|
||||
// never reused, so a volume created again under a name gets another
|
||||
// directory; it is resolved only from the master's volume record.
|
||||
func VolumeDir(name string, id VolumeID) string {
|
||||
return name + "-" + id.String()[:8]
|
||||
}
|
||||
|
||||
// VolumeFormat is the layout format a VOLUME record declares.
|
||||
const VolumeFormat = 1
|
||||
|
||||
|
||||
@@ -517,7 +517,7 @@ Tests: `TestSnapshotSchedule_SlotsAreOffsetPerVolume`, `_FailureIsTypedAndBacksO
|
||||
|
||||
### M9 Snapshot kernel: HEAD transactions over the content-named layout
|
||||
|
||||
A library, `core/frontend/chunkstore/layout`, with no production caller yet. A volume's HEAD holds its epoch and holder, one activity (`idle`, `snap(s)` or `clean(c)`), the current root and position, and the named snapshots with their dependents. Every transition is one conditional update of HEAD through `runTransition`; no transition creates a HEAD, and an absent HEAD is refused. Objects (chunks, segments, roots) are written first under content names; the commit is the only step that makes them reachable.
|
||||
A library, `core/frontend/chunkstore/layout`, with no production caller yet. A volume's HEAD holds its epoch and holder, one activity (`idle`, `snap(s)` or `clean(c)`), the current root and position, and the named snapshots with their dependents. Every transition is one conditional update of HEAD through `runTransition`; no transition creates a HEAD, and an absent HEAD is refused. One exception: the remove-dependent command of the operator writes a deleted HEAD exclusively for a restore target without HEAD (a tombstone), before releasing it from the source. Objects (chunks, segments, roots) are written first under content names; the commit is the only step that makes them reachable.
|
||||
|
||||
```mermaid
|
||||
stateDiagram-v2
|
||||
@@ -531,6 +531,10 @@ stateDiagram-v2
|
||||
idle --> clean: BeginClean(c)
|
||||
clean --> idle: EndClean(c)
|
||||
clean --> clean: RemoveUnreachable(shard)
|
||||
idle --> deleting: MarkDeleting (reserved, no live lease, no dependents)
|
||||
deleting --> deleted: MarkDeleted (after release and pool)
|
||||
[*] --> deleted: tombstone (operator, target without HEAD; exclusive create)
|
||||
idle --> idle: ReleaseDependent(target) on a source
|
||||
```
|
||||
|
||||
| From | To | Guard | Enforced in | Protects |
|
||||
@@ -542,10 +546,14 @@ stateDiagram-v2
|
||||
| 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 | the master reserved the volume for delete (no line granted after), then no line holds a live lease, checked between the HEAD read and the update; no open activity, no snapshot with dependents; deleting again is a replay | delete.go `Head.MarkDeleting`, `RunMarkDeleting` (`DeleteAuthority`) | `INV-SNAPK-DELETE-ORDER-001` |
|
||||
| absent | deleted (tombstone) | the operator's remove-dependent, for a restore target without HEAD (never created, or a restore died between its two creates); one exclusive create, so a later HEAD create of the restore fails; a HEAD appearing first refuses | delete.go `OperatorReleaseDependent` (`TargetStore.CreateDeletedHead`) | `INV-SNAPK-TOMBSTONE-001`, `INV-SNAPK-HEAD-WRITE-001` |
|
||||
| source: any live | source: target released | by the target's volume id, from every snapshot: from DeleteVolume once the target's HEAD is deleting, or from the operator's command once the target is deleted, of another id, no longer naming the source, or tombstoned; an absent target writes nothing | delete.go `Head.ReleaseDependent`, `RunReleaseDependent`, `OperatorReleaseDependent` | `INV-SNAPK-RELEASE-001`, `INV-SNAPK-RELEASE-CALLERS-001`, `INV-SNAPK-RELEASE-OPERATOR-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
|
||||
|
||||
350 rows: 279 ACTIVE, 67 STUB, 4 ARCHIVED; 15 kept from the internal ledger, 335 new.
|
||||
361 rows: 290 ACTIVE, 67 STUB, 4 ARCHIVED; 15 kept from the internal ledger, 346 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.
|
||||
|
||||
@@ -1086,8 +1094,8 @@ Notes:
|
||||
| ID | Statement | Machine / transition | Enforced in | Test | TLA+ property | Status |
|
||||
|---|---|---|---|---|---|---|
|
||||
| `INV-SNAPK-NAME-CANONICAL-001` | A chunk is named by its index and the SHA-256 of its bytes under `pool/<index/10000>/`; a segment and a root are named by the SHA-256 of their canonical encoding, and decoding refuses any bytes the encoder would not write, so an object has one encoding and one name. | Content-named layout (no state transition) | `core/frontend/chunkstore/layout` `layout.go` `ParseChunkName`, `DecodeSegment`, `DecodeRoot` | `TestParseChunkName_RoundTripAndRefusals`, `TestDecodeSegment_RefusesNonCanonical`, `TestRoot_Refusals`, `TestBuild_ShardsAndIncrementalReuse` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-HEAD-WRITE-001` | HEAD changes only by one conditional update on its generation through `runTransition`; no path in the package creates a HEAD, and an absent HEAD is refused. | M9 every transition | `core/frontend/chunkstore/layout` `head.go` `runTransition`; `HeadStore` (read and conditional update only) | `TestGuard_WritersTransitionsAndRemovers`, `TestRunBegin` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-HEAD-GUARD-001` | A source scan refuses any other use of `UpdateHead`, a transition without its closure and interrupt tests, and any store remover other than the mark-gated RemoveUnreachable. | M9 every transition | `core/frontend/chunkstore/layout` (source scan of the package) | `TestGuard_WritersTransitionsAndRemovers`, `TestGuard_Controls` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-HEAD-WRITE-001` | HEAD changes only by one conditional update on its generation through `runTransition`; an absent HEAD is refused; the one HEAD the package creates is the exclusive deleted HEAD the operator writes (tombstone) for a restore target without HEAD. | M9 every transition | `core/frontend/chunkstore/layout` `head.go` `runTransition`; `HeadStore` (read and conditional update only) | `TestGuard_WritersTransitionsAndRemovers`, `TestRunBegin` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-HEAD-GUARD-001` | A source scan refuses any other use of `UpdateHead`, a transition without its closure and interrupt tests, and any store remover other than the mark-gated RemoveUnreachable and the ordered DeleteVolume. | M9 every transition | `core/frontend/chunkstore/layout` (source scan of the package) | `TestGuard_WritersTransitionsAndRemovers`, `TestGuard_Controls` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-HEAD-CODEC-001` | HEAD is canonical JSON with at most 100 snapshots and sorted unique dependents; unknown fields, non-canonical bytes and names that are not valid UTF-8 are refused at encode and decode, and the next HEAD is checked before it is written. | M9 every transition | `core/frontend/chunkstore/layout` `head.go` `Head.check`, `Head.Encode`, `DecodeHead` | `TestHead_GoldenEncodingRoundTrip`, `TestHead_Refusals`, `TestHead_RefusesInvalidUTF8` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-BEGIN-001` | Begin opens snap(s) only for the holder at HEAD's epoch and only from idle; a re-run of the open session writes nothing; killed at its write and re-run, it ends in snap(s) at one generation step. | M9 idle → snap | `core/frontend/chunkstore/layout` `head.go` `Head.Begin`, `RunBegin` | `TestBegin_Closure`, `TestRunBegin_InterruptAtEveryStep` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-ABORT-001` | Abort closes the holder's own snap(s) and changes nothing else; after its own crash a holder rolls the open session back before beginning another; over idle Abort writes nothing and its success never says whether the work was committed. | M9 snap → idle (Abort) | `core/frontend/chunkstore/layout` `head.go` `Head.Abort`, `RunAbort` | `TestAbort_Closure`, `TestAbort_IdleMeansNoActivityRemains`, `TestAbort_RollBackAfterOwnCrash`, `TestRunAbort_InterruptAtEveryStep` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
@@ -1106,6 +1114,17 @@ Notes:
|
||||
| `INV-SNAPK-REF-ID-001` | Every chunk reference in a segment carries its owner's volume id; a read checks it against the owner's VOLUME before fetching (another id is ErrIdentity), and the remover tells its own chunks by its VOLUME id. | Content-named layout | `core/frontend/chunkstore/layout` `layout.go` `Segment.Encode`; `read.go` `Image.Chunk`; `remove.go` | `TestSegment_EncodeRefusals`, `TestRead_ForeignChunkNeedsTheOwnersVolumeID`, `TestRemoveUnreachable_NeedsItsOwnVolumeID` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-DEP-ID-001` | Every dependent records the target's volume id and the root of the snapshot it depends on; a dependent without the id, or of another root, is refused. | M9 snapshots and dependents | `core/frontend/chunkstore/layout` `head.go` `Head.check` | `TestHead_Refusals`, `TestHead_GoldenEncodingRoundTrip` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-CLAIM-ID-001` | A holder is its epoch, its server and the claim id its claim wrote into HEAD; every transition refuses the same server at the same epoch with another claim id. | M9 every transition | `core/frontend/chunkstore/layout` `head.go` `heldBy`; `claim.go` `Head.Claim` | `TestClaim_WritesItsClaimID`, `TestTransitions_RefuseAStaleHolder`, `TestHolderFunctions_RefuseAStaleHolder` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-DELETE-ORDER-001` | A volume delete runs in its order, each prefix safe and the whole re-runnable: HEAD deleting, this volume released from every source, its objects deleted, HEAD deleted. | M9 idle → deleting → deleted | `core/frontend/chunkstore/layout` `delete.go` `DeleteVolume` | `TestDeleteVolume`, `TestDeleteVolume_InterruptAtEveryStep`, `TestRunMarkDeleting_InterruptAtEveryStep`, `TestRunMarkDeleted_InterruptAtEveryStep` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-DELETE-OWNED-001` | Every object entry carries the id of its volume; a volume delete removes an object only if it carries that id, so a late delete of a finished run never removes the object of a volume created again under the name. | M9 deleting → deleted | `core/frontend/chunkstore/layout` `delete.go` `DeleteVolume`; `objects.go` `ObjectStore.DeleteOfVolume` | `TestDeleteVolume_ALateDeleteSparesTheNameReused`, `TestDeleteVolume` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-DELETE-GATE-001` | HEAD becomes deleting only after the master reserved the volume (no grant after) and saw no live lease between the HEAD read and the update, with no open activity and no snapshot with dependents; then no holder transition, claim or removal applies. | M9 idle → deleting | `core/frontend/chunkstore/layout` `delete.go` `Head.MarkDeleting`; `head.go` `holderErr` | `TestMarkDeleting_Closure`, `TestMarkDeleted_Closure`, `TestDeleting_RefusesEveryHolderStep`, `TestDeleteVolume`, `TestDeleteVolume_AGrantRaceNeverDeletesALiveVolume` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-DELETE-GUARD-001` | A source scan requires DeleteVolume to run reservation, deleting (whose transition checks live leases), release, object deletes and deleted in that order, and allows it as the only remover besides RemoveUnreachable. | M9 idle → deleting → deleted | `core/frontend/chunkstore/layout` (source scan of `delete.go`) | `TestGuard_WritersTransitionsAndRemovers`, `TestGuard_Controls` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-VOLUME-DIR-001` | A volume lives in the directory <name>-<first 8 hex of its volume id>, created exclusively and never reused; a foreign chunk is read from the directory its reference's owner name and id give, after that directory's VOLUME id is checked. | Content-named layout | `core/frontend/chunkstore/layout` `volume.go` `VolumeDir`; `read.go` `Image.Chunk` | `TestRead_ForeignChunkFromSourcePool`, `TestRead_ForeignChunkNeedsTheOwnersVolumeID` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-TOMBSTONE-001` | For a restore target without HEAD (never created, or a restore died between its two creates) the operator writes a deleted HEAD exclusively in its directory before releasing, so the restore cannot create it later. | M9 source HEAD, dependents | `core/frontend/chunkstore/layout` `delete.go` `OperatorReleaseDependent`, `TargetStore.CreateDeletedHead` | `TestOperatorReleaseDependent`, `TestOperatorReleaseDependent_TombstoneLosesToTheRestore`, `TestGuard_Controls` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-KEEP-HEAD-001` | Nothing removes a HEAD, a VOLUME or a volume directory: a volume delete removes only pool, segment and root objects; a source scan lists every delete and every directory-naming site in core/ and cmd/. | M9 deleting → deleted | `core/frontend/chunkstore/layout` `delete.go` `DeleteVolume`; (source scan) | `TestDeleteVolume_RemovesOnlyObjects`, `TestDeleteAndDirectorySites_Enumeration` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-RELEASE-001` | A target is released from a source's dependents by its volume id, from every snapshot, in one conditional update; a volume created again under its name releases nothing; an absent target writes nothing. | M9 source HEAD, dependents | `core/frontend/chunkstore/layout` `delete.go` `Head.ReleaseDependent`, `RunReleaseDependent` | `TestReleaseDependent_Closure`, `TestRunReleaseDependent_InterruptAtEveryStep` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-RELEASE-CALLERS-001` | Only the target's own delete (its HEAD already deleting) and the operator's command release a dependent; a source scan restricts the callers and requires the operator's read of the target. | M9 source HEAD, dependents | `core/frontend/chunkstore/layout` (source scan of `delete.go`) | `TestGuard_Controls` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-RELEASE-OPERATOR-001` | The operator's command releases a target that is deleted (HEAD deleting or deleted, or its directory's VOLUME of another id), one whose live roots name no chunk of the source, or one without HEAD, after its tombstone. | M9 source HEAD, dependents | `core/frontend/chunkstore/layout` `delete.go` `OperatorReleaseDependent` | `TestOperatorReleaseDependent` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-RELEASE-REFUSE-001` | The operator's command refuses a live target still naming the source and one whose HEAD appeared before its tombstone, and then writes nothing to the source. | M9 source HEAD, dependents | `core/frontend/chunkstore/layout` `delete.go` `OperatorReleaseDependent` | `TestOperatorReleaseDependent` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
| `INV-SNAPK-STALE-HOLDER-001` | Every transition refuses an older epoch of the same server, the same epoch held by another server, and the same epoch and server with another claim id, in idle, snap and clean; a new transition must be added to the table. | M9 every transition | `core/frontend/chunkstore/layout` `Head.heldBy` and each transition | `TestTransitions_RefuseAStaleHolder` | — (the snapshot kernel model is not in this repository) | ACTIVE |
|
||||
|
||||
Notes:
|
||||
|
||||
Reference in new issue
Block a user