1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 00:32:42 +01:00

Don't require a device be registered in Almanac to do cluster init/resync steps

Summary:
Fixes T12893. See also PHI15. This is complicated but:

  - In the documentation, we say "register your web devices with Almanac". We do this ourselves on `secure` and in the production Phacility cluster.
  - We don't actually require you to do this, don't detect that you didn't, and there's no actual reason you need to.
  - If you don't register your "web" devices, the only bad thing that really happens is that creating repositories skips version initialization, creating the bug in T12893. This process does not actually require the devices be registered, but the code currently just kind of fails silently if they aren't.

Instead, just move forward on these init/resync phases even if the device isn't registered. These steps are safe to run from unregistered hosts since they just wipe the whole table and don't affect specific devices.

If this sticks, I'll probably update the docs to not tell you to register `web` devices, or at least add "Optionally, ...". I don't think there's any future reason we'd need them to be registered.

Test Plan:
This is a bit tough to test without multiple hosts, but I added this piece of code to `AlmanacKeys` so we'd pretend to be a nameless "web" device when creating a repository:

```
if ($_REQUEST['__path__'] == '/diffusion/edit/form/default/') {
  return null;
}
```

Then I created some Git repositories. Before the patch, they came up with `-` versions (no version information). After the patch, they came up with `0` versions (correctly initialized).

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12893

Differential Revision: https://secure.phabricator.com/D18273
This commit is contained in:
epriestley 2017-07-24 11:37:04 -07:00
parent 69a7d57c3f
commit 8034b9d819

View file

@ -58,7 +58,7 @@ final class DiffusionRepositoryClusterEngine extends Phobject {
* @task sync
*/
public function synchronizeWorkingCopyAfterCreation() {
if (!$this->shouldEnableSynchronization()) {
if (!$this->shouldEnableSynchronization(false)) {
return;
}
@ -86,7 +86,7 @@ final class DiffusionRepositoryClusterEngine extends Phobject {
* @task sync
*/
public function synchronizeWorkingCopyAfterHostingChange() {
if (!$this->shouldEnableSynchronization()) {
if (!$this->shouldEnableSynchronization(false)) {
return;
}
@ -133,7 +133,7 @@ final class DiffusionRepositoryClusterEngine extends Phobject {
* @task sync
*/
public function synchronizeWorkingCopyBeforeRead() {
if (!$this->shouldEnableSynchronization()) {
if (!$this->shouldEnableSynchronization(true)) {
return;
}
@ -288,7 +288,7 @@ final class DiffusionRepositoryClusterEngine extends Phobject {
* @task sync
*/
public function synchronizeWorkingCopyBeforeWrite() {
if (!$this->shouldEnableSynchronization()) {
if (!$this->shouldEnableSynchronization(true)) {
return;
}
@ -382,7 +382,7 @@ final class DiffusionRepositoryClusterEngine extends Phobject {
public function synchronizeWorkingCopyAfterDiscovery($new_version) {
if (!$this->shouldEnableSynchronization()) {
if (!$this->shouldEnableSynchronization(true)) {
return;
}
@ -426,7 +426,7 @@ final class DiffusionRepositoryClusterEngine extends Phobject {
* @task sync
*/
public function synchronizeWorkingCopyAfterWrite() {
if (!$this->shouldEnableSynchronization()) {
if (!$this->shouldEnableSynchronization(true)) {
return;
}
@ -551,7 +551,7 @@ final class DiffusionRepositoryClusterEngine extends Phobject {
/**
* @task internal
*/
private function shouldEnableSynchronization() {
private function shouldEnableSynchronization($require_device) {
$repository = $this->getRepository();
$service_phid = $repository->getAlmanacServicePHID();
@ -563,9 +563,11 @@ final class DiffusionRepositoryClusterEngine extends Phobject {
return false;
}
$device = AlmanacKeys::getLiveDevice();
if (!$device) {
return false;
if ($require_device) {
$device = AlmanacKeys::getLiveDevice();
if (!$device) {
return false;
}
}
return true;