"git push": tellme-more protocol extension
PATCH 1/1 "git push": tellme-more protocol extension
The workflow git supports has always been biased towards the kernel style "each developer has his own publishing repository only himself pushes into, and others pull from it". We have been fairly good at enhancing support for the workflow at the other end of the spectrum, a shared repository everybody clones and updates from and everybody also pushes into. However, if you look under the hood and study the native protocol used for fetching and pushing, it becomes apparent that our origin is really "pushing into owned publishing point" workflow.
The protocol between send-pack and receive-pack, which is used for "git push", is much simpler than the protocol used on the "git fetch" side.
When the sender connects, the receiver first tells the sender what commits its refs are pointing at, and then the sender figures out what revision range to build a pack out of, based on the "here are my refs" information it learned from the receiver and the set of refs it has.
This works well enough, if you assume that the sender always knows enough about what the receiver has, and when the sender owns the receiving end (i.e. he is the only one who pushes into it), by definition, all the commits at the receiving end will be what the sender has pushed there, and it already knows about them.
Also, because by default we do not accept a commit that does not fast-forward the old ref when you are updating an existing branch, this assumption often holds true even for shared repository workflow. If your push is blocked because it does not fast-forward, the first thing you would do is to fetch from there, which makes you learn everything the other end has.
But this breaks down in one case. If you have a single branch shared repository with two developers, and after one developer updates that branch, if the second developer wants to push a new branch (fork) to the shared repository:
(0) First, an illustration of the situation. Developer one and two cloned from the shared repository when its head was at commit A. Developer one built some changes and pushed it back. The shared repository's "master" is now at commit B.
---o----o----o----A----o----o----B
\
o---o---o---C
In the meantime, developer two hacked on top of A and his tip is at commit C. He is not confident enough to push this back to "master" (and if he did so, he won't succeed because it wouldn't fast-forward), but wants to share it with co-workers by pushing it to a new "xprm" branch at the shared repository. He says:
$ git push origin master:refs/heads/xprm
Now what happens?
(1) The recieving end (i.e. the shared repository) will say "master is now at commit B".
(2) The sending end, however, has not seen B. All it knows is that there is no "xprm" over there yet, and it wants to send C.
(3) Based on the available information, it ends up sending the whole history leading to C. Oops.
This patch teaches the send-pack protocol a new extension, "tellme-more".
When both ends support this extension, the receiving end first says "I support tellme-more, and here are my refs". The sending side, when it sees commits that it does not know about (e.g. "B" in the above example), can then ask "I do not know about B, but it probably is related to what I already have, so tell me more about it".
The receiving end then responds with list of commits that are ancestors of "B", and in the above example, the sender will find out that the recieving end also has "A". After this exchange, the sending end can build a pack that contains objects between A..C, instead of having to send the full history leading to "C".
Without the protocol extension, the attached small test (t5407) ends up transferring 39 objects, which exactly matches the above observation, and with the patch it sends only 9.
There are a few obvious things that could be improved.
- Currently, there is a backoff mechanism to optimize responses to tellme-more requests by sending every N^2-th non-merge commit in a single-strand-of-pearls ancestry chain so that a very stale sender can find some common ancestor efficiently, but this backoff could be a bit too aggressive.
- There is no active defence against a malicious sender that asks tellme-more over and over to force the receiver do extra work, except the abovementioned backoff and the fact that the receiver stops working once it reaches the root commit. Push is allowed to only trusted parties so hopefully this will not be such a big deal.
---
* Obviously post 1.5.5 material.
Documentation/technical/pack-protocol.txt | 29 ++++++- builtin-send-pack.c | 108 ++++++++++++++++++++++- receive-pack.c | 141 ++++++++++++++++++++++++++++- t/t5407-send-pack-shared.sh | 59 ++++++++++++ 4 files changed, 332 insertions(+), 5 deletions(-) create mode 100755 t/t5407-send-pack-shared.sh
Documentation/technical/pack-protocol.txt +28 -1
@@ -29,7 +29,7 @@ upload-pack (S) | fetch/clone-pack (C) protocol: send-pack | receive-pack protocol. # Tell the pusher what commits we have and what their names are - C: SHA1 name + C: SHA1 name (capabilities) C: ... C: SHA1 name C: # flush -- it's your turn
@@ -39,3 +39,30 @@ send-pack | receive-pack protocol. S: ... S: # flush -- done with the list S: XXXXXXX --- packfile contents. + +When tellme-more extension is used: + + # Tell the pusher what commits we have and what their names are + C: SHA1 name (capabilities) + C: ... + C: SHA1 name + C: # flush -- it's your turn + # Tell the puller what the pusher has + S: old-SHA1 new-SHA1 name + S: old-SHA1 new-SHA1 name + S: tellme-more old-SHA1 -- I do not know about this one, + S: tellme-more old-SHA1 -- give me ancestors of them. + S: # flush -- done with the list + # Tell the pusher more about history + C: SHA1 old-SHA1 -- This is ancestor of that, you might know + C: SHA1 old-SHA1 + C: ... + C: # flush -- have you heard ehough? + S: tellme-more old-SHA1 -- I still want to know more about this one + S: # flush -- please give me more + C: SHA1 old-SHA1' + C: SHA1 old-SHA1' + C: ... + C: # flush -- have you heard ehough? + S: # flush -- yes, thanks, we've heard enough + S: XXXXXXX --- packfile contents.
builtin-send-pack.c +107 -1
144 lines not on this page · raw message
receive-pack.c +138 -3
177 lines not on this page · raw message
t/t5407-send-pack-shared.sh new file +59 -0
59 lines not on this page · raw message
Signature · 1 line
1.5.5.rc0.133.g7e207
Quoted 11 lines · Junio C Hamano
When both ends support this extension, the receiving end first says "I support tellme-more, and here are my refs". The sending side, when it sees commits that it does not know about (e.g. "B" in the above example), can then ask "I do not know about B, but it probably is related to what I already have, so tell me more about it".
The receiving end then responds with list of commits that are ancestors of "B", and in the above example, the sender will find out that the recieving end also has "A". After this exchange, the sending end can build a pack that contains objects between A..C, instead of having to send the full history leading to "C".
Hrm. It seems like we are sending a lot more data than we need. The sender doesn't actually _care_ about A..B, which can be arbitrarily long; he only cares about finding A.
I wonder if there's a way to for the _sender_ to claim "I have up to A", and the receiver to send back an "OK, just send A..C." If the receiver is currently at "B", then the sender can't figure it out from the refs the receiver shows. But he might he might optimistically suggest it if he has other refs pointing to "A" (like remotes/origin/master).
IOW, something like:
[S connects to R]
R: master is at B
[S realizes he doesn't have B, so he shows his refs, without names]
S: I have optimistically interesting commits: A, C
R: I have A
S: OK, here's C ^A
In the case that the receiver doesn't have any of those refs, then we fall back to the old behavior. So basically rather than enumerating the ancestors, we optimistically assume that things that are in refs are likely to be of interest.
Two disadvantages I can think of:
1. S actually "leaks" some knowledge about which commits he has to R (not refnames, but actual SHA1s). I don't know if we care about that or not.
2. This can actually be _more_ network intensive than your proposal. It trades off sending all of the ancestors A..B for sending the tip of all of the refs. So if A..B is short, but you have a ton of local refs, it's a lose. You could maybe be smarter about the optimistic choice (e.g., "I'm talking with origin, therefore consider only refs/remotes/origin/*"). That also alleviates the "leak" problem since you are saying "I have this commit that I got from you before." But it doesn't kick in if you usually talk to one remote, but now are talking to a different, related one.
-Peff
Quoted 1 line · Jeff King
2. This can actually be _more_ network intensive than your proposal.
I do not think this matters much in practice. If you have tons of refs on _your_ side to matter, some of them would be tags that are known to both ends. The only case it really is troublesome is when the sender does not know _any_ of the refs the receiver presented to it.
In the illustration in the message you are responding to, if the commit A was tagged at the shared repository when two developers cloned, it does not matter if C is unknown to the second pusher.
So a potential improvement might be to ask for "tellme-more" only if we do not know any of the refs the receiver showed us; my patch does it if there is at least one unknown instead.
Quoted 3 lines · Junio C Hamano
So a potential improvement might be to ask for "tellme-more" only if we do not know any of the refs the receiver showed us; my patch does it if there is at least one unknown instead.
You can still get cases where doing this is more expensive than your patch, because A..B is very small but shared_tag..A is very large. I'm not sure which is more likely in practice.
-Peff
Quoted 9 lines · Jeff King
Quoted 3 lines · Junio C Hamano
So a potential improvement might be to ask for "tellme-more" only if we do not know any of the refs the receiver showed us; my patch does it if there is at least one unknown instead.
You can still get cases where doing this is more expensive than your patch, because A..B is very small but shared_tag..A is very large. I'm not sure which is more likely in practice.
Oh, I have a few fix-ups since I sent the patch, but I am not planning to experiment with _your_ protocol myself. Debugging one protocol extension a week is painful enough ;-)
And tellme-more does not send _every_ commit. The sender asks only about the refs it does not know about, and the receiver sends densely near the tip and then walks sparsely as it goes deeper, so the traffic wouldn't be so bad. Latency might be a different story, though.