1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-18 11:30:55 +01:00

Hold a lock while collecting garbage

Summary:
Fixes T11771. Adds a lock around each GC process so we don't try to, e.g., delete old files on two machines at once just because they're both running trigger daemons.

The other aspects of this daemon (actual triggers; nuance importers) already have separate locks.

Test Plan: Ran `bin/phd debug trigger --trace`, saw daemon acquire locks and collect garbage.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11771

Differential Revision: https://secure.phabricator.com/D16739
This commit is contained in:
epriestley 2016-10-20 11:36:31 -07:00
parent 272046ae77
commit 7678f412be

View file

@ -98,7 +98,27 @@ abstract class PhabricatorGarbageCollector extends Phobject {
}
}
return $this->collectGarbage();
// Hold a lock while performing collection to avoid racing other daemons
// running the same collectors.
$lock_name = 'gc:'.$this->getCollectorConstant();
$lock = PhabricatorGlobalLock::newLock($lock_name);
try {
$lock->lock(5);
} catch (PhutilLockException $ex) {
return false;
}
try {
$result = $this->collectGarbage();
} catch (Exception $ex) {
$lock->unlock();
throw $ex;
}
$lock->unlock();
return $result;
}