Let a bundle purge a deleted object's leftovers through the runtime
The runtime's objects act purge removes a deleted object's chunks: busstate.Objects.Purge and TypeScript purgeObject, so the registry's program opens no connection of its own for it. Builds: design 47 H2 §812; H-A-366
This commit is contained in:
@@ -26,8 +26,11 @@ const (
|
||||
ObjectsGet = "mesh/objects.get"
|
||||
ObjectsList = "mesh/objects.list"
|
||||
ObjectsDelete = "mesh/objects.delete"
|
||||
ObjectsInfo = "mesh/objects.info"
|
||||
ObjectsWatch = "mesh/objects.watch"
|
||||
// ObjectsPurge removes what a deleted object leaves behind, its chunks, from the store (H-A-366): asked with an
|
||||
// ObjectsNameRequest, answered Done.
|
||||
ObjectsPurge = "mesh/objects.purge"
|
||||
ObjectsInfo = "mesh/objects.info"
|
||||
ObjectsWatch = "mesh/objects.watch"
|
||||
// ObjectsSentGet reads an object of a sender's store of sent objects by the reference a reply or an event carried
|
||||
// (design 47 G §347, §407), served under the standing grant the grants part derives from the manifests; the answer is
|
||||
// ObjectData.
|
||||
|
||||
@@ -78,6 +78,13 @@ func (o Objects) Delete(name string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Purge removes what the deleted object name left behind in the store, its chunks, through the runtime (H-A-366): a
|
||||
// bundle never opens a connection of its own for it.
|
||||
func (o Objects) Purge(name string) error {
|
||||
_, err := call[buscalls.Done](buscalls.ObjectsPurge, buscalls.ObjectsNameRequest{Objects: o.local, Name: name})
|
||||
return err
|
||||
}
|
||||
|
||||
// Fill is how much the store holds against its cap.
|
||||
func (o Objects) Fill() (buscalls.Fill, error) {
|
||||
return call[buscalls.Fill](buscalls.ObjectsInfo, buscalls.ObjectsRequest{Objects: o.local})
|
||||
|
||||
@@ -35,6 +35,7 @@ func subABundleKeepsObjectsThroughTheRuntime(t *testing.T) {
|
||||
list, err := in.List()
|
||||
results <- result{"list", err, len(list)}
|
||||
results <- result{"delete", in.Delete("t1.part0"), nil}
|
||||
results <- result{"purge", in.Purge("t1.part0"), nil} // H-A-366
|
||||
fill, err := in.Fill()
|
||||
results <- result{"fill", err, fill.MaxBytes}
|
||||
_, err = stdio.BusState("mesh/state.get", nil)
|
||||
@@ -68,6 +69,7 @@ func subABundleKeepsObjectsThroughTheRuntime(t *testing.T) {
|
||||
buscalls.ObjectsGet: buscalls.ObjectData{Info: buscalls.ObjectInfo{Name: "t1.part0"}, Data: []byte("hello")},
|
||||
buscalls.ObjectsList: buscalls.ObjectsListed{Objects: []buscalls.ObjectInfo{{Name: "t1.part0"}}},
|
||||
buscalls.ObjectsDelete: buscalls.Done{},
|
||||
buscalls.ObjectsPurge: buscalls.Done{},
|
||||
buscalls.ObjectsInfo: buscalls.Fill{Count: 0, MaxBytes: 20 << 30},
|
||||
}
|
||||
asked := map[string]map[string]any{}
|
||||
@@ -81,8 +83,8 @@ func subABundleKeepsObjectsThroughTheRuntime(t *testing.T) {
|
||||
asked[method] = p
|
||||
send(map[string]any{"jsonrpc": "2.0", "id": m["id"], "result": answers[method]})
|
||||
}
|
||||
want := map[string]any{"put": "SHA-256=x", "get": "hello", "list": 1, "delete": nil, "fill": uint64(20 << 30)}
|
||||
for range 5 {
|
||||
want := map[string]any{"put": "SHA-256=x", "get": "hello", "list": 1, "delete": nil, "purge": nil, "fill": uint64(20 << 30)}
|
||||
for range 6 {
|
||||
r := <-results
|
||||
if r.err != nil || r.got != want[r.what] {
|
||||
t.Errorf("%s answered %v, %v; want %v", r.what, r.got, r.err, want[r.what])
|
||||
@@ -96,6 +98,9 @@ func subABundleKeepsObjectsThroughTheRuntime(t *testing.T) {
|
||||
t.Errorf("%s named the store %v, not its local name", method, p["objects"])
|
||||
}
|
||||
}
|
||||
if p := asked[buscalls.ObjectsPurge]; p["name"] != "t1.part0" {
|
||||
t.Errorf("purge asked %v", p)
|
||||
}
|
||||
if p := asked[buscalls.ObjectsPut]; p["name"] != "t1.part0" || p["data"] != "aGVsbG8=" || p["description"] != "a part" {
|
||||
t.Errorf("put asked %v", p)
|
||||
}
|
||||
|
||||
@@ -168,6 +168,15 @@ export async function takeOnce(seat: string, ask: string, boundMs: number, state
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove what the deleted object `name` left behind in the object store `objects` (by its local name), its chunks,
|
||||
* through the runtime's `mesh/objects.purge` (H-A-366): the Go side's `busstate.Objects.Purge`. A bundle never opens a
|
||||
* connection of its own for it.
|
||||
*/
|
||||
export async function purgeObject(objects: string, name: string): Promise<void> {
|
||||
await boundChannel().ask("mesh/objects.purge", { objects, name });
|
||||
}
|
||||
|
||||
/** A state this module keeps (by its local name) or reads (`<module>.<name>`). */
|
||||
export function state<T = unknown>(name: string): State<T> {
|
||||
const bound = (): StateChannel => {
|
||||
|
||||
@@ -1052,4 +1052,9 @@ async function newTest6(): Promise<void> {
|
||||
assert.equal(await takeOnce("git", "a-7", 600_000), false);
|
||||
assert.deepEqual(asked[0], ["mesh/state.create", { state: "taken", key: "git.a-7", value: { seat: "git", ask: "a-7" }, ttl_seconds: 600 }]);
|
||||
await assert.rejects(takeOnce("git", "", 1000), /is not an ask id/);
|
||||
// H-A-366: a bundle purges a deleted object's leftovers through the runtime
|
||||
const { purgeObject } = await import("../dist/state/index.js");
|
||||
asked.length = 0;
|
||||
await purgeObject("artifacts", "pkg-1.tgz");
|
||||
assert.deepEqual(asked[0], ["mesh/objects.purge", { objects: "artifacts", name: "pkg-1.tgz" }]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user