From f59bb63746924d44aecc1a0c65902292736360c6 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Wed, 10 Jun 2020 12:18:11 -0700 Subject: [PATCH] git-svn gc: acquire a `gc.pid` lock for any packing activities It really should not be possible for any kind of gc to run on an svn mirror project while a clone/update operation is in progress. It really shouldn't. Nevertheless, do the right thing and acquire a `gc.pic` lock for the duration of any packing operations. Since, strictly speaking, no packing is actually required during a clone or update of a `git-svn` mirror, failure to acquire the lock only results in the packing operation being skipped rather than an outright failure. Signed-off-by: Kyle J. McKay --- jobd/gc-git-svn.sh | 7 +++++-- jobd/gc-util-functions.sh | 18 +++++++++++++++++- taskd/clone.sh | 3 ++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/jobd/gc-git-svn.sh b/jobd/gc-git-svn.sh index 1dbecc2..15397cc 100755 --- a/jobd/gc-git-svn.sh +++ b/jobd/gc-git-svn.sh @@ -34,8 +34,11 @@ proj="${proj%.git}" if lotsa_loose_pruned_objects; then echo "Packing loose objects ($(date))" - pack_incremental_loose_objects - echo "Packing and pruning complete ($(date))" + if pack_incremental_loose_objects_if_lockable; then + echo "Packing and pruning complete ($(date))" + else + echo "Packing skipped: $lockerr ($(date))" + fi fi exit 0 diff --git a/jobd/gc-util-functions.sh b/jobd/gc-util-functions.sh index 7feb14f..66952c2 100755 --- a/jobd/gc-util-functions.sh +++ b/jobd/gc-util-functions.sh @@ -163,10 +163,12 @@ lotsa_loose_objects() { [ ${_objs:-0} -ge 5 ] } -# same as lotsa_loose_objects but first runs `git prune-packed` +# same as lotsa_loose_objects but first runs `git prune-packed` if it can get a gc lock lotsa_loose_pruned_objects() { lotsa_loose_objects || return $? + v_lock_gc _gclock || return 0 git prune-packed --quiet + rm -f "$_gclock" lotsa_loose_objects } @@ -195,6 +197,20 @@ pack_incremental_loose_objects() { } } +# same as pack_incremental_loose_objects except +# returns true if locked and packed and unlocked or +# false if could not lock (with err in $lockerr) +pack_incremental_loose_objects_if_lockable() { + if v_lock_gc _gclock; then + pack_incremental_loose_objects || : + rm -f "$_gclock" + return 0 + else + lockerr="$_gclock" + return 1 + fi +} + # combine small _l packs into larger pack(s) using --weak-naming # we avoid any non _l, keep, bndl or bitmap packs combine_small_incremental_loose_packs() { diff --git a/taskd/clone.sh b/taskd/clone.sh index 44646d6..a91f868 100755 --- a/taskd/clone.sh +++ b/taskd/clone.sh @@ -405,7 +405,8 @@ case "$url" in else pausestop="$(( $(date '+%s') + 120 ))" echo 'Pausing and packing loose objects for 120 seconds before retrying' - pack_incremental_loose_objects + pack_incremental_loose_objects_if_lockable || + echo "Packing skipped: $lockerr" timenow="$(date '+%s')" if [ "$timenow" -lt "$pausestop" ]; then sleepamt="$(( $pausestop - $timenow ))" -- 2.11.4.GIT