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

Record more details about where a write is taking place while holding a cluster lock

Summary: Ref T4292. This will let the UI and future `bin/repository` tools give administrators more tools to understand problems when reporting or resolving them.

Test Plan:
  - Pushed fully clean repository.
  - Pushed previously-pushed repository.
  - Forced write to abort, inspected useful information in the database.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T4292

Differential Revision: https://secure.phabricator.com/D15748
This commit is contained in:
epriestley 2016-04-18 08:26:40 -07:00
parent 368d2d1ddb
commit f424f9f2d2
4 changed files with 29 additions and 9 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_repository.repository_workingcopyversion
ADD writeProperties LONGTEXT COLLATE {$COLLATE_TEXT};

View file

@ -26,7 +26,8 @@ final class DiffusionGitReceivePackSSHWorkflow extends DiffusionGitSSHWorkflow {
$command = csprintf('git-receive-pack %s', $repository->getLocalPath());
$did_synchronize = true;
$repository->synchronizeWorkingCopyBeforeWrite();
$viewer = $this->getUser();
$repository->synchronizeWorkingCopyBeforeWrite($viewer);
}
$caught = null;

View file

@ -2482,7 +2482,8 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
/**
* @task sync
*/
public function synchronizeWorkingCopyBeforeWrite() {
public function synchronizeWorkingCopyBeforeWrite(
PhabricatorUser $actor) {
if (!$this->shouldEnableSynchronization()) {
return;
}
@ -2516,7 +2517,12 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
PhabricatorRepositoryWorkingCopyVersion::willWrite(
$repository_phid,
$device_phid);
$device_phid,
array(
'userPHID' => $actor->getPHID(),
'epoch' => PhabricatorTime::getNow(),
'devicePHID' => $device_phid,
));
$this->clusterWriteVersion = $max_version;
$this->clusterWriteLock = $write_lock;

View file

@ -7,6 +7,7 @@ final class PhabricatorRepositoryWorkingCopyVersion
protected $devicePHID;
protected $repositoryVersion;
protected $isWriting;
protected $writeProperties;
protected function getConfiguration() {
return array(
@ -14,6 +15,7 @@ final class PhabricatorRepositoryWorkingCopyVersion
self::CONFIG_COLUMN_SCHEMA => array(
'repositoryVersion' => 'uint32',
'isWriting' => 'bool',
'writeProperties' => 'text?',
),
self::CONFIG_KEY_SCHEMA => array(
'key_workingcopy' => array(
@ -66,7 +68,10 @@ final class PhabricatorRepositoryWorkingCopyVersion
* lock is released by default. This is a durable lock which stays locked
* by default.
*/
public static function willWrite($repository_phid, $device_phid) {
public static function willWrite(
$repository_phid,
$device_phid,
array $write_properties) {
$version = new self();
$conn_w = $version->establishConnection('w');
$table = $version->getTableName();
@ -74,16 +79,19 @@ final class PhabricatorRepositoryWorkingCopyVersion
queryfx(
$conn_w,
'INSERT INTO %T
(repositoryPHID, devicePHID, repositoryVersion, isWriting)
(repositoryPHID, devicePHID, repositoryVersion, isWriting,
writeProperties)
VALUES
(%s, %s, %d, %d)
(%s, %s, %d, %d, %s)
ON DUPLICATE KEY UPDATE
isWriting = VALUES(isWriting)',
isWriting = VALUES(isWriting),
writeProperties = VALUES(writeProperties)',
$table,
$repository_phid,
$device_phid,
0,
1);
1,
phutil_json_encode($write_properties));
}
@ -101,7 +109,10 @@ final class PhabricatorRepositoryWorkingCopyVersion
queryfx(
$conn_w,
'UPDATE %T SET repositoryVersion = %d, isWriting = 0
'UPDATE %T SET
repositoryVersion = %d,
isWriting = 0,
writeProperties = null
WHERE
repositoryPHID = %s AND
devicePHID = %s AND