RG3: the registry purges a deleted chunk's leftovers
Every delete of a chunk in the incoming object store is followed by the runtime's purge of what it left (busstate.Objects.Purge), so the store's kept descriptions equal its live objects; a failed purge is said. Builds: design 47 H2 §813 (8); H-A-227, H-A-366
This commit is contained in:
@@ -46,8 +46,13 @@ func stepErr(bound time.Duration, what string, f func() error) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// boundedObjects is the incoming object store with each operation bounded and logged.
|
||||
type boundedObjects struct{ parts.Objects }
|
||||
// boundedObjects is the incoming object store with each operation bounded and logged. Purge is the store's purge of a
|
||||
// deleted object's chunks (busstate.Objects.Purge): every delete of a chunk is followed by it, so what a delete left
|
||||
// behind is dropped and the store's kept descriptions equal its live objects (design 47 H2 §813 (8); H-A-227, H-A-366).
|
||||
type boundedObjects struct {
|
||||
parts.Objects
|
||||
Purge func(name string) error
|
||||
}
|
||||
|
||||
func (b boundedObjects) Used() (uint64, error) {
|
||||
return step(stepBound, "the incoming object store's fill (objects)", b.Objects.Used)
|
||||
@@ -59,7 +64,15 @@ func (b boundedObjects) Get(name string) ([]byte, error) {
|
||||
return step(stepBound, "the get of a chunk from the incoming object store (objects)", func() ([]byte, error) { return b.Objects.Get(name) })
|
||||
}
|
||||
func (b boundedObjects) Delete(name string) error {
|
||||
return stepErr(stepBound, "the delete of a chunk in the incoming object store (objects)", func() error { return b.Objects.Delete(name) })
|
||||
err := stepErr(stepBound, "the delete of a chunk in the incoming object store (objects)", func() error { return b.Objects.Delete(name) })
|
||||
if b.Purge == nil {
|
||||
return err
|
||||
}
|
||||
perr := stepErr(stepBound, "the purge of a deleted chunk's leftovers in the incoming object store (objects)", func() error { return b.Purge(name) })
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return perr
|
||||
}
|
||||
|
||||
// boundedTransfers is the transfers state with its reads and writes bounded and logged.
|
||||
|
||||
@@ -8,8 +8,15 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// The incoming store's steps (design 47 H2 §819: one test function for the bounded steps).
|
||||
func TestTheBoundedSteps(t *testing.T) {
|
||||
t.Run("a hung step answers with its name", hungStepAnswersWithItsName)
|
||||
t.Run("a given-up step says when its call ended", givenUpStepSaysWhenItsCallEnded)
|
||||
t.Run("a deleted chunk is purged", deletedChunkIsPurged)
|
||||
}
|
||||
|
||||
// A bus operation that never answers becomes an error naming its step, within the bound.
|
||||
func TestAHungStepAnswersWithItsName(t *testing.T) {
|
||||
func hungStepAnswersWithItsName(t *testing.T) {
|
||||
block := make(chan struct{})
|
||||
defer close(block)
|
||||
_, err := step(10*time.Millisecond, "the write of the idle key", func() (int, error) { <-block; return 0, nil })
|
||||
@@ -22,7 +29,7 @@ func TestAHungStepAnswersWithItsName(t *testing.T) {
|
||||
}
|
||||
|
||||
// A step given up on is said given up by name, and the log says later when the call behind it ended and how (A-443a).
|
||||
func TestAGivenUpStepSaysWhenItsCallEnded(t *testing.T) {
|
||||
func givenUpStepSaysWhenItsCallEnded(t *testing.T) {
|
||||
var mu sync.Mutex
|
||||
var lines []string
|
||||
ended := make(chan struct{})
|
||||
@@ -68,3 +75,31 @@ func TestAFindingIsSaidOffThePath(t *testing.T) {
|
||||
t.Fatal("the call was held by the finding")
|
||||
}
|
||||
}
|
||||
|
||||
// fakeObjects is an object store that counts deletes.
|
||||
type fakeObjects struct{ deleted []string }
|
||||
|
||||
func (f *fakeObjects) Put(string, []byte) error { return nil }
|
||||
func (f *fakeObjects) Get(string) ([]byte, error) { return nil, nil }
|
||||
func (f *fakeObjects) Delete(name string) error { f.deleted = append(f.deleted, name); return nil }
|
||||
func (f *fakeObjects) Used() (uint64, error) { return 0, nil }
|
||||
|
||||
// Every delete of a chunk purges what it left behind, so the store's kept descriptions equal its live objects (design 47
|
||||
// H2 §813 (8)); a purge's failure is said, never swallowed.
|
||||
func deletedChunkIsPurged(t *testing.T) {
|
||||
f := &fakeObjects{}
|
||||
var purged []string
|
||||
b := boundedObjects{f, func(name string) error { purged = append(purged, name); return nil }}
|
||||
for i := range 1000 {
|
||||
if err := b.Delete(fmt.Sprintf("chunk.%d", i)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if len(f.deleted) != 1000 || len(purged) != 1000 || purged[999] != "chunk.999" {
|
||||
t.Fatalf("deleted %d, purged %d", len(f.deleted), len(purged))
|
||||
}
|
||||
b.Purge = func(string) error { return fmt.Errorf("no responders") }
|
||||
if err := b.Delete("chunk.x"); err == nil || !strings.Contains(err.Error(), "no responders") {
|
||||
t.Fatalf("a failed purge answered %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
reg "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/containerimageregistry"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/parts"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/busstate"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
|
||||
@@ -488,7 +489,7 @@ func main() {
|
||||
}()
|
||||
base, _ := url.Parse("http://127.0.0.1:5001")
|
||||
store := &holder.OCI{Base: base, Upstream: &holder.Upstream{}}
|
||||
h := &holder.Holder{Logf: logf, Objects: boundedObjects{parts.BusObjects(holder.IncomingObjects)}, Builder: holder.Reserved{Ask: stdio.Ask}, Store: store, Say: say, Finding: boundedFinding(findings.Say),
|
||||
h := &holder.Holder{Logf: logf, Objects: boundedObjects{parts.BusObjects(holder.IncomingObjects), busstate.ObjectsOf(holder.IncomingObjects).Purge}, Builder: holder.Reserved{Ask: stdio.Ask}, Store: store, Say: say, Finding: boundedFinding(findings.Say),
|
||||
Transfers: boundedTransfers{parts.BusTransfers[holder.Opening](holder.TransfersState)}, Cap: boundedCap(parts.BusCap(holder.IncomingObjects)), Record: recordAct, Idle: boundedArm(parts.BusArm(holder.IdleState))}
|
||||
files := &holder.Files{Container: or(os.Getenv("MESH_REGISTRY_CONTAINER"), "mesh-registry"), Run: holder.ExecRunner, UID: os.Getuid()}
|
||||
v := &holder.Verbs{Holder: h, Catalog: store, Holds: kept[holder.Hold]{state: "holds", key: holder.Hold.Key}, Mirrors: mirrors{},
|
||||
|
||||
Reference in New Issue
Block a user