Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Carefully avoid the harbormaster/differential race
Browse files Browse the repository at this point in the history
Summary: Ref T8650. This should stop the problem, but isn't a root cause fix. See discussion on the task.

Test Plan: Made some local diffs, but this is a bit hard to reproduce reliably.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T8650

Differential Revision: https://secure.phabricator.com/D13441
  • Loading branch information
epriestley committed Jun 25, 2015
1 parent 5f99d79 commit db1bc7f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 36 deletions.
Expand Up @@ -585,6 +585,8 @@ protected function applyCustomExternalTransaction(
'a race?'));
}

// TODO: This can race with diff updates, particularly those from
// Harbormaster. See discussion in T8650.
$diff->setRevisionID($object->getID());
$diff->save();

Expand All @@ -593,6 +595,8 @@ protected function applyCustomExternalTransaction(
// the old (`null`) container.

// TODO: This is a bit iffy, maybe we can find a cleaner approach?
// In particular, this could (rarely) be overwritten by Harbormaster
// workers.
$table = new HarbormasterBuildable();
$conn_w = $table->establishConnection('w');
queryfx(
Expand Down
88 changes: 52 additions & 36 deletions src/applications/harbormaster/engine/HarbormasterBuildEngine.php
Expand Up @@ -406,43 +406,59 @@ private function updateBuildable(HarbormasterBuildable $buildable) {
$should_publish = $did_update &&
$new_status != HarbormasterBuildable::STATUS_BUILDING &&
!$buildable->getIsManualBuildable();
if ($should_publish) {
$object = id(new PhabricatorObjectQuery())
->setViewer($viewer)
->withPHIDs(array($buildable->getBuildablePHID()))
->executeOne();

if ($object instanceof PhabricatorApplicationTransactionInterface) {
$template = $object->getApplicationTransactionTemplate();
if ($template) {
$template
->setTransactionType(PhabricatorTransactions::TYPE_BUILDABLE)
->setMetadataValue(
'harbormaster:buildablePHID',
$buildable->getPHID())
->setOldValue($old_status)
->setNewValue($new_status);

$harbormaster_phid = id(new PhabricatorHarbormasterApplication())
->getPHID();

$daemon_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_DAEMON,
array());

$editor = $object->getApplicationTransactionEditor()
->setActor($viewer)
->setActingAsPHID($harbormaster_phid)
->setContentSource($daemon_source)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true);

$editor->applyTransactions(
$object->getApplicationTransactionObject(),
array($template));
}
}

if (!$should_publish) {
return;
}

$object = id(new PhabricatorObjectQuery())
->setViewer($viewer)
->withPHIDs(array($buildable->getBuildablePHID()))
->executeOne();
if (!$object) {
return;
}

if (!($object instanceof PhabricatorApplicationTransactionInterface)) {
return;
}

// TODO: Publishing these transactions is causing a race. See T8650.
// We shouldn't be publishing to diffs anyway.
if ($object instanceof DifferentialDiff) {
return;
}

$template = $object->getApplicationTransactionTemplate();
if (!$template) {
return;
}

$template
->setTransactionType(PhabricatorTransactions::TYPE_BUILDABLE)
->setMetadataValue(
'harbormaster:buildablePHID',
$buildable->getPHID())
->setOldValue($old_status)
->setNewValue($new_status);

$harbormaster_phid = id(new PhabricatorHarbormasterApplication())
->getPHID();

$daemon_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_DAEMON,
array());

$editor = $object->getApplicationTransactionEditor()
->setActor($viewer)
->setActingAsPHID($harbormaster_phid)
->setContentSource($daemon_source)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true);

$editor->applyTransactions(
$object->getApplicationTransactionObject(),
array($template));
}

private function releaseAllArtifacts(HarbormasterBuild $build) {
Expand Down

0 comments on commit db1bc7f

Please sign in to comment.