Git development
 help / color / mirror / Atom feed
* [RFC,PATCH] Make git prune remove temporary packs that look like write failures
@ 2008-02-04 14:10 David Tweed
  2008-02-04 14:52 ` Nicolas Pitre
  2008-02-04 15:16 ` Johannes Schindelin
  0 siblings, 2 replies; 11+ messages in thread
From: David Tweed @ 2008-02-04 14:10 UTC (permalink / raw)
  To: gi mailing list, Nicolas Pitre

Make git prune remove temporary packs that look like write failures

Write errors when repacking (eg, due to out-of-space conditions)
can leave temporary packs lying around which no existing
codepath removes and  which aren't obvious to the casual user.
Unfortunately the only way to tell in builtin-prune that a tmp_pack file is
of this sort is that it hasn't been modified recently. We assume a pack
which hasn't been modified within 10 minutes is of this sort and
delete it, printing a notification to help debugging. (Nicolas Pitre
suggested this functionality should be activated only by --prune.)

Signed-off-by: David Tweed (david.tweed@gmail.com)
---

I KNOW this initial RFC is mailer whitespace damaged. Finally version won't be.

In principle this is a really trivial patch, but I'm being cautious because I
don't like the fact that I don't know (and AFAICS can't reliably check) that
the files being deleting are definitely dead. An alternative would
be to make prune just print out that the suspicious packs are
there and let the user delete them manually. (My itch is that once
a write-failure pack gets created, nothing in git operations tells the
user that a generally multimegabyte file hidden in .git occupying space.)

 builtin-prune.c |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/builtin-prune.c b/builtin-prune.c
index b5e7684..90111ab 100644
--- a/builtin-prune.c
+++ b/builtin-prune.c
@@ -83,6 +83,39 @@ static void prune_object_dir(const char *path)
        }
 }

