diff --git a/modules/mesh-delivery-indexer/internal/index/held.go b/modules/mesh-delivery-indexer/internal/index/held.go index ca1e685da..41f1d971e 100644 --- a/modules/mesh-delivery-indexer/internal/index/held.go +++ b/modules/mesh-delivery-indexer/internal/index/held.go @@ -167,20 +167,27 @@ func (ix *Indexer) unhold(ctx context.Context, branch string, source int64) { } } -// TakeHeldIn takes every branch's held source revisions in, each branch in its order, on the indexer's own room and at its -// start (H-A-114, H-A-118): a branch stops at the first that still cannot be taken in, which stays held with those behind it. +// TakeHeldIn takes every branch's held source revisions in, each branch in its order, on the indexer's own room, at its +// start and by hand (H-A-114, H-A-118): a branch stops at the first that still cannot be taken in, which stays held with those +// behind it. Once a held one is taken in, the next held of its branch is taken in at once, each such start said in the journal +// (design 47 H2 H-A-497). func (ix *Indexer) TakeHeldIn(ctx context.Context) { all, err := ReadHeld(ctx, ix.Held) if err != nil { ix.logf("take-in: the state %s is not read, so no held take-in is taken in again now: %v", HeldState, err) return } - stopped := map[string]bool{} + stopped, landed := map[string]bool{}, map[string]int64{} for _, h := range all { if stopped[h.Branch] { continue } - if _, err := ix.TakeInSource(ctx, h.Event()); err != nil { + if prev, ok := landed[h.Branch]; ok { + ix.logf("take-in: held source %d of %s taken in next, after %d (H-A-497)", h.Source, h.Branch, prev) + } + if _, err := ix.TakeInSource(ctx, h.Event()); err == nil { + landed[h.Branch] = h.Source + } else { ix.logf("take-in: source revision %d of %s is still held: %v", h.Source, h.Branch, err) stopped[h.Branch] = true } diff --git a/modules/mesh-delivery-indexer/internal/index/takein_source_test.go b/modules/mesh-delivery-indexer/internal/index/takein_source_test.go index 5765977ef..9ff2077df 100644 --- a/modules/mesh-delivery-indexer/internal/index/takein_source_test.go +++ b/modules/mesh-delivery-indexer/internal/index/takein_source_test.go @@ -371,11 +371,25 @@ func TestATakeInOnAFullStoreIsHeldAndSaidOnce(t *testing.T) { len(held[0].Heads) != 1 || held[0].Heads[0] != moved.Heads[0] || !reflect.DeepEqual(held[0].Event(), moved) { t.Fatalf("held = %+v, want 3 then 4, each with its event whole", held) } + // H-A-497: behind them a source whose head the forge does not answer, and one more behind it. + for _, n := range []struct { + source int64 + commit string + }{{5, "c-unread"}, {6, f.Merge}} { + e := moved + e.Source, e.Call, e.Heads = n.source, fmt.Sprintf("%d123456789abcdef", n.source), []meshdelivery.SourceMovedEventHeadsItem{{Repository: f.Repository, Commit: n.commit}} + if behind, err := ix.HoldBehind(ctx, e); err != nil || !behind { + t.Fatalf("source %d held behind: %v (%v)", n.source, behind, err) + } + } + var lines []string + ix.Logf = func(format string, args ...any) { lines = append(lines, fmt.Sprintf(format, args...)) } objects.capacity = 1 << 22 if ok, err := ix.RoomAgain(ctx); err != nil || !ok || rooms != 1 { t.Fatalf("room said %v %d times (%v), want once the store has room", ok, rooms, err) } - // H-A-114: on room (and at start) the held ones are taken in again from the state held alone, in their order. + // H-A-114, H-A-497: on room (and at start, and by hand) the held ones are taken in again from the state held alone, in + // their order, each next one at once and said in the journal, until one is held again: those behind it stay held. ix.TakeHeldIn(ctx) var taken []int64 for _, e := range *said { @@ -386,8 +400,25 @@ func TestATakeInOnAFullStoreIsHeldAndSaidOnce(t *testing.T) { if !reflect.DeepEqual(taken, []int64{3, 4}) { t.Errorf("taken again on room: %v of %+v, want 3 then 4", taken, *said) } - if held, _ := ReadHeld(ctx, ix.Held); len(held) != 0 { - t.Errorf("held = %+v after the take-in, want none", held) + if held, _ := ReadHeld(ctx, ix.Held); len(held) != 2 || held[0].Source != 5 || held[1].Source != 6 { + t.Errorf("held = %+v after the take-in, want 5 held again and 6 behind it", held) + } + for _, want := range []string{ + "take-in: held source 4 of main taken in next, after 3 (H-A-497)", + "take-in: held source 5 of main taken in next, after 4 (H-A-497)", + } { + if !slices.Contains(lines, want) { + t.Errorf("the journal holds no line %q: %q", want, lines) + } + } + for _, l := range lines { + if strings.Contains(l, "held source 6 of main taken in") { + t.Errorf("source 6 was taken in behind a held one: %q", l) + } + } + ix.Logf = nil + for _, src := range []int64{5, 6} { + ix.unhold(ctx, "main", src) } // A skip ends a held source revision unwritten: take-in.taken with no entries, skipped, by and why; held is deleted. ix.hold(ctx, meshdelivery.SourceMovedEvent{Branch: "nox-mesh", Source: 9, Call: "fedcba9876543210"}, "the catalog store is full")