Differential D18273 Diff 43953 src/applications/diffusion/protocol/DiffusionRepositoryClusterEngine.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/protocol/DiffusionRepositoryClusterEngine.php
| Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | /* -( Cluster Synchronization )-------------------------------------------- */ | ||||
| * | * | ||||
| * This initializes working copy versions for all currently bound devices to | * This initializes working copy versions for all currently bound devices to | ||||
| * 0, so that we don't get stuck making an ambiguous choice about which | * 0, so that we don't get stuck making an ambiguous choice about which | ||||
| * devices are leaders when we later synchronize before a read. | * devices are leaders when we later synchronize before a read. | ||||
| * | * | ||||
| * @task sync | * @task sync | ||||
| */ | */ | ||||
| public function synchronizeWorkingCopyAfterCreation() { | public function synchronizeWorkingCopyAfterCreation() { | ||||
| if (!$this->shouldEnableSynchronization()) { | if (!$this->shouldEnableSynchronization(false)) { | ||||
| return; | return; | ||||
| } | } | ||||
| $repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
| $repository_phid = $repository->getPHID(); | $repository_phid = $repository->getPHID(); | ||||
| $service = $repository->loadAlmanacService(); | $service = $repository->loadAlmanacService(); | ||||
| if (!$service) { | if (!$service) { | ||||
| Show All 11 Lines | public function synchronizeWorkingCopyAfterCreation() { | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| /** | /** | ||||
| * @task sync | * @task sync | ||||
| */ | */ | ||||
| public function synchronizeWorkingCopyAfterHostingChange() { | public function synchronizeWorkingCopyAfterHostingChange() { | ||||
| if (!$this->shouldEnableSynchronization()) { | if (!$this->shouldEnableSynchronization(false)) { | ||||
| return; | return; | ||||
| } | } | ||||
| $repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
| $repository_phid = $repository->getPHID(); | $repository_phid = $repository->getPHID(); | ||||
| $versions = PhabricatorRepositoryWorkingCopyVersion::loadVersions( | $versions = PhabricatorRepositoryWorkingCopyVersion::loadVersions( | ||||
| $repository_phid); | $repository_phid); | ||||
| Show All 30 Lines | public function synchronizeWorkingCopyAfterHostingChange() { | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| /** | /** | ||||
| * @task sync | * @task sync | ||||
| */ | */ | ||||
| public function synchronizeWorkingCopyBeforeRead() { | public function synchronizeWorkingCopyBeforeRead() { | ||||
| if (!$this->shouldEnableSynchronization()) { | if (!$this->shouldEnableSynchronization(true)) { | ||||
| return; | return; | ||||
| } | } | ||||
| $repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
| $repository_phid = $repository->getPHID(); | $repository_phid = $repository->getPHID(); | ||||
| $device = AlmanacKeys::getLiveDevice(); | $device = AlmanacKeys::getLiveDevice(); | ||||
| $device_phid = $device->getPHID(); | $device_phid = $device->getPHID(); | ||||
| ▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | public function synchronizeWorkingCopyBeforeRead() { | ||||
| return $result_version; | return $result_version; | ||||
| } | } | ||||
| /** | /** | ||||
| * @task sync | * @task sync | ||||
| */ | */ | ||||
| public function synchronizeWorkingCopyBeforeWrite() { | public function synchronizeWorkingCopyBeforeWrite() { | ||||
| if (!$this->shouldEnableSynchronization()) { | if (!$this->shouldEnableSynchronization(true)) { | ||||
| return; | return; | ||||
| } | } | ||||
| $repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $repository_phid = $repository->getPHID(); | $repository_phid = $repository->getPHID(); | ||||
| ▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | PhabricatorRepositoryWorkingCopyVersion::willWrite( | ||||
| $this->clusterWriteOwner); | $this->clusterWriteOwner); | ||||
| $this->clusterWriteVersion = $max_version; | $this->clusterWriteVersion = $max_version; | ||||
| $this->clusterWriteLock = $write_lock; | $this->clusterWriteLock = $write_lock; | ||||
| } | } | ||||
| public function synchronizeWorkingCopyAfterDiscovery($new_version) { | public function synchronizeWorkingCopyAfterDiscovery($new_version) { | ||||
| if (!$this->shouldEnableSynchronization()) { | if (!$this->shouldEnableSynchronization(true)) { | ||||
| return; | return; | ||||
| } | } | ||||
| $repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
| $repository_phid = $repository->getPHID(); | $repository_phid = $repository->getPHID(); | ||||
| if ($repository->isHosted()) { | if ($repository->isHosted()) { | ||||
| return; | return; | ||||
| } | } | ||||
| Show All 27 Lines | public function synchronizeWorkingCopyAfterDiscovery($new_version) { | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * @task sync | * @task sync | ||||
| */ | */ | ||||
| public function synchronizeWorkingCopyAfterWrite() { | public function synchronizeWorkingCopyAfterWrite() { | ||||
| if (!$this->shouldEnableSynchronization()) { | if (!$this->shouldEnableSynchronization(true)) { | ||||
| return; | return; | ||||
| } | } | ||||
| if (!$this->clusterWriteLock) { | if (!$this->clusterWriteLock) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Trying to synchronize after write, but not holding a write '. | 'Trying to synchronize after write, but not holding a write '. | ||||
| 'lock!')); | 'lock!')); | ||||
| ▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | |||||
| /* -( Internals )---------------------------------------------------------- */ | /* -( Internals )---------------------------------------------------------- */ | ||||
| /** | /** | ||||
| * @task internal | * @task internal | ||||
| */ | */ | ||||
| private function shouldEnableSynchronization() { | private function shouldEnableSynchronization($require_device) { | ||||
| $repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
| $service_phid = $repository->getAlmanacServicePHID(); | $service_phid = $repository->getAlmanacServicePHID(); | ||||
| if (!$service_phid) { | if (!$service_phid) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (!$repository->supportsSynchronization()) { | if (!$repository->supportsSynchronization()) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if ($require_device) { | |||||
| $device = AlmanacKeys::getLiveDevice(); | $device = AlmanacKeys::getLiveDevice(); | ||||
| if (!$device) { | if (!$device) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | |||||
| return true; | return true; | ||||
| } | } | ||||
| /** | /** | ||||
| * @task internal | * @task internal | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 187 Lines • Show Last 20 Lines | |||||