+/*
+ * Write errors (particularly out of space) can result in
+ * failed temporary packs accumulating in the object directory.
+ * This removes anything in the object directory beginning
+ * with tmp_ using the heuristic that anything
+ * that was last modified more than 10 minutes
+ * ago is the abandoned result of a write failure.
+ */
+static void remove_temporary_files(void)
+{
+       DIR *dir;
+       struct stat status;
+       time_t now;
+       struct dirent *de;
+       char* dirname=get_object_directory();
+
+       now = time(NULL);
+       dir = opendir(dirname);
+       while ((de = readdir(dir)) != NULL) {
+               if(strncmp(de->d_name, "tmp_", 4) == 0){
+                       char name[4096];
+                       int c=snprintf(name, 4095, "%s/%s", dirname,
de->d_name);
+                       if(c>0 && c<4096 && stat(name, &status) == 0
+                          && status.st_mtime < now - 600){
+                               printf("Removing apparently abandoned
%s\n",name);
+                               unlink(name);
+                       }
+               }
+       }
+       closedir(dir);
+}
+
+
 int cmd_prune(int argc, const char **argv, const char *prefix)
 {
        int i;
@@ -115,5 +148,6 @@ int cmd_prune(int argc, const char **argv, const
char *prefix)

        sync();
        prune_packed_objects(show_only);
+       remove_temporary_files();
        return 0;
 }

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [RFC,PATCH] Make git prune remove temporary packs that look like write failures
  2008-02-04 14:10 [RFC,PATCH] Make git prune remove temporary packs that look like write failures David Tweed
@ 2008-02-04 14:52 ` Nicolas Pitre
  2008-02-04 15:16 ` Johannes Schindelin
  1 sibling, 0 replies; 11+ messages in thread
From: Nicolas Pitre @ 2008-02-04 14:52 UTC (permalink / raw)
  To: David Tweed; +Cc: gi mailing list

On Mon, 4 Feb 2008, David Tweed wrote:

> In principle this is a really trivial patch, but I'm being cautious because I
> don't like the fact that I don't know (and AFAICS can't reliably check) that
> the files being deleting are definitely dead. An alternative would
> be to make prune just print out that the suspicious packs are
> there and let the user delete them manually. (My itch is that once
> a write-failure pack gets created, nothing in git operations tells the
> user that a generally multimegabyte file hidden in .git occupying space.)

The lifelessness of a temporary pack is the same as for loose objects, 
hence the same rule should apply in both cases.  Just asking the user to 
delete them manually isn't too nice either.  A prune operation is 
already said to be dangerous and should be performed only when no other 
activities are occurring in the same repository.  That should cover the 
case of dead temporary pack files just as well.


Nicolas

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC,PATCH] Make git prune remove temporary packs that look like write failures
  2008-02-04 14:10 [RFC,PATCH] Make git prune remove temporary packs that look like write failures David Tweed
  2008-02-04 14:52 ` Nicolas Pitre
@ 2008-02-04 15:16 ` Johannes Schindelin
  2008-02-04 15:24   ` David Tweed
  2008-02-04 16:06   ` Nicolas Pitre
  1 sibling, 2 replies; 11+ messages in thread
From: Johannes Schindelin @ 2008-02-04 15:16 UTC (permalink / raw)
  To: David Tweed; +Cc: gi mailing list, Nicolas Pitre

Hi,

On Mon, 4 Feb 2008, David Tweed wrote:

> +                       if(c>0 && c<4096 && stat(name, &status) == 0
> +                          && status.st_mtime < now - 600){

Please have spaces after the "if" and before the "{" (just imitate the 
style of the rest of the file).

Also, 10 minutes grace period for any ongoing fetch or repack seems a bit 
arbitrary.  Maybe default to 10 minutes, and introduce 
prune.packGracePeriod?

(Which reminds me that it might be useful to add a 
prune.looseObjectsGracePeriod to avoid having to type --expire= all the 
time?)

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC,PATCH] Make git prune remove temporary packs that look like write failures
  2008-02-04 15:16 ` Johannes Schindelin
@ 2008-02-04 15:24   ` David Tweed
  2008-02-04 17:21     ` Johannes Schindelin
  2008-02-04 16:06   ` Nicolas Pitre
  1 sibling, 1 reply; 11+ messages in thread
From: David Tweed @ 2008-02-04 15:24 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: gi mailing list, Nicolas Pitre

On Feb 4, 2008 3:16 PM, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> Hi,
>
> On Mon, 4 Feb 2008, David Tweed wrote:
>
> > +                       if(c>0 && c<4096 && stat(name, &status) == 0
> > +                          && status.st_mtime < now - 600){
>
> Please have spaces after the "if" and before the "{" (just imitate the
> style of the rest of the file).
>
> Also, 10 minutes grace period for any ongoing fetch or repack seems a bit
> arbitrary.  Maybe default to 10 minutes, and introduce
> prune.packGracePeriod?

In response to this and to Nico's earlier mail, I _think_ the usage
with repack is completely safe. What I'm not sure about is that other
things like git-svn create temporary packs with usage/semantics I'm
not sure about. I'm happy to delete immediately if those who
understand the interactions in the whole of git say that's acceptable
when the user specifically calls git-prune.

-- 
cheers, dave tweed__________________________
david.tweed@gmail.com
Rm 124, School of Systems Engineering, University of Reading.
"while having code so boring anyone can maintain it, use Python." --
attempted insult seen on slashdot

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC,PATCH] Make git prune remove temporary packs that look like write failures
  2008-02-04 15:16 ` Johannes Schindelin
  2008-02-04 15:24   ` David Tweed
@ 2008-02-04 16:06   ` Nicolas Pitre
  2008-02-04 16:33     ` Johannes Schindelin
  1 sibling, 1 reply; 11+ messages in thread
From: Nicolas Pitre @ 2008-02-04 16:06 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: David Tweed, gi mailing list

On Mon, 4 Feb 2008, Johannes Schindelin wrote:

> Hi,
> 
> On Mon, 4 Feb 2008, David Tweed wrote:
> 
> > +                       if(c>0 && c<4096 && stat(name, &status) == 0
> > +                          && status.st_mtime < now - 600){
> 
> Please have spaces after the "if" and before the "{" (just imitate the 
> style of the rest of the file).
> 
> Also, 10 minutes grace period for any ongoing fetch or repack seems a bit 
> arbitrary.  Maybe default to 10 minutes, and introduce 
> prune.packGracePeriod?
> 
> (Which reminds me that it might be useful to add a 
> prune.looseObjectsGracePeriod to avoid having to type --expire= all the 
> time?)

Please use the same parameter for both.  There is no need to have 
separate settings.


Nicolas

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC,PATCH] Make git prune remove temporary packs that look like write failures
  2008-02-04 16:06   ` Nicolas Pitre
@ 2008-02-04 16:33     ` Johannes Schindelin
  0 siblings, 0 replies; 11+ messages in thread
From: Johannes Schindelin @ 2008-02-04 16:33 UTC (permalink / raw)
  To: Nicolas Pitre; +Cc: David Tweed, gi mailing list

Hi,

On Mon, 4 Feb 2008, Nicolas Pitre wrote:

> On Mon, 4 Feb 2008, Johannes Schindelin wrote:
> 
> > On Mon, 4 Feb 2008, David Tweed wrote:
> > 
> > > +                       if(c>0 && c<4096 && stat(name, &status) == 0
> > > +                          && status.st_mtime < now - 600){
> > 
> > Please have spaces after the "if" and before the "{" (just imitate the 
> > style of the rest of the file).
> > 
> > Also, 10 minutes grace period for any ongoing fetch or repack seems a 
> > bit arbitrary.  Maybe default to 10 minutes, and introduce 
> > prune.packGracePeriod?
> > 
> > (Which reminds me that it might be useful to add a 
> > prune.looseObjectsGracePeriod to avoid having to type --expire= all 
> > the time?)
> 
> Please use the same parameter for both.  There is no need to have 
> separate settings.

Right.

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC,PATCH] Make git prune remove temporary packs that look like write failures
  2008-02-04 15:24   ` David Tweed
@ 2008-02-04 17:21     ` Johannes Schindelin
  2008-02-04 17:39       ` David Tweed
  0 siblings, 1 reply; 11+ messages in thread
From: Johannes Schindelin @ 2008-02-04 17:21 UTC (permalink / raw)
  To: David Tweed; +Cc: gi mailing list, Nicolas Pitre

Hi,

On Mon, 4 Feb 2008, David Tweed wrote:

> In response to this and to Nico's earlier mail, I _think_ the usage with 
> repack is completely safe.

It would have been nicer of you to defend that, instead of sending me off 
to look for myself.  Having looked for myself, I am not convinced at all.

And it would have been surprising: if your patch would play nicely with a 
repack in progress, then it would fail to remove the temporary packs left 
by a crashed repack.

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC,PATCH] Make git prune remove temporary packs that look like write failures
  2008-02-04 17:21     ` Johannes Schindelin
@ 2008-02-04 17:39       ` David Tweed
  2008-02-04 17:42         ` David Tweed
  2008-02-04 17:47         ` Nicolas Pitre
  0 siblings, 2 replies; 11+ messages in thread
From: David Tweed @ 2008-02-04 17:39 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: gi mailing list, Nicolas Pitre

On Feb 4, 2008 5:21 PM, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> On Mon, 4 Feb 2008, David Tweed wrote:

> > In response to this and to Nico's earlier mail, I _think_ the usage with
> > repack is completely safe.
>
> It would have been nicer of you to defend that, instead of sending me off
> to look for myself.  Having looked for myself, I am not convinced at all.

I probably ought to have put the underlines around the "I". I'm
convinced, but since this is deleting things I'm more cautious than I
would be, say, parsing options.

> And it would have been surprising: if your patch would play nicely with a
> repack in progress, then it would fail to remove the temporary packs left
> by a crashed repack.

I should been more careful what I said: I only use repack via "git gc"
which calls the repack as a subcommand. If the repack fails then the
whole process dies and you've got a dead tmp pack. The _next_ time you
call "git gc" it will do the repack, finish and then call "git prune"
(assuming --prune) and delete the temporary pack. Used in this way, I
have tried and I cannot see an execution path where this can go wrong.
You're right (and I didn't intend to suggest otherwise) that it would
be safe when running a "git prune" concurrently with a separate "git
repack".

However, I'm not familiar with what things like git-svn, cvs, etc, do.
Given that I've seen patches adding "git gc" periodically during
various imports, I wanted to someone who knows that area to confirm
the patch isn't violating any assumptions.

-- 
cheers, dave tweed__________________________
david.tweed@gmail.com
Rm 124, School of Systems Engineering, University of Reading.
"while having code so boring anyone can maintain it, use Python." --
attempted insult seen on slashdot

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC,PATCH] Make git prune remove temporary packs that look like write failures
  2008-02-04 17:39       ` David Tweed
@ 2008-02-04 17:42         ` David Tweed
  2008-02-04 17:47         ` Nicolas Pitre
  1 sibling, 0 replies; 11+ messages in thread
From: David Tweed @ 2008-02-04 17:42 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: gi mailing list, Nicolas Pitre

Ugh:
On Feb 4, 2008 5:39 PM, David Tweed <david.tweed@gmail.com> wrote:
> You're right (and I didn't intend to suggest otherwise) that it would
> be safe when running a "git prune" concurrently with a separate "git
s/safe/unsafe/
> repack".

