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

Re: [PATCH 1/2] prepare_packed_git(): refactor garbage reporting in pack directory

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 13, 2016, 20:08 UTC
Message-ID
<xmqqvb6xmedw.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<CAEtYS8Qs2B3rP1PDGhoWGAgcj2c_pOTpt=s8qj9tWMjkLLFyhQ@mail.gmail.com>
Doug Kelly <dougk.ff7@gmail.com> writes:
Show 6 quoted lines
> Yeah, I know I never got to adding the mtime logic, but for a simple (naive,
> hard-coded) case, I did come up with a basic patch today.  I think this could
> be extended to a configuration option(?) which would allow a default longer
> than 10 seconds (an hour? a day?), then during the regression tests, we
> could provide a shorter timeout to ensure the guarding both works and also
> not wait forever for tests to complete.  Thoughts?

Please do not sleep in the tests. Instead, please try to see if you can use test-chmtime to set the timestamps of these files to the necessary ages for the purpose of your tests.

Thanks.
Show 52 quoted lines
>
> ---
>  builtin/gc.c     | 14 ++++++++++++--
>  t/t5304-prune.sh |  2 ++
>  2 files changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/gc.c b/builtin/gc.c
> index 79e9886..a4ce616 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -51,8 +51,18 @@ static struct string_list pack_garbage =
> STRING_LIST_INIT_DUP;
>  static void clean_pack_garbage(void)
>  {
>   int i;
> - for (i = 0; i < pack_garbage.nr; i++)
> - unlink_or_warn(pack_garbage.items[i].string);
> + /* Define a cutoff time for "new" garbage to prevent race conditions */
> + time_t cutoff = time(NULL) - 10;
> + for (i = 0; i < pack_garbage.nr; i++) {
> + struct stat s;
> + char *garbage = pack_garbage.items[i].string;
> + if (!stat(garbage, &s)) {
> + if (s.st_mtime < cutoff)
> + unlink_or_warn(garbage);
> + } else
> + fprintf(stderr, _("stat failed on pack garbage: %s"),
> + garbage);
> + }
>   string_list_clear(&pack_garbage, 0);
>  }
>
> diff --git a/t/t5304-prune.sh b/t/t5304-prune.sh
> index cbcc0c0..7b4650f 100755
> --- a/t/t5304-prune.sh
> +++ b/t/t5304-prune.sh
> @@ -272,6 +272,7 @@ test_expect_success 'clean pack garbage with gc' '
>   : >.git/objects/pack/fake6.keep &&
>   : >.git/objects/pack/fake6.bitmap &&
>   : >.git/objects/pack/fake6.idx &&
> + sleep 10 &&
>   git gc &&
>   git count-objects -v 2>stderr &&
>   grep "^warning:" stderr | sort >actual &&
> @@ -291,6 +292,7 @@ test_expect_success 'ensure unknown garbage kept with gc' '
>   : >.git/objects/pack/foo.keep &&
>   : >.git/objects/pack/fake.pack &&
>   : >.git/objects/pack/fake2.foo &&
> + sleep 10 &&
>   git gc &&
>   git count-objects -v 2>stderr &&
>   grep "^warning:" stderr | sort >actual &&
Previous: Doug KellyNext: Doug Kelly
Message 29 of 34 in “Question: .idx without .pack causes performance issues?”
  1. Doug KellyJul 21, 2015
  2. Junio C HamanoJul 21, 2015
  3. Junio C HamanoJul 21, 2015
  4. Junio C HamanoJul 21, 2015
  5. Doug KellyJul 21, 2015
  6. Doug KellyAug 3, 2015
  7. Junio C HamanoAug 4, 2015
  8. Doug KellyAug 7, 2015
  9. Junio C HamanoAug 7, 2015
  10. 1/2 prepare_packed_git(): refactor garbage reporting in pack directoryDoug Kelly, Aug 13, 2015
  11. 2/2 gc: Remove garbage .idx files from pack dirDoug Kelly, Aug 13, 2015
  12. Junio C HamanoAug 17, 2015
  13. Junio C HamanoAug 17, 2015
  14. Eric SunshineAug 13, 2015
  15. Junio C HamanoAug 17, 2015
  16. Junio C HamanoOct 28, 2015
  17. Doug KellyOct 28, 2015
  18. 1/3 prepare_packed_git(): refactor garbage reporting in pack directoryDoug Kelly, Nov 4, 2015
  19. 2/3 t5304: Add test for cleaning pack garbageDoug Kelly, Nov 4, 2015
  20. 3/3 gc: Remove garbage .idx files from pack dirDoug Kelly, Nov 4, 2015
  21. Doug KellyNov 4, 2015
  22. Junio C HamanoNov 4, 2015
  23. Doug KellyNov 4, 2015
  24. Jeff KingNov 4, 2015
  25. Doug KellyNov 4, 2015
  26. Jeff KingNov 4, 2015
  27. Jeff KingDec 30, 2015
  28. Doug KellyJan 13, 2016
  29. Junio C HamanoJan 13, 2016
  30. Doug KellyJan 13, 2016
  31. Jeff KingJan 13, 2016
  32. Jeff KingNov 4, 2015
  33. Doug KellyJul 21, 2015
  34. Fwd: Question: .idx without .pack causes performance issues?Thomas Berg, Nov 11, 2015

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.