git remote: since v2.1.2 a pull can re-download the whole database, because each process deletes its fetch ref
Since v2.1.2 (#11150, the fix for #11141), Teardown() deletes each process's tracking ref when it exits. A later git fetch into the same git remote cache then has no local ref that reaches the data history, so it sends no usable have, and the remote sends the whole object closure of refs/dolt/data. In a database that was created locally and then pushed, every dolt pull of a one-row change receives the whole database. On 1.86.6, before #11150, the same pulls received only the new objects. A dolt clone is affected less: its clone-time ref is never deleted, so its pulls receive everything pushed since the clone.
Reproduction
dolt 2.3.5, git 2.54.0, macOS arm64, a git+file:// remote. Dolt will not push to a repository with no branches, so the first lines seed one.
git init -q --bare hub.git
empty=$(git --git-dir hub.git hash-object -t tree -w /dev/null)
git --git-dir hub.git update-ref refs/heads/main "$(git --git-dir hub.git commit-tree "$empty" -m seed)"
{ echo id,txt; head -c 15000000 /dev/urandom | base64 | tr -d '\n' | fold -w 1000 | head -n 20000 | awk '{print NR "," $0}'; } > data.csv
mkdir A && cd A && dolt init
dolt sql -q "create table t (id int primary key, txt varchar(1000))"
dolt table import -u t ../data.csv
dolt add -A && dolt commit -m seed
dolt remote add origin "git+file://$PWD/../hub.git"
dolt push --set-upstream origin main
cd .. && dolt clone "git+file://$PWD/hub.git" B
cd B && dolt sql -q "update t set txt = 'x' where id = 1" && dolt commit -am edit && dolt push origin main && cd ..
cd A && GIT_TRACE_PACKFILE="$PWD/../pack.bin" dolt pull && wc -c < ../pack.binThe last pull received 15,681,794 bytes; hub.git is 16 MB. With 80,000 rows and alternating one-row edits:
| Pull | Pack bytes | Objects in pack / in remote closure |
|---|---|---|
| B (the clone), 3 pulls | 12,144 to 15,170 | 8/18, 16/26, 24/34 |
| A (created and pushed), 3 pulls | 62,632,260 to 62,639,680 | 42/42, 50/50, 58/58 |
| A, with a ref pinned in its cache | 13,073 | 8/66 |
| Same script on 1.86.6, every pull after A's first into an empty cache | about 13,000 | 8 |
Mechanism
- Each process fetches into its own ref,
refs/dolt/remotes/<remote>/<ref>/<uuid>(RemoteTrackingRef), withgit fetch --no-tags --refmap= <remote> +refs/dolt/data:<that ref>(FetchRef).Teardown()deletes it. - Afterwards A's cache holds only
refs/dolt/info/__dolt_remote_info__andrefs/remotes/origin/__dolt_remote_info__, which are on a separate history. In the packet trace of A's pull, the onlyhaveis that commit. The server ACKs it and sends the whole closure. - The pinned row used
git --git-dir <cache>/repo.git update-ref refs/test/keep <tip>, where<tip>is the remote'srefs/dolt/dataand the cache already holds it. The fetch offers it as ahaveand receives 8 objects. Dolt leaves the extra ref alone.
We hit this through beads, which embeds Dolt (commit 796d07497741). Over git+ssh, every one-row pull of our database received all 334 MB of it and took about 50 s. With the pinned ref, it received 19-36 KB in 6-10 s.
Suggested fix
Keep the per-instance refs for concurrent fetches. After a successful fetch, also move one stable per-remote ref, such as refs/dolt/remotes/<remote>/<ref>/last, to the fetched tip, and have Teardown() leave it in place. A failed write there can be ignored, since either concurrent writer's tip is a valid base. Because the ref always names the latest tip, the old flattened histories from #11141 still become unreachable, and the daily gc --prune=now still removes them.
This would not help the first pull after Dolt starts a new parentless data commit (every 64 data commits). In the beads setup, that pull received the whole database (334.7 MB) even with the ref pinned at the exact previous tip, which the server acknowledged as common.
Related: #11141, #11150, #11916 (read amplification after the fetch, a separate cost).
Source: dolthub/dolt