-- 
cheers, dave tweed__________________________
david.tweed@gmail.com
Rm 124, School of Systems Engineering, University of Reading.
"while having code so boring anyone can maintain it, use Python." --
attempted insult seen on slashdot

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC,PATCH] Make git prune remove temporary packs that look like write failures
  2008-02-04 17:39       ` David Tweed
  2008-02-04 17:42         ` David Tweed
@ 2008-02-04 17:47         ` Nicolas Pitre
  2008-02-04 17:54           ` David Tweed
  1 sibling, 1 reply; 11+ messages in thread
From: Nicolas Pitre @ 2008-02-04 17:47 UTC (permalink / raw)
  To: David Tweed; +Cc: Johannes Schindelin, gi mailing list

On Mon, 4 Feb 2008, David Tweed wrote:

> However, I'm not familiar with what things like git-svn, cvs, etc, do.
> Given that I've seen patches adding "git gc" periodically during
> various imports, I wanted to someone who knows that area to confirm
> the patch isn't violating any assumptions.

If they're prunning old objects already, they can prune old temporary 
pack files assuming the same level of (non) risk.


Nicolas

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC,PATCH] Make git prune remove temporary packs that look like write failures
  2008-02-04 17:47         ` Nicolas Pitre
@ 2008-02-04 17:54           ` David Tweed
  0 siblings, 0 replies; 11+ messages in thread
