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

Re: [PATCH v4] gc: reject if another gc is running, unless --force is given

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 8, 2013, 18:12 UTC
Message-ID
<7vk3jw9hlm.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1375959938-6395-1-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
Show 27 quoted lines
> diff --git a/builtin/gc.c b/builtin/gc.c
> index 6be6c8d..99682f0 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -167,11 +167,69 @@ static int need_to_gc(void)
> + ...
> +	fd = hold_lock_file_for_update(&lock, git_path("gc.pid"),
> +				       LOCK_DIE_ON_ERROR);
> +	if (!force) {
> +		fp = fopen(git_path("gc.pid"), "r");
> +		memset(locking_host, 0, sizeof(locking_host));
> +		should_exit =
> +			fp != NULL &&
> +			!fstat(fileno(fp), &st) &&
> +			/*
> +			 * 12 hour limit is very generous as gc should
> +			 * never take that long. On the other hand we
> +			 * don't really need a strict limit here,
> +			 * running gc --auto one day late is not a big
> +			 * problem. --force can be used in manual gc
> +			 * after the user verifies that no gc is
> +			 * running.
> +			 */
> +			time(NULL) - st.st_mtime <= 12 * 3600 &&
> +			fscanf(fp, "%"PRIuMAX" %127c", &pid, locking_host) == 2 &&
> +			!strcmp(locking_host, my_host) &&
> +			!kill(pid, 0);

If there is a lockfile we can read, and if we can positively determine that the process named in the lockfile is still running, then we definitely do not want to do another "gc". That part is good.

If the lock is very stale, 12-hour test will kick in, and we do not read who locked it, nor check if the locker is still alive. By doing so, we avoid misidentifying a new process that is unrelated to the locker who died and left the lockfile behind, which is a good thing. The logic to ignore such lockfile as "unknown" applies equally to a remote locker on a lockfile that is old. So the logic for an old lockfile is good, too.

When we see a recent lockfile created by a "gc" running elsewhere, we do not set "should_exit". Is that a good thing? I am wondering if the last two lines should be:

- !strcmp(locking_host, my_host) && - !kill(pid, 0); + (strcmp(locking_host, my_host) || !kill(pid, 0));

instead.
Thanks, looking good.
Previous: Nguyễn Thái Ngọc DuyNext: Duy Nguyen
Message 14 of 20 in “gc: reject if another gc is running, unless --force is given”
  1. gc: reject if another gc is running, unless --force is givenNguyễn Thái Ngọc Duy, Aug 3, 2013
  2. gc: reject if another gc is running, unless --force is givenNguyễn Thái Ngọc Duy, Aug 3, 2013
  3. Ramkumar RamachandraAug 3, 2013
  4. Duy NguyenAug 3, 2013
  5. Johannes SixtAug 3, 2013
  6. Duy NguyenAug 3, 2013
  7. Johannes SixtAug 3, 2013
  8. gc: reject if another gc is running, unless --force is givenNguyễn Thái Ngọc Duy, Aug 5, 2013
  9. Junio C HamanoAug 5, 2013
  10. Ramkumar RamachandraAug 5, 2013
  11. Junio C HamanoAug 6, 2013
  12. Ramkumar RamachandraAug 6, 2013
  13. gc: reject if another gc is running, unless --force is givenNguyễn Thái Ngọc Duy, Aug 8, 2013
  14. Junio C HamanoAug 8, 2013
  15. Duy NguyenAug 9, 2013
  16. Junio C HamanoAug 9, 2013
  17. Andres PereraAug 9, 2013
  18. Junio C HamanoAug 9, 2013
  19. Duy NguyenAug 10, 2013
  20. Andreas SchwabAug 10, 2013

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.