git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [WIP RFC 4/5] upload-pack: refactor writing of "packfile" line

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 7, 2018, 00:22 UTC
Message-ID
<xmqqmupi89ub.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20181206232538.141378-1-jonathantanmy@google.com>
Jonathan Tan <jonathantanmy@google.com> writes:
Show 20 quoted lines
>> Jonathan Tan <jonathantanmy@google.com> writes:
>> 
>> > @@ -126,6 +129,12 @@ static int read_pack_objects_stdout(int outfd, struct output_state *os)
>> >  	}
>> >  	os->used += readsz;
>> >  
>> > +	if (!os->packfile_started) {
>> > +		os->packfile_started = 1;
>> > +		if (use_protocol_v2)
>> > +			packet_write_fmt(1, "packfile\n");
>> 
>> If we fix this function so that the only byte in the buffer is held
>> back without emitted when os->used == 1 as I alluded to, this may
>> have to be done a bit later, as with such a change, it is no longer
>> guaranteed that send_client_data() will be called after this point.
>
> I'm not sure what you mean about there being no guarantee that
> send_client_data() is not called - in create_pack_file(), there is an
> "if (output_state.used > 0)" line (previously "if (0 <= buffered)") that
> outputs anything remaining.

I was referring to this part of the review on the previous step, which you may not yet have read.

    OK, this corresponds to the "*cp++ = buffered"  in the original just
    before xread().
    > +		os->used = 1;
    > +	} else {
    > +		send_client_data(1, os->buffer, os->used);
    > +		os->used = 0;
    I am not sure if the code is correct when os->used happens to be 1
    (shouldn't we hold the byte, skip the call to send_client_data(),
    and go back to poll() to expect more data?), but this is a faithful
    code movement and rewrite of the original.

The point of this logic is to make sure we always hold back some bytes and do not feed *all* the bytes to the other side by calling "send-client-data" until we made sure the upstream of what we are relaying (pack-objects?) successfully exited, but it looks to me that the "else" clause above ends up flushing everything when os->used is 1, which goes against the whole purpose of the code.

And the "fix" I was alluding to was to update that "else" clause to make it a no-op that keeps os->used non-zero, which would not call send-client-data.

When that fix happens, the part that early in the function this patch added "now we know we will call send-client-data, so let's say 'here comes packdata' unless we have already said that" is making the decision too early. Depending on the value of os->used when we enter the code and the number of bytes xread() reads from the upstream, we might not call send-client-data yet (namely, when we have no buffered data and we happened to get only one byte).

> ... it might be
> better if the server can send sideband throughout the whole response -
> perhaps that should be investigated first.

Yup. It just looked quite crazy, and it is even more crazy to buffer keepalives ;-)

Previous: Jonathan TanNext: Jonathan Tan
Message 27 of 30 in “[WIP RFC 0/5] Design for offloading part of packfile response to CDN”
  1. Jonathan TanDec 3, 2018
  2. 1/5 Documentation: order protocol v2 sectionsJonathan Tan, Dec 3, 2018
  3. Junio C HamanoDec 5, 2018
  4. Jonathan TanDec 6, 2018
  5. Junio C HamanoDec 9, 2018
  6. 2/5 Documentation: add Packfile URIs design docJonathan Tan, Dec 3, 2018
  7. Stefan BellerDec 4, 2018
  8. brian m. carlsonDec 4, 2018
  9. Jonathan TanDec 4, 2018
  10. Christian CouderFeb 19, 2019
  11. Jonathan TanFeb 19, 2019
  12. Christian CouderFeb 22, 2019
  13. Ævar Arnfjörð BjarmasonFeb 19, 2019
  14. brian m. carlsonFeb 21, 2019
  15. Ævar Arnfjörð BjarmasonFeb 22, 2019
  16. Junio C HamanoDec 5, 2018
  17. Junio C HamanoDec 5, 2018
  18. Jonathan TanDec 6, 2018
  19. Ævar Arnfjörð BjarmasonFeb 19, 2019
  20. Jonathan TanFeb 19, 2019
  21. 3/5 upload-pack: refactor reading of pack-objects outJonathan Tan, Dec 3, 2018
  22. Stefan BellerDec 4, 2018
  23. Junio C HamanoDec 5, 2018
  24. 4/5 upload-pack: refactor writing of "packfile" lineJonathan Tan, Dec 3, 2018
  25. Junio C HamanoDec 6, 2018
  26. Jonathan TanDec 6, 2018
  27. Junio C HamanoDec 7, 2018
  28. 5/5 upload-pack: send part of packfile response as uriJonathan Tan, Dec 3, 2018
  29. Stefan BellerDec 4, 2018
  30. Stefan BellerDec 4, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.