git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org, Ramkumar Ramachandra <artagnon@gmail.com>,
	Johannes Sixt <j6t@kdbg.org>
Subject: Re: [PATCH v4] gc: reject if another gc is running, unless --force is given
Date: Thu, 08 Aug 2013 11:12:53 -0700	[thread overview]
Message-ID: <7vk3jw9hlm.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <1375959938-6395-1-git-send-email-pclouds@gmail.com> ("Nguyễn	Thái Ngọc Duy"'s message of "Thu, 8 Aug 2013 18:05:38 +0700")

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> 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.

  reply	other threads:[~2013-08-08 18:13 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-03  4:20 [PATCH] gc: reject if another gc is running, unless --force is given Nguyễn Thái Ngọc Duy
2013-08-03  6:21 ` [PATCH v2] " Nguyễn Thái Ngọc Duy
2013-08-03  7:52   ` Ramkumar Ramachandra
2013-08-03 10:01     ` Duy Nguyen
2013-08-03  9:49   ` Johannes Sixt
2013-08-03 10:01     ` Duy Nguyen
2013-08-03 10:40       ` Johannes Sixt
2013-08-05 14:19   ` [PATCH v3] " Nguyễn Thái Ngọc Duy
2013-08-05 18:17     ` Junio C Hamano
2013-08-05 18:37       ` Ramkumar Ramachandra
2013-08-06  6:43         ` Junio C Hamano
2013-08-06  6:45           ` Ramkumar Ramachandra
2013-08-08 11:05     ` [PATCH v4] " Nguyễn Thái Ngọc Duy
2013-08-08 18:12       ` Junio C Hamano [this message]
2013-08-09 12:52         ` Duy Nguyen
2013-08-09 16:00           ` Junio C Hamano
2013-08-09 16:29       ` Andres Perera
2013-08-09 17:41         ` Junio C Hamano
2013-08-10  0:45         ` Duy Nguyen
2013-08-10  7:11           ` Andreas Schwab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vk3jw9hlm.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=artagnon@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    --cc=pclouds@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).