mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
Strip some obsolete code out of Drydock
Summary: Ref T9252. This simplifies some Drydock code. Most of this code relates to the old notion of Drydock being able to enumerate all the tasks it needs to complete in order to acquire a lease. The code has stepped back from this, since it's unnecessary, the queue is more powerful than it used to be, and it would be a lot of work to keep track of. The ~only thing that should ever wait for leases in modern code is `bin/drydock lease`, and it's fine for it to just sit there sleeping, so this just does that. This reduces the granularity of logging, but I'll address that separately in future logging-focused changes. Test Plan: Used `bin/drydock lease` to acquire a lease, saw it acquire cleanly. Reviewers: hach-que, chad Reviewed By: chad Maniphest Tasks: T9252 Differential Revision: https://secure.phabricator.com/D14147
This commit is contained in:
parent
be9cc235b2
commit
fcb6d1e2fa
6 changed files with 34 additions and 160 deletions
2
resources/sql/autopatches/20150923.drydock.taskid.1.sql
Normal file
2
resources/sql/autopatches/20150923.drydock.taskid.1.sql
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE {$NAMESPACE}_drydock.drydock_lease
|
||||||
|
DROP taskID;
|
|
@ -812,7 +812,6 @@ phutil_register_library_map(array(
|
||||||
'DrydockBlueprintListController' => 'applications/drydock/controller/DrydockBlueprintListController.php',
|
'DrydockBlueprintListController' => 'applications/drydock/controller/DrydockBlueprintListController.php',
|
||||||
'DrydockBlueprintPHIDType' => 'applications/drydock/phid/DrydockBlueprintPHIDType.php',
|
'DrydockBlueprintPHIDType' => 'applications/drydock/phid/DrydockBlueprintPHIDType.php',
|
||||||
'DrydockBlueprintQuery' => 'applications/drydock/query/DrydockBlueprintQuery.php',
|
'DrydockBlueprintQuery' => 'applications/drydock/query/DrydockBlueprintQuery.php',
|
||||||
'DrydockBlueprintScopeGuard' => 'applications/drydock/util/DrydockBlueprintScopeGuard.php',
|
|
||||||
'DrydockBlueprintSearchEngine' => 'applications/drydock/query/DrydockBlueprintSearchEngine.php',
|
'DrydockBlueprintSearchEngine' => 'applications/drydock/query/DrydockBlueprintSearchEngine.php',
|
||||||
'DrydockBlueprintTransaction' => 'applications/drydock/storage/DrydockBlueprintTransaction.php',
|
'DrydockBlueprintTransaction' => 'applications/drydock/storage/DrydockBlueprintTransaction.php',
|
||||||
'DrydockBlueprintTransactionQuery' => 'applications/drydock/query/DrydockBlueprintTransactionQuery.php',
|
'DrydockBlueprintTransactionQuery' => 'applications/drydock/query/DrydockBlueprintTransactionQuery.php',
|
||||||
|
@ -4538,7 +4537,6 @@ phutil_register_library_map(array(
|
||||||
'DrydockBlueprintListController' => 'DrydockBlueprintController',
|
'DrydockBlueprintListController' => 'DrydockBlueprintController',
|
||||||
'DrydockBlueprintPHIDType' => 'PhabricatorPHIDType',
|
'DrydockBlueprintPHIDType' => 'PhabricatorPHIDType',
|
||||||
'DrydockBlueprintQuery' => 'DrydockQuery',
|
'DrydockBlueprintQuery' => 'DrydockQuery',
|
||||||
'DrydockBlueprintScopeGuard' => 'Phobject',
|
|
||||||
'DrydockBlueprintSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
'DrydockBlueprintSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
'DrydockBlueprintTransaction' => 'PhabricatorApplicationTransaction',
|
'DrydockBlueprintTransaction' => 'PhabricatorApplicationTransaction',
|
||||||
'DrydockBlueprintTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
'DrydockBlueprintTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||||
|
|
|
@ -8,9 +8,6 @@
|
||||||
*/
|
*/
|
||||||
abstract class DrydockBlueprintImplementation extends Phobject {
|
abstract class DrydockBlueprintImplementation extends Phobject {
|
||||||
|
|
||||||
private $activeResource;
|
|
||||||
private $activeLease;
|
|
||||||
|
|
||||||
abstract public function getType();
|
abstract public function getType();
|
||||||
|
|
||||||
abstract public function isEnabled();
|
abstract public function isEnabled();
|
||||||
|
@ -265,10 +262,7 @@ abstract class DrydockBlueprintImplementation extends Phobject {
|
||||||
* @task log
|
* @task log
|
||||||
*/
|
*/
|
||||||
protected function log($message) {
|
protected function log($message) {
|
||||||
self::writeLog(
|
self::writeLog(null, null, $message);
|
||||||
$this->activeResource,
|
|
||||||
$this->activeLease,
|
|
||||||
$message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -320,13 +314,6 @@ abstract class DrydockBlueprintImplementation extends Phobject {
|
||||||
// Pre-allocate the resource PHID.
|
// Pre-allocate the resource PHID.
|
||||||
$resource->setPHID($resource->generatePHID());
|
$resource->setPHID($resource->generatePHID());
|
||||||
|
|
||||||
$this->activeResource = $resource;
|
|
||||||
|
|
||||||
$this->log(
|
|
||||||
pht(
|
|
||||||
"Blueprint '%s': Created New Template",
|
|
||||||
get_class($this)));
|
|
||||||
|
|
||||||
return $resource;
|
return $resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,24 +336,4 @@ abstract class DrydockBlueprintImplementation extends Phobject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function pushActiveScope(
|
|
||||||
DrydockResource $resource = null,
|
|
||||||
DrydockLease $lease = null) {
|
|
||||||
|
|
||||||
if (($this->activeResource !== null) ||
|
|
||||||
($this->activeLease !== null)) {
|
|
||||||
throw new Exception(pht('There is already an active resource or lease!'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->activeResource = $resource;
|
|
||||||
$this->activeLease = $lease;
|
|
||||||
|
|
||||||
return new DrydockBlueprintScopeGuard($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function popActiveScope() {
|
|
||||||
$this->activeResource = null;
|
|
||||||
$this->activeLease = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ final class DrydockLease extends DrydockDAO
|
||||||
protected $ownerPHID;
|
protected $ownerPHID;
|
||||||
protected $attributes = array();
|
protected $attributes = array();
|
||||||
protected $status = DrydockLeaseStatus::STATUS_PENDING;
|
protected $status = DrydockLeaseStatus::STATUS_PENDING;
|
||||||
protected $taskID;
|
|
||||||
|
|
||||||
private $resource = self::ATTACHABLE;
|
private $resource = self::ATTACHABLE;
|
||||||
private $releaseOnDestruction;
|
private $releaseOnDestruction;
|
||||||
|
@ -64,7 +63,6 @@ final class DrydockLease extends DrydockDAO
|
||||||
'status' => 'uint32',
|
'status' => 'uint32',
|
||||||
'until' => 'epoch?',
|
'until' => 'epoch?',
|
||||||
'resourceType' => 'text128',
|
'resourceType' => 'text128',
|
||||||
'taskID' => 'id?',
|
|
||||||
'ownerPHID' => 'phid?',
|
'ownerPHID' => 'phid?',
|
||||||
'resourceID' => 'id?',
|
'resourceID' => 'id?',
|
||||||
),
|
),
|
||||||
|
@ -108,20 +106,15 @@ final class DrydockLease extends DrydockDAO
|
||||||
return ($this->resource !== null);
|
return ($this->resource !== null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadResource() {
|
|
||||||
return id(new DrydockResource())->loadOneWhere(
|
|
||||||
'id = %d',
|
|
||||||
$this->getResourceID());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function queueForActivation() {
|
public function queueForActivation() {
|
||||||
if ($this->getID()) {
|
if ($this->getID()) {
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
pht('Only new leases may be queued for activation!'));
|
pht('Only new leases may be queued for activation!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setStatus(DrydockLeaseStatus::STATUS_PENDING);
|
$this
|
||||||
$this->save();
|
->setStatus(DrydockLeaseStatus::STATUS_PENDING)
|
||||||
|
->save();
|
||||||
|
|
||||||
$task = PhabricatorWorker::scheduleTask(
|
$task = PhabricatorWorker::scheduleTask(
|
||||||
'DrydockAllocatorWorker',
|
'DrydockAllocatorWorker',
|
||||||
|
@ -132,14 +125,6 @@ final class DrydockLease extends DrydockDAO
|
||||||
'objectPHID' => $this->getPHID(),
|
'objectPHID' => $this->getPHID(),
|
||||||
));
|
));
|
||||||
|
|
||||||
// NOTE: Scheduling the task might execute it in-process, if we're running
|
|
||||||
// from a CLI script. Reload the lease to make sure we have the most
|
|
||||||
// up-to-date information. Normally, this has no effect.
|
|
||||||
$this->reload();
|
|
||||||
|
|
||||||
$this->setTaskID($task->getID());
|
|
||||||
$this->save();
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,54 +146,36 @@ final class DrydockLease extends DrydockDAO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function waitForLeases(array $leases) {
|
|
||||||
assert_instances_of($leases, __CLASS__);
|
|
||||||
|
|
||||||
$task_ids = array_filter(mpull($leases, 'getTaskID'));
|
|
||||||
|
|
||||||
PhabricatorWorker::waitForTasks($task_ids);
|
|
||||||
|
|
||||||
$unresolved = $leases;
|
|
||||||
while (true) {
|
|
||||||
foreach ($unresolved as $key => $lease) {
|
|
||||||
$lease->reload();
|
|
||||||
switch ($lease->getStatus()) {
|
|
||||||
case DrydockLeaseStatus::STATUS_ACTIVE:
|
|
||||||
unset($unresolved[$key]);
|
|
||||||
break;
|
|
||||||
case DrydockLeaseStatus::STATUS_RELEASED:
|
|
||||||
throw new Exception(pht('Lease has already been released!'));
|
|
||||||
case DrydockLeaseStatus::STATUS_EXPIRED:
|
|
||||||
throw new Exception(pht('Lease has already expired!'));
|
|
||||||
case DrydockLeaseStatus::STATUS_BROKEN:
|
|
||||||
throw new Exception(pht('Lease has been broken!'));
|
|
||||||
case DrydockLeaseStatus::STATUS_PENDING:
|
|
||||||
case DrydockLeaseStatus::STATUS_ACQUIRED:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Exception(pht('Unknown status??'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($unresolved) {
|
|
||||||
sleep(1);
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($leases as $lease) {
|
|
||||||
$lease->attachResource($lease->loadResource());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function waitUntilActive() {
|
public function waitUntilActive() {
|
||||||
if (!$this->getID()) {
|
while (true) {
|
||||||
$this->queueForActivation();
|
$lease = $this->reload();
|
||||||
}
|
if (!$lease) {
|
||||||
|
throw new Exception(pht('Failed to reload lease.'));
|
||||||
|
}
|
||||||
|
|
||||||
self::waitForLeases(array($this));
|
$status = $lease->getStatus();
|
||||||
return $this;
|
|
||||||
|
switch ($status) {
|
||||||
|
case DrydockLeaseStatus::STATUS_ACTIVE:
|
||||||
|
return;
|
||||||
|
case DrydockLeaseStatus::STATUS_RELEASED:
|
||||||
|
throw new Exception(pht('Lease has already been released!'));
|
||||||
|
case DrydockLeaseStatus::STATUS_EXPIRED:
|
||||||
|
throw new Exception(pht('Lease has already expired!'));
|
||||||
|
case DrydockLeaseStatus::STATUS_BROKEN:
|
||||||
|
throw new Exception(pht('Lease has been broken!'));
|
||||||
|
case DrydockLeaseStatus::STATUS_PENDING:
|
||||||
|
case DrydockLeaseStatus::STATUS_ACQUIRED:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Exception(
|
||||||
|
pht(
|
||||||
|
'Lease has unknown status "%s".',
|
||||||
|
$status));
|
||||||
|
}
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setActivateWhenAcquired($activate) {
|
public function setActivateWhenAcquired($activate) {
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
final class DrydockBlueprintScopeGuard extends Phobject {
|
|
||||||
|
|
||||||
private $blueprint;
|
|
||||||
|
|
||||||
public function __construct(DrydockBlueprintImplementation $blueprint) {
|
|
||||||
$this->blueprint = $blueprint;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __destruct() {
|
|
||||||
$this->blueprint->popActiveScope();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -157,51 +157,6 @@ abstract class PhabricatorWorker extends Phobject {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wait for tasks to complete.
|
|
||||||
*
|
|
||||||
* @param list<int> List of queued task IDs to wait for.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
final public static function waitForTasks(array $task_ids) {
|
|
||||||
if (!$task_ids) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$task_table = new PhabricatorWorkerActiveTask();
|
|
||||||
|
|
||||||
$waiting = array_fuse($task_ids);
|
|
||||||
while ($waiting) {
|
|
||||||
$conn_w = $task_table->establishConnection('w');
|
|
||||||
|
|
||||||
// Check if any of the tasks we're waiting on are still queued. If they
|
|
||||||
// are not, we're done waiting.
|
|
||||||
$row = queryfx_one(
|
|
||||||
$conn_w,
|
|
||||||
'SELECT COUNT(*) N FROM %T WHERE id IN (%Ld)',
|
|
||||||
$task_table->getTableName(),
|
|
||||||
$waiting);
|
|
||||||
if (!$row['N']) {
|
|
||||||
// Nothing is queued anymore. Stop waiting.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We were not successful in leasing anything. Sleep for a bit and
|
|
||||||
// see if we have better luck later.
|
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
$tasks = id(new PhabricatorWorkerArchiveTaskQuery())
|
|
||||||
->withIDs($task_ids)
|
|
||||||
->execute();
|
|
||||||
|
|
||||||
foreach ($tasks as $task) {
|
|
||||||
if ($task->getResult() != PhabricatorWorkerArchiveTask::RESULT_SUCCESS) {
|
|
||||||
throw new Exception(pht('Task %d failed!', $task->getID()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function renderForDisplay(PhabricatorUser $viewer) {
|
public function renderForDisplay(PhabricatorUser $viewer) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue