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

Re: [PATCHv1 3/3] git-p4: auto-size the block

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jun 5, 2018, 10:05 UTC
Message-ID
<CAPig+cQj1jxgHKMagkX71v3W7KHbkZOrEJ_aceY_LsiSWVt_yw@mail.gmail.com>
In-Reply-To
<20180605091350.14476-4-luke@diamand.org>
On Tue, Jun 5, 2018 at 5:14 AM Luke Diamand <luke@diamand.org> wrote:
Show 29 quoted lines
> git-p4 originally would fetch changes in one query. On large repos this
> could fail because of the limits that Perforce imposes on the number of
> items returned and the number of queries in the database.
>
> To fix this, git-p4 learned to query changes in blocks of 512 changes,
> However, this can be very slow - if you have a few million changes,
> with each chunk taking about a second, it can be an hour or so.
>
> Although it's possible to tune this value manually with the
> "--changes-block-size" option, it's far from obvious to ordinary users
> that this is what needs doing.
>
> This change alters the block size dynamically by looking for the
> specific error messages returned from the Perforce server, and reducing
> the block size if the error is seen, either to the limit reported by the
> server, or to half the current block size.
>
> That means we can start out with a very large block size, and then let
> it automatically drop down to a value that works without error, while
> still failing correctly if some other error occurs.
>
> Signed-off-by: Luke Diamand <luke@diamand.org>
> ---
> diff --git a/git-p4.py b/git-p4.py
> @@ -48,7 +48,8 @@ def __str__(self):
>  # Grab changes in blocks of this many revisions, unless otherwise requested
> -defaultBlockSize = 512
> +# The code should now automatically reduce the block size if it is required
> +defaultBlockSize = 1<<20

As worded, the new comment only has value to someone who knew the old behavior (before this patch), not for someone reading the code fresh. However, if reworded, it might be meaningful to all readers (new and old):

    # The block size is reduced automatically if required
Show 12 quoted lines
> @@ -983,10 +985,24 @@ def p4ChangesForPaths(depotPaths, changeRange, requestedBlockSize):
> +        try:
> +            result = p4CmdList(cmd, errors_as_exceptions=True)
> +        except P4RequestSizeException as e:
> +            if not block_size:
> +                block_size = e.limit
> +            elif block_size > e.limit:
> +                block_size = e.limit
> +            else:
> +                block_size = max(2, block_size // 2)
> +
> +            if verbose: print("block size error, retry with block size {0}".format(block_size))
Perhaps: s/retry/retrying/
Show 11 quoted lines
> diff --git a/t/t9818-git-p4-block.sh b/t/t9818-git-p4-block.sh
> @@ -129,6 +129,7 @@ test_expect_success 'Create a repo with multiple depot paths' '
> +test_expect_success 'Clone repo with self-sizing block size' '
> +       test_when_finished cleanup_git &&
> +       git p4 clone --changes-block-size=1000000 //depot@all --destination="$git" &&
> +       (
> +               cd "$git" &&
> +               git log --oneline > log &&
> +               test_line_count \> 10 log
> +       )
> +'
Or, without a subshell (and dropping whitespace after redirection operator):
    git -C git log --oneline >log &&
    test_line_count \> 10 log
(not worth a re-roll)
Previous: Luke Diamand
Message 10 of 10 in “[PATCHv1 0/3] git-p4: improvements to p4 "blocking"”
  1. Luke DiamandJun 5, 2018
  2. 1/3 git-p4: raise exceptions from p4CmdList based on error from p4 serverLuke Diamand, Jun 5, 2018
  3. Eric SunshineJun 5, 2018
  4. Luke DiamandJun 5, 2018
  5. Eric SunshineJun 5, 2018
  6. Luke DiamandJun 5, 2018
  7. Luke DiamandJun 8, 2018
  8. 2/3 git-p4: narrow the scope of exceptions caught when parsing an intLuke Diamand, Jun 5, 2018
  9. 3/3 git-p4: auto-size the blockLuke Diamand, Jun 5, 2018
  10. Eric SunshineJun 5, 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.