Artifact 3285c218fd1ca512079b2a80c1f79fba4b36810793fd3d3ee89d61a1e37202d9:
- File
internal/sync/clone_shun_test.go
— part of check-in
[b43fd24a1f]
at
2026-10-23 05:28:31
on branch feat/horizon-cones
— perf(sync): check received deltas against a cached basis
The real-repository gate found a dense clone of the Fossil repository CPU-bound past an hour, in delta.Checksum and chain expansion. checkDelta rebuilt each received delta's basis from the root of its chain with content.ExpandUnchecked, after walking the chain for availability; a file's history arrives as one chain of hundreds or thousands of deltas, so the cost was quadratic in its depth, as Repo.Verify's was before 1a5abca.
A receive pass now rebuilds the basis through an unchecked content cache (content.NewUncheckedCache): from the deepest node of the chain it holds, keeping each node it rebuilds, and it remembers every artifact a card stored and verified once the card's savepoint commits. A clone keeps one such cache across its rounds and clears it when a round rolls back. A basis the cache holds, or one dangling in the pass, needs no availability walk, and the clone's check for a basis to request uses the same knowledge. The cache holds what each row rebuilds to, unchecked as checkDelta's basis always was, so every verdict is unchanged; a verified delta's target also goes to the receive linker, which no longer expands it again.
TestCorpusClone (LIBFOSSIL_CORPUS) clones a copy of a repository from an in-process server for profiling. (user: [email protected], size: 2571) [annotate] [blame] [check-ins using] [more...]
package sync import ( "context" "github.com/danmestas/go-libfossil/internal/content" "testing" "github.com/danmestas/go-libfossil/internal/blob" "github.com/danmestas/go-libfossil/internal/delta" "github.com/danmestas/go-libfossil/internal/hash" "github.com/danmestas/go-libfossil/internal/manifest" "github.com/danmestas/go-libfossil/internal/shun" "github.com/danmestas/go-libfossil/internal/xfer" "github.com/danmestas/go-libfossil/simio" ) // TestCloneShunRules pins fossil's shun handling during a clone: a shunned // cfile is dropped (xfer_accept_compressed_file checks the shun list // always), a shunned file card is kept (xfer_accept_file skips the check for // a clone), and a shunned delta basis never becomes a phantom to ask for. func TestCloneShunRules(t *testing.T) { r := setupSyncTestRepo(t) linker, err := manifest.NewReceiveLinker(r) if err != nil { t.Fatalf("NewReceiveLinker: %v", err) } cs := &cloneSession{ repo: r, env: simio.RealEnv(), linker: linker, seqno: 1, phantoms: map[string]bool{}, availableDeltaSources: map[string]struct{}{}, basis: content.NewUncheckedCache(receiveBasisBytes), } cs.obs = resolveObserver(nil) fileData := []byte("a shunned file card") cfileData := []byte("a shunned cfile card") base := []byte("a shunned basis, long enough for a delta to be worth it") target := []byte("a shunned basis, long enough for a delta to be worth it, v2") deltaBytes, err := delta.Create(base, target) if err != nil { t.Fatalf("delta.Create: %v", err) } fileUUID, cfileUUID, baseUUID := hash.SHA1(fileData), hash.SHA1(cfileData), hash.SHA1(base) for _, u := range []string{fileUUID, cfileUUID, baseUUID} { if err := shun.Add(r.DB(), u, ""); err != nil { t.Fatalf("shun.Add: %v", err) } } msg := &xfer.Message{Cards: []xfer.Card{ &xfer.FileCard{UUID: fileUUID, Content: fileData}, &xfer.CFileCard{UUID: cfileUUID, Content: cfileData}, &xfer.CFileCard{UUID: hash.SHA1(target), DeltaSrc: baseUUID, Content: deltaBytes}, }} if err := cs.processResponse(context.Background(), 1, msg); err != nil { t.Fatalf("processResponse: %v", err) } if _, ok := blob.Exists(r.DB(), fileUUID); !ok { t.Error("a shunned file card was dropped during a clone") } if _, ok := blob.Exists(r.DB(), cfileUUID); ok { t.Error("a shunned cfile was stored during a clone") } if cs.phantoms[baseUUID] { t.Error("a shunned delta basis became a phantom to ask for") } if cs.result.BlobsRecvd != 2 { t.Errorf("BlobsRecvd = %d, want 2 (the shunned cfile not counted)", cs.result.BlobsRecvd) } }