mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 12:00:55 +01:00
Prevent artifact key collision when builds are restarted
Summary: Ref T1049. Because we no longer destroy artifacts when builds are restarted, we need the build generation number to be part of the artifact key, otherwise we get collisions when restarting builds that contain build steps that emit artifacts. Test Plan: Ran it with a build plan of "Lease Host" and "Run Command", no longer got an artifact key crash. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T1049 Differential Revision: https://secure.phabricator.com/D10336
This commit is contained in:
parent
0e15393b46
commit
a26c6147f5
3 changed files with 14 additions and 5 deletions
|
@ -8,6 +8,7 @@ final class HarbormasterBuildArtifactQuery
|
||||||
private $artifactTypes;
|
private $artifactTypes;
|
||||||
private $artifactKeys;
|
private $artifactKeys;
|
||||||
private $keyBuildPHID;
|
private $keyBuildPHID;
|
||||||
|
private $keyBuildGeneration;
|
||||||
|
|
||||||
public function withIDs(array $ids) {
|
public function withIDs(array $ids) {
|
||||||
$this->ids = $ids;
|
$this->ids = $ids;
|
||||||
|
@ -24,8 +25,12 @@ final class HarbormasterBuildArtifactQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function withArtifactKeys($build_phid, array $artifact_keys) {
|
public function withArtifactKeys(
|
||||||
|
$build_phid,
|
||||||
|
$build_gen,
|
||||||
|
array $artifact_keys) {
|
||||||
$this->keyBuildPHID = $build_phid;
|
$this->keyBuildPHID = $build_phid;
|
||||||
|
$this->keyBuildGeneration = $build_gen;
|
||||||
$this->artifactKeys = $artifact_keys;
|
$this->artifactKeys = $artifact_keys;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +103,7 @@ final class HarbormasterBuildArtifactQuery
|
||||||
$indexes = array();
|
$indexes = array();
|
||||||
foreach ($this->artifactKeys as $key) {
|
foreach ($this->artifactKeys as $key) {
|
||||||
$indexes[] = PhabricatorHash::digestForIndex(
|
$indexes[] = PhabricatorHash::digestForIndex(
|
||||||
$this->keyBuildPHID.$key);
|
$this->keyBuildPHID.$this->keyBuildGeneration.$key);
|
||||||
}
|
}
|
||||||
|
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
|
|
|
@ -213,7 +213,10 @@ final class HarbormasterBuild extends HarbormasterDAO
|
||||||
|
|
||||||
$artifact =
|
$artifact =
|
||||||
HarbormasterBuildArtifact::initializeNewBuildArtifact($build_target);
|
HarbormasterBuildArtifact::initializeNewBuildArtifact($build_target);
|
||||||
$artifact->setArtifactKey($this->getPHID(), $artifact_key);
|
$artifact->setArtifactKey(
|
||||||
|
$this->getPHID(),
|
||||||
|
$this->getBuildGeneration(),
|
||||||
|
$artifact_key);
|
||||||
$artifact->setArtifactType($artifact_type);
|
$artifact->setArtifactType($artifact_type);
|
||||||
$artifact->save();
|
$artifact->save();
|
||||||
return $artifact;
|
return $artifact;
|
||||||
|
@ -224,6 +227,7 @@ final class HarbormasterBuild extends HarbormasterDAO
|
||||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||||
->withArtifactKeys(
|
->withArtifactKeys(
|
||||||
$this->getPHID(),
|
$this->getPHID(),
|
||||||
|
$this->getBuildGeneration(),
|
||||||
array($name))
|
array($name))
|
||||||
->executeOne();
|
->executeOne();
|
||||||
if ($artifact === null) {
|
if ($artifact === null) {
|
||||||
|
|
|
@ -38,9 +38,9 @@ final class HarbormasterBuildArtifact extends HarbormasterDAO
|
||||||
return $this->assertAttached($this->buildTarget);
|
return $this->assertAttached($this->buildTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setArtifactKey($build_phid, $key) {
|
public function setArtifactKey($build_phid, $build_gen, $key) {
|
||||||
$this->artifactIndex =
|
$this->artifactIndex =
|
||||||
PhabricatorHash::digestForIndex($build_phid.$key);
|
PhabricatorHash::digestForIndex($build_phid.$build_gen.$key);
|
||||||
$this->artifactKey = $key;
|
$this->artifactKey = $key;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue