Differential D21669 Diff 51572 src/applications/diffusion/protocol/DiffusionRepositoryClusterEngine.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/protocol/DiffusionRepositoryClusterEngine.php
<?php | <?php | ||||
/** | /** | ||||
* Manages repository synchronization for cluster repositories. | * Manages repository synchronization for cluster repositories. | ||||
* | * | ||||
* @task config Configuring Synchronization | * @task config Configuring Synchronization | ||||
* @task sync Cluster Synchronization | * @task sync Cluster Synchronization | ||||
* @task internal Internals | * @task internal Internals | ||||
*/ | */ | ||||
final class DiffusionRepositoryClusterEngine extends Phobject { | final class DiffusionRepositoryClusterEngine extends Phobject { | ||||
private $repository; | private $repository; | ||||
private $viewer; | private $viewer; | ||||
private $actingAsPHID; | |||||
private $logger; | private $logger; | ||||
private $clusterWriteLock; | private $clusterWriteLock; | ||||
private $clusterWriteVersion; | private $clusterWriteVersion; | ||||
private $clusterWriteOwner; | private $clusterWriteOwner; | ||||
/* -( Configuring Synchronization )---------------------------------------- */ | /* -( Configuring Synchronization )---------------------------------------- */ | ||||
Show All 17 Lines | public function getViewer() { | ||||
return $this->viewer; | return $this->viewer; | ||||
} | } | ||||
public function setLog(DiffusionRepositoryClusterEngineLogInterface $log) { | public function setLog(DiffusionRepositoryClusterEngineLogInterface $log) { | ||||
$this->logger = $log; | $this->logger = $log; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setActingAsPHID($acting_as_phid) { | |||||
$this->actingAsPHID = $acting_as_phid; | |||||
return $this; | |||||
} | |||||
public function getActingAsPHID() { | |||||
return $this->actingAsPHID; | |||||
} | |||||
private function getEffectiveActingAsPHID() { | |||||
if ($this->actingAsPHID) { | |||||
return $this->actingAsPHID; | |||||
} | |||||
return $this->getViewer()->getPHID(); | |||||
} | |||||
/* -( Cluster Synchronization )-------------------------------------------- */ | /* -( Cluster Synchronization )-------------------------------------------- */ | ||||
/** | /** | ||||
* Synchronize repository version information after creating a repository. | * Synchronize repository version information after creating a repository. | ||||
* | * | ||||
* This initializes working copy versions for all currently bound devices to | * This initializes working copy versions for all currently bound devices to | ||||
▲ Show 20 Lines • Show All 342 Lines • ▼ Show 20 Lines | public function synchronizeWorkingCopyBeforeWrite() { | ||||
$hash = Filesystem::readRandomCharacters(12); | $hash = Filesystem::readRandomCharacters(12); | ||||
$this->clusterWriteOwner = "{$pid}.{$hash}"; | $this->clusterWriteOwner = "{$pid}.{$hash}"; | ||||
PhabricatorRepositoryWorkingCopyVersion::willWrite( | PhabricatorRepositoryWorkingCopyVersion::willWrite( | ||||
$locked_connection, | $locked_connection, | ||||
$repository_phid, | $repository_phid, | ||||
$device_phid, | $device_phid, | ||||
array( | array( | ||||
'userPHID' => $viewer->getPHID(), | 'userPHID' => $this->getEffectiveActingAsPHID(), | ||||
'epoch' => PhabricatorTime::getNow(), | 'epoch' => PhabricatorTime::getNow(), | ||||
'devicePHID' => $device_phid, | 'devicePHID' => $device_phid, | ||||
), | ), | ||||
$this->clusterWriteOwner); | $this->clusterWriteOwner); | ||||
$this->clusterWriteVersion = $max_version; | $this->clusterWriteVersion = $max_version; | ||||
$this->clusterWriteLock = $write_lock; | $this->clusterWriteLock = $write_lock; | ||||
Show All 14 Lines | public function synchronizeWorkingCopyAfterDiscovery($new_version) { | ||||
} | } | ||||
$repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
$repository_phid = $repository->getPHID(); | $repository_phid = $repository->getPHID(); | ||||
if ($repository->isHosted()) { | if ($repository->isHosted()) { | ||||
return; | return; | ||||
} | } | ||||
$viewer = $this->getViewer(); | |||||
$device = AlmanacKeys::getLiveDevice(); | $device = AlmanacKeys::getLiveDevice(); | ||||
$device_phid = $device->getPHID(); | $device_phid = $device->getPHID(); | ||||
// NOTE: We are not holding a lock here because this method is only called | // NOTE: We are not holding a lock here because this method is only called | ||||
// from PhabricatorRepositoryDiscoveryEngine, which already holds a device | // from PhabricatorRepositoryDiscoveryEngine, which already holds a device | ||||
// lock. Even if we do race here and record an older version, the | // lock. Even if we do race here and record an older version, the | ||||
// consequences are mild: we only do extra work to correct it later. | // consequences are mild: we only do extra work to correct it later. | ||||
▲ Show 20 Lines • Show All 443 Lines • Show Last 20 Lines |