I8 pin-drop-record: indexer_pin_drop with record drops that one record from every pin holding it, the pins' other records staying

Builds: design 47 H2 H-A-572 (3)
This commit is contained in:
2026-11-25 17:37:22 +01:00
parent f1f2d352e5
commit 5922da0a92
5 changed files with 87 additions and 4 deletions
@@ -20,6 +20,7 @@ type takerIn interface {
DropCandidateGraph(ctx context.Context, group, heads, by, why string) index.TakenIn
NamedDrop(ctx context.Context, fingerprint, member, by, why string) index.TakenIn
PinDrop(ctx context.Context, key, by, why string) index.TakenIn
PinDropRecord(ctx context.Context, record, by, why string) index.TakenIn
DropRunByHand(ctx context.Context, run, by, why string) index.TakenIn
RegistryAct(ctx context.Context, a index.TakeInAsk) index.TakenIn
// HeldAgain and HeldSkip act on a watched branch's held source-moved (design 47 H §744).
@@ -70,6 +71,9 @@ func takenIn(ctx context.Context, ix takerIn, kv jetstream.KeyValue, e jetstream
} else if a.NamedFingerprint != "" && a.Drop {
asked, r = "drop of a member of a fingerprint's names", ix.NamedDrop(ctx, a.NamedFingerprint, a.NamedMember, a.By, a.Why)
a.Module = r.Module
} else if a.PinDropRecord != "" {
asked, r = "drop of a record from the pins of the catalog graph revisions", ix.PinDropRecord(ctx, a.PinDropRecord, a.By, a.Why)
a.Module = r.Module
} else if a.PinDrop != "" {
asked, r = "drop of a pin of the catalog graph revisions", ix.PinDrop(ctx, a.PinDrop, a.By, a.Why)
a.Module = r.Module
@@ -39,6 +39,9 @@ func (s *askedBy) NamedDrop(context.Context, string, string, string, string) ind
func (s *askedBy) PinDrop(context.Context, string, string, string) index.TakenIn {
return s.did("pin-drop")
}
func (s *askedBy) PinDropRecord(context.Context, string, string, string) index.TakenIn {
return s.did("pin-drop-record")
}
func (s *askedBy) DropRunByHand(context.Context, string, string, string) index.TakenIn {
return s.did("run-drop")
}
@@ -799,6 +799,48 @@ func (ix *Indexer) PinDrop(ctx context.Context, key, by, why string) TakenIn {
return r
}
// PinDropRecord drops one record, by its name, from every pin of the state pins that holds it, leaving each pin's other records
// (indexer_pin_drop with record, design 47 H2 H-A-572 (3)); the removal rule then applies.
func (ix *Indexer) PinDropRecord(ctx context.Context, record, by, why string) TakenIn {
r := TakenIn{Module: "pins record " + record}
if ix.Pins == nil {
r.Answer = "the indexer keeps no state " + PinsState + ": nothing dropped"
return r
}
pinKeys, err := ix.Pins.Keys(ctx)
if err != nil {
r.Answer = "the state " + PinsState + " cannot be read: " + err.Error()
return r
}
slices.Sort(pinKeys)
dropped := 0
for _, k := range pinKeys {
if _, _, ok := ParsePinKey(k); !ok {
continue
}
v, _, found, err := ix.Pins.Get(ctx, k)
if err != nil {
r.Answer = "the pin " + k + " cannot be read, so the drop stops there: " + err.Error()
return r
}
var pv PinValue
if !found || json.Unmarshal(v, &pv) != nil || !slices.Contains(pv.Records, record) {
continue
}
if err := ix.unpin(ctx, k, record); err != nil {
r.Answer = "the record " + record + " could not be dropped from " + k + ": " + err.Error()
ix.logf("%s", r.Answer)
return r
}
dropped++
}
r.Stored = dropped > 0
r.Answer = fmt.Sprintf("the record %s is dropped from %d pins by %s (%s)", record, dropped, by, why)
ix.logf("%s", r.Answer)
ix.JudgePins(ctx)
return r
}
// PinnedRevision is one revision of the state pins as indexer_pins lists it.
type PinnedRevision struct {
Revision string `json:"revision"`
@@ -881,14 +923,34 @@ func PinsTools(pins Store, o Objects, ask func(key string, value []byte) (TakeIn
"running pipeline (design 47 H §765); the removal rule then applies (a revision no record pins and not current goes). A hand " +
"act, recorded through mesh-hand-acts before it is asked. Clears the finding pin-missing of the key. indexer_pins names the keys. " +
"With all true and no key, every pin of the state goes, each recorded and asked as one: the clean state's tool, run while no " +
"pipeline runs (design 47 H-A-121, H-A-124); it answers the count dropped and the pipelines they named.",
"pipeline runs (design 47 H-A-121, H-A-124); it answers the count dropped and the pipelines they named. With record " +
"and no key, that one record (`failed.<branch>.<module>`, as indexer_pins names it) is dropped from every pin that holds it " +
"and the pins' other records stay (design 47 H2 H-A-572 (3)).",
Input: map[string]any{"type": "object", "required": []string{"why"}, "properties": map[string]any{
"key": map[string]any{"type": "string", "description": "the pin's key `<branch>.<revision>`, as indexer_pins names it"},
"all": map[string]any{"type": "boolean", "description": "true drops every pin of the state pins, naming no key"},
"why": map[string]any{"type": "string", "description": "why it is dropped, in plain words"}}},
"key": map[string]any{"type": "string", "description": "the pin's key `<branch>.<revision>`, as indexer_pins names it"},
"all": map[string]any{"type": "boolean", "description": "true drops every pin of the state pins, naming no key"},
"record": map[string]any{"type": "string", "description": "one record, as indexer_pins names it, dropped from every pin that holds it; the pins' other records stay"},
"why": map[string]any{"type": "string", "description": "why it is dropped, in plain words"}}},
Run: func(args map[string]any) (any, error) {
str := func(k string) string { s, _ := args[k].(string); return strings.TrimSpace(s) }
key, why := str("key"), str("why")
if rec := str("record"); rec != "" {
if key != "" || str("all") == "true" || why == "" {
return nil, errors.New("name a record (record) with no key and no all, and say why (why): a drop is a hand act, recorded through mesh-hand-acts")
}
data, err := json.Marshal(TakeInAsk{V: 1, PinDropRecord: rec, Why: why, By: stdio.CallerOf(args), At: now().UTC()})
if err != nil {
return nil, err
}
if err := record("dropped the record "+rec+" from the pins of the catalog graph revisions by hand", why); err != nil {
return nil, fmt.Errorf("the hand act was not recorded through mesh-hand-acts, so nothing was dropped: %w", err)
}
a, err := ask("pin-drop-record."+keys.EscapeName(rec), data)
if err != nil {
return nil, err
}
return a.Result, nil
}
if all, _ := args["all"].(bool); all || str("all") == "true" {
if key != "" {
return nil, errors.New("the all form drops every pin: name no key with it")
@@ -177,6 +177,17 @@ func TestTheIndexerRemovesARevisionOnlyWhenNoRecordPinsItAndItIsNotCurrent(t *te
if f := ix.Findings.Held(); len(f) != 1 || f[0].Kind != PinMissingKind {
t.Fatalf("findings %v, want one %s", f, PinMissingKind)
}
// H-A-572 (3): a record dropped by name leaves its pin's other records.
if err := ix.pin(ctx, "main.3", FailedRecord("main", "x")); err != nil {
t.Fatal(err)
}
before, _, _, _ := ix.Pins.Get(ctx, "main.3")
if r := ix.PinDropRecord(ctx, FailedRecord("main", "x"), "operator", "a hand act"); !r.Stored {
t.Fatalf("the record drop answered %q", r.Answer)
}
if v, _, _, _ := ix.Pins.Get(ctx, "main.3"); len(mustRecords(t, v)) != len(mustRecords(t, before))-1 || slices.Contains(mustRecords(t, v), FailedRecord("main", "x")) {
t.Errorf("the pin holds %s after the record drop, was %s: want the one record gone and the others staying", v, before)
}
if r := ix.PinDrop(ctx, "main.1", "operator", "names no running pipeline"); !r.Stored {
t.Fatalf("the pin drop answered %q", r.Answer)
}
@@ -45,6 +45,9 @@ type TakeInAsk struct {
NamedFingerprint string `json:"named-fingerprint,omitempty" takein:"act"`
// PinDrop asks one pin of the state pins, by its key, to be dropped (indexer_pin_drop, design 47 H §765).
PinDrop string `json:"pin-drop,omitempty" takein:"act"`
// PinDropRecord asks one record, by its name, to be dropped from every pin that holds it, the pins' other records staying
// (indexer_pin_drop with record, design 47 H2 H-A-572 (3)).
PinDropRecord string `json:"pin-drop-record,omitempty" takein:"act"`
// Held names the watched branch whose held source-moved is taken in again now (indexer_take_in_pending) or, with Skip and
// HeldSource, ended unwritten (indexer_take_in_skip; design 47 H §744).
Held string `json:"held,omitempty" takein:"act"`