From: David Tweed @ 2008-02-04 17:54 UTC (permalink / raw)
  To: Nicolas Pitre; +Cc: Johannes Schindelin, gi mailing list

On Feb 4, 2008 5:47 PM, Nicolas Pitre <nico@cam.org> wrote:
> On Mon, 4 Feb 2008, David Tweed wrote:
> If they're prunning old objects already, they can prune old temporary
> pack files assuming the same level of (non) risk.

Thanks. I'll leave it a day or so, then post a final patch without the
modification time check.

-- 
cheers, dave tweed__________________________
david.tweed@gmail.com
Rm 124, School of Systems Engineering, University of Reading.
"while having code so boring anyone can maintain it, use Python." --
attempted insult seen on slashdot

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-02-04 17:54 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-04 14:10 [RFC,PATCH] Make git prune remove temporary packs that look like write failures David Tweed
2008-02-04 14:52 ` Nicolas Pitre
2008-02-04 15:16 ` Johannes Schindelin
2008-02-04 15:24   ` David Tweed
2008-02-04 17:21     ` Johannes Schindelin
2008-02-04 17:39       ` David Tweed
2008-02-04 17:42         ` David Tweed
2008-02-04 17:47         ` Nicolas Pitre
2008-02-04 17:54           ` David Tweed
2008-02-04 16:06   ` Nicolas Pitre
2008-02-04 16:33     ` Johannes Schindelin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox