Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software:2222/vole.git

A free and open-source forge that lives in your Git repo.

Metadata writers queue on the branch instead of racing for it

122cbe4f62bf87a941538450584ba1b20444c135 · Keenan Nemetz · 7d ago · parent 4739664b

Metadata writers queue on the branch instead of racing for it

Every write to refs/heads/vole read the whole branch, decided, and moved the
ref with a compare-and-swap, retrying up to 64 times with no backoff and no
coordination. Concurrent writers therefore did not queue: they each paid a full
read, lost, and paid it again. Measured on a 2,000-file branch, one write needed
one attempt alone and 21 with 32 writers, and throughput fell as writers were
added because the retries were the load. At 64 simultaneous writers the loop ran
out and the write failed for being unlucky.

The read-modify-write now runs with one writer at a time, holding a flock in the
repository so the SSH hook and the server queue behind each other. The
compare-and-swap stays for writers that go around the lock — a push, a hand-run
git command, another host — and losing one now waits with jittered backoff
before deciding again.

Writers read the branch once. The load and the decision happen inside the commit
instead of before it, which also stops an edit from replacing a change that
landed while the page was open: the decision is made against the tree it writes.

A push only does that work when it has metadata to move. Post-receive asks the
index which open requests follow the branch it moved, and a branch nobody is
proposing from now writes an audit line and no commit.

Measurements, 32 concurrent writers: 21.3 CAS attempts per write before, 1.0
after. Through the web, posting comments at concurrency 32: p99 4.7 s -> 0.95 s,
and throughput no longer falls as workers are added. The load harness gains a
`comment` scenario so the number is visible.

Closes: 01M6D9G8H6E0RCQ3AD5TMAGX34

forge/index/requests_test.go +50

@@ -292,3 +292,53 @@ func TestEnsureIndexesReleaseArtifacts(t *testing.T) {
292 292 t.Fatalf("artifacts(v2.0.0) = %+v, %v", list, err)
293 293 }
294 294 }
295
296 // A push asks whether any open request follows the branch it moved. The answer has
297 // to be trustworthy or absent: a stale index must say "ask the branch" rather than
298 // "nobody follows this", because a skipped sync is not repaired afterwards.
299 func TestRequestsFollowingOnlyAnswersForTheBranchItIndexed(t *testing.T) {
300 t.Parallel()
301 s, m, g := incrementalRepo(t)
302 now := time.Date(2026, 10, 30, 12, 0, 0, 0, time.UTC)
303 followed := createIndexedRequest(t, g, "Follows feature", now, nil)
304 if _, err := metadata.SetRequestHead(g, followed.ID, requestHead, "feature", "keenan"); err != nil {
305 t.Fatal(err)
306 }
307 createIndexedRequest(t, g, "Pinned to a commit", now.Add(time.Minute), nil)
308 if err := s.Ensure(m); err != nil {
309 t.Fatal(err)
310 }
311
312 follows, ok, err := s.RequestsFollowing(m, "feature")
313 if err != nil {
314 t.Fatal(err)
315 }
316 if !follows || !ok {
317 t.Fatalf("feature = follows %v, known %v; want both true", follows, ok)
318 }
319 follows, ok, err = s.RequestsFollowing(m, "other")
320 if err != nil {
321 t.Fatal(err)
322 }
323 if follows || !ok {
324 t.Fatalf("other = follows %v, known %v; want a known no", follows, ok)
325 }
326
327 // A closed request stops following its branch.
328 if _, err := metadata.SetRequestState(g, followed.ID, "closed", "keenan"); err != nil {
329 t.Fatal(err)
330 }
331 if err := s.Ensure(m); err != nil {
332 t.Fatal(err)
333 }
334 if follows, ok, err = s.RequestsFollowing(m, "feature"); err != nil || follows || !ok {
335 t.Fatalf("closed request: follows %v, known %v, err %v", follows, ok, err)
336 }
337
338 // The branch moves and the index is behind: the question is no longer answerable,
339 // so the caller has to look.
340 createIndexedIssue(t, g, "Moved on", now.Add(2*time.Minute), nil, nil)
341 if follows, ok, err = s.RequestsFollowing(m, "feature"); err != nil || ok {
342 t.Fatalf("stale index answered: follows %v, known %v, err %v", follows, ok, err)
343 }
344 }