Skip to content

Git designed for AI agents.

graft: a lane round that could not ask the rules gives its ticket back, and the holder does not ask its rule in the lane

Federico Eliacf2645090bff
diff --git a/internal/gitaly/service/operations/land_attempt.go b/internal/gitaly/service/operations/land_attempt.go
index 070538e..9ce7cb8 100644
--- a/internal/gitaly/service/operations/land_attempt.go
+++ b/internal/gitaly/service/operations/land_attempt.go
@@ -61,7 +61,7 @@ type landingAttempt struct {
observe landPhaseObserver
// mode is how the attempt makes its objects durable.
mode landPublishMode
- // inline is the time the members of the attempt may lose to inline calls that fail (land_inline.go).
+ // inline is the time the members of the attempt have spent in inline calls (land_inline.go).
inline landInlineBudget
}
diff --git a/internal/gitaly/service/operations/land_inline.go b/internal/gitaly/service/operations/land_inline.go
index c647abc..ab881bb 100644
--- a/internal/gitaly/service/operations/land_inline.go
+++ b/internal/gitaly/service/operations/land_inline.go
@@ -209,31 +209,3 @@ func landListingPaths(l landListing) []string {
}
return paths
}
-
-// landWillNotLand reports whether the files the land has now carry a model's verdict (or a held one) and no
-// verification is configured: such a land ends with the package, so no other land gives way to it.
-func (s *Server) landWillNotLand(pre *landPreResolution) bool {
- if s.resolveCfg.Verify.Enabled {
- return false
- }
- for k := range pre.current {
- if v, ok := pre.verdicts[k]; ok && (v.file.FromModel() || v.file.Hold != "") {
- return true
- }
- }
- return false
-}
-
-// landHasModelVerdict reports whether a file of the listing has a model's (or a held) verdict. Without a
-// verification such a land does not land, so no other land has to give way to it.
-func landHasModelVerdict(s *Server, l landListing, pre *landPreResolution) bool {
- if s.resolveCfg.Verify.Enabled {
- return false
- }
- for _, f := range l.files {
- if v, ok := pre.verdicts[landKeyOf(f.conflict)]; ok && (v.file.FromModel() || v.file.Hold != "") {
- return true
- }
- }
- return false
-}
diff --git a/internal/gitaly/service/operations/land_inline_bounds_test.go b/internal/gitaly/service/operations/land_inline_bounds_test.go
index a86b860..0b847f4 100644
--- a/internal/gitaly/service/operations/land_inline_bounds_test.go
+++ b/internal/gitaly/service/operations/land_inline_bounds_test.go
@@ -552,4 +552,97 @@ func TestUserLand_aRuleSlowerThanTheTimeoutLandsOnAHotFile(t *testing.T) {
require.Contains(t, got, "slowrule-1")
require.Len(t, strings.Split(got, "\n"), stream+2, "ours, the slow rule's line and every other land's")
require.Empty(t, landTickets.keysOf(q.scope))
+
+ // The holder does not ask its slow rule in the lane again: once for its first lane round, once for the round
+ // in which it lost, and no more.
+ raw, err := os.ReadFile(filepath.Join(q.dir, "inline-slow.log"))
+ require.NoError(t, err)
+ require.LessOrEqual(t, len(raw)/2, 2, "the slow rule was asked in the lane by the holder with priority")
+}
+
+// TestUserLand_aModelLandThatCannotAskTheRulesReleasesItsTicket: as
+// TestUserLand_aModelLandReleasesTheTicketItQueuedFor, but the inline slots stay taken, so the lane round after the
+// wait cannot ask the rules at all (no rulesCannot to say that a model is next). The land must not hold the ticket
+// of the file during the model call out of the lane.
+func TestUserLand_aModelLandThatCannotAskTheRulesReleasesItsTicket(t *testing.T) {
+ t.Parallel()
+
+ var s *Server
+ operationServerHooks.Store(t.Name(), func(served *Server) { s = served })
+ q := newQueueFixtureMode(t, 1, "model", func(c *config.GraftResolver) { c.InlineTimeout = "" })
+ require.NotNil(t, s)
+
+ var own []interface{ Release() }
+ for {
+ slot, ok := s.conflictResolver.TryAcquireInlineSlot()
+ if !ok {
+ break
+ }
+ own = append(own, slot)
+ }
+ defer func() {
+ for _, slot := range own {
+ slot.Release()
+ }
+ }()
+ holder, err := landTickets.acquire(q.ctx, []string{q.keyOfA})
+ require.NoError(t, err)
+ defer holder.release()
+
+ model := gittest.WriteCommit(t, q.cfg, q.repoPath, gittest.WithParents(q.base),
+ gittest.WithTreeEntries(
+ gittest.TreeEntry{Mode: "100644", Path: "a", Content: "model-1\n"},
+ gittest.TreeEntry{Mode: "100644", Path: "b", Content: "base\n"}))
+ done := make(chan error, 1)
+ go func() {
+ _, err := q.land(model)
+ done <- err
+ }()
+ require.Eventually(t, func() bool { return landTickets.waiting(q.keyOfA) == 1 }, 30*time.Second, 5*time.Millisecond, "the model land queued")
+ holder.release()
+
+ require.Eventually(t, func() bool { return unionCalls(t, q.dir)-inlineCalls(t, q.dir) >= 1 }, 30*time.Second, 5*time.Millisecond, "the model call is in flight")
+ require.False(t, landTickets.blocked([]string{q.keyOfA}, nil), "the land held the ticket of the file during its model call")
+
+ require.NoError(t, os.WriteFile(filepath.Join(q.dir, "release"), nil, 0o644))
+ select {
+ case err := <-done:
+ requireMergeConflict(t, err)
+ case <-time.After(60 * time.Second):
+ t.Fatal("the model land did not end")
+ }
+}
+
+// TestLandApplyVerdicts_theHolderWithPriorityDoesNotAskTheRulesInTheLane: a land that holds its files with priority
+// and comes back to the lane without a verdict for them (the files changed under it once more) is handed back to
+// be resolved out of the lane: it does not ask its rule in the lane again, which would only stall the batch. The
+// control, a land without a ticket, asks.
+func TestLandApplyVerdicts_theHolderWithPriorityDoesNotAskTheRulesInTheLane(t *testing.T) {
+ t.Parallel()
+
+ p := newInlineProbe(t, "", nil)
+ req := p.fx.request("Land")
+ apply := func(pre *landPreResolution) error {
+ _, err := p.s.landApplyVerdicts(p.fx.ctx, req, p.fx.repo, p.fx.tip, p.fx.commit, p.fx.committer(), pre)
+ return err
+ }
+
+ // Without a ticket the lane asks the rules, and resolves.
+ pre := newLandPreResolution()
+ _, err := p.s.landApplyVerdicts(p.fx.ctx, req, p.fx.repo, p.fx.tip, p.fx.commit, p.fx.committer(), pre)
+ require.NoError(t, err)
+ require.Equal(t, 1, inlineCalls(t, p.dir))
+
+ // With the priority it does not: the land is handed back, with the files it needs resolved.
+ ticket, err := landTickets.acquire(p.fx.ctx, p.s.landListingKeys(req, p.l))
+ require.NoError(t, err)
+ defer ticket.release()
+ ticket.setPriority()
+ held := newLandPreResolution()
+ held.ticket = ticket
+ var need *landNeedsResolution
+ require.ErrorAs(t, apply(held), &need)
+ require.NotEmpty(t, need.paths)
+ require.False(t, need.queued)
+ require.Equal(t, 1, inlineCalls(t, p.dir), "the holder did not ask the rules in the lane")
}
diff --git a/internal/gitaly/service/operations/land_preresolve.go b/internal/gitaly/service/operations/land_preresolve.go
index a8e3baf..57d8fb8 100644
--- a/internal/gitaly/service/operations/land_preresolve.go
+++ b/internal/gitaly/service/operations/land_preresolve.go
@@ -348,6 +348,13 @@ func (s *Server) landResolving(ctx context.Context, in *gitalypb.UserLandRequest
continue
}
if laneRound && !need.queued {
+ // The lane could not ask the rules (no slot, the batch's budget spent, a slow rule): what is next may
+ // be a model's call out of the lane, and a ticket taken only to wait in the lane protects nothing
+ // then. Only the priority of a land that lost a round out of the lane is kept.
+ if !pre.ticket.hasPriority() {
+ pre.ticket.release()
+ pre.ticket = nil
+ }
continue
}
if err := s.landTakeTicket(resolveCtx, in, pre, need); err != nil {
@@ -391,7 +398,7 @@ func (p *landPreResolution) currentPaths() []string {
// landTicketsBlock reports whether another land holds the ticket of one of paths.
func (s *Server) landTicketsBlock(in *gitalypb.UserLandRequest, paths []string, pre *landPreResolution) bool {
- if len(paths) == 0 || s.landWillNotLand(pre) {
+ if len(paths) == 0 {
return false
}
scope := landTicketScope(in.GetRepository().GetStorageName(), in.GetRepository().GetRelativePath(), in.GetBranch())
@@ -400,8 +407,9 @@ func (s *Server) landTicketsBlock(in *gitalypb.UserLandRequest, paths []string,
// landTakeTicket makes the land hold the tickets of the files it needs resolved, waiting for the lands
// that lost a round before it (land_tickets.go). A land that holds tickets for all of them keeps them.
-// One that now needs more files gives its tickets back and takes the larger set at the tail: tickets
-// are taken in sorted order, so that no two lands wait for each other.
+// One that now needs more files gives its tickets back and takes the larger set at the tail (it loses its
+// place in the queues, and its priority until it is back in the lane): tickets are taken in sorted order, so
+// that no two lands wait for each other.
func (s *Server) landTakeTicket(ctx context.Context, in *gitalypb.UserLandRequest, pre *landPreResolution, need *landNeedsResolution) error {
scope := landTicketScope(in.GetRepository().GetStorageName(), in.GetRepository().GetRelativePath(), in.GetBranch())
keys := landTicketKeys(scope, need.paths, s.resolveCfg.Verify.Enabled)
diff --git a/internal/gitaly/service/operations/land_queue_test.go b/internal/gitaly/service/operations/land_queue_test.go
index edc3cab..188e425 100644
--- a/internal/gitaly/service/operations/land_queue_test.go
+++ b/internal/gitaly/service/operations/land_queue_test.go
@@ -82,6 +82,8 @@ for f in req["files"]:
theirs = base64.b64decode(f["theirs"]["content"]).decode().splitlines()
model = any("model" in l for l in theirs)
if mode == "slowrule" and any("slowrule" in l for l in theirs):
+ if rules:
+ open(dir + "/inline-slow.log", "a").write("x\n")
time.sleep(2)
if mode == "model" and model:
if rules:
diff --git a/internal/gitaly/service/operations/land_resolve.go b/internal/gitaly/service/operations/land_resolve.go
index 8efec82..c9025c6 100644
--- a/internal/gitaly/service/operations/land_resolve.go
+++ b/internal/gitaly/service/operations/land_resolve.go
@@ -522,7 +522,11 @@ func (s *Server) landApplyVerdicts(
if s.landInlineEnabled() && landTickets.priorityBlocked(s.landListingKeys(in, l), pre.ticket) {
return landResolution{}, &landNeedsResolution{tip: tip, commit: commitID, paths: landListingPaths(l), queued: true}
}
- inline = s.landResolveInline(ctx, in, tip, commitID, l, pre)
+ // The holder itself does not resolve inline: it comes back with the verdict of its slow rule, and asking
+ // the rule again would only stall the batch.
+ if !pre.ticket.hasPriority() {
+ inline = s.landResolveInline(ctx, in, tip, commitID, l, pre)
+ }
if inline == landInlineResolved {
missing = missing[:0]
for _, f := range l.files {
@@ -539,9 +543,7 @@ func (s *Server) landApplyVerdicts(
// land on the same files, whose verdicts were made out of the lane, waits for its turn
// (land_tickets.go), instead of landing first and invalidating the holder's verdict once more. A land
// that the lane has just resolved inline needs no turn: the rules do not wait for the tickets.
- // Without a verification, a land whose files have a model's verdict does not land either: it is not
- // waited for.
- if pre != nil && s.conflictResolver != nil && l.bases <= 1 && inline != landInlineResolved && !rulesCannot && !landHasModelVerdict(s, l, pre) {
+ if pre != nil && s.conflictResolver != nil && l.bases <= 1 && inline != landInlineResolved && !rulesCannot {
paths := make([]string, 0, len(l.files))
for _, f := range l.files {
paths = append(paths, f.conflict.path)
diff --git a/internal/gitaly/service/operations/land_tickets.go b/internal/gitaly/service/operations/land_tickets.go
index 83dbd47..5afd752 100644
--- a/internal/gitaly/service/operations/land_tickets.go
+++ b/internal/gitaly/service/operations/land_tickets.go
@@ -218,12 +218,18 @@ func (t *landTicket) covers(keys []string) bool {
// setPriority makes the ticket one that the inline resolutions of the other lands give way to.
func (t *landTicket) setPriority() {
+ if t == nil {
+ return
+ }
t.mu.Lock()
t.priority = true
t.mu.Unlock()
}
func (t *landTicket) hasPriority() bool {
+ if t == nil {
+ return false
+ }
t.mu.Lock()
defer t.mu.Unlock()
return t.priority && !t.released