@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Don't reclaim resources that have a destroyed lease less than 3 minutes old

Summary:
Ref T13676. The 3-minute grace period when a resource can not be reclaimed after its leases are released currently doesn't work reliably because the Resource object usually isn't actually updated when a lease is released.

Add an additional check for recently-destroyed leases, and extend the grace period if we find any.

Test Plan:
- See T13676. Ran reproduction sequence there, observed immediate resource reclamation.
- Applied patch.
- Ran sequence again, observed repository B wait 3 minutes to reclaim a repository A resource.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13676

Differential Revision: https://secure.phabricator.com/D21803

+44 -3
+22
src/applications/drydock/query/DrydockLeaseQuery.php
··· 9 9 private $statuses; 10 10 private $datasourceQuery; 11 11 private $needUnconsumedCommands; 12 + private $minModified; 13 + private $maxModified; 12 14 13 15 public function withIDs(array $ids) { 14 16 $this->ids = $ids; ··· 37 39 38 40 public function withDatasourceQuery($query) { 39 41 $this->datasourceQuery = $query; 42 + return $this; 43 + } 44 + 45 + public function withDateModifiedBetween($min_epoch, $max_epoch) { 46 + $this->minModified = $min_epoch; 47 + $this->maxModified = $max_epoch; 40 48 return $this; 41 49 } 42 50 ··· 144 152 $conn, 145 153 'id = %d', 146 154 (int)$this->datasourceQuery); 155 + } 156 + 157 + if ($this->minModified !== null) { 158 + $where[] = qsprintf( 159 + $conn, 160 + 'dateModified >= %d', 161 + $this->minModified); 162 + } 163 + 164 + if ($this->maxModified !== null) { 165 + $where[] = qsprintf( 166 + $conn, 167 + 'dateModified <= %d', 168 + $this->maxModified); 147 169 } 148 170 149 171 return $where;
+3
src/applications/drydock/storage/DrydockLease.php
··· 111 111 'key_owner' => array( 112 112 'columns' => array('ownerPHID'), 113 113 ), 114 + 'key_recent' => array( 115 + 'columns' => array('resourcePHID', 'dateModified'), 116 + ), 114 117 ), 115 118 ) + parent::getConfiguration(); 116 119 }
+19 -3
src/applications/drydock/worker/DrydockWorker.php
··· 203 203 // from one another forever without making progress, so make resources 204 204 // immune to reclamation for a little while after they activate or update. 205 205 206 + $now = PhabricatorTime::getNow(); 207 + $max_epoch = ($now - phutil_units('3 minutes in seconds')); 208 + 206 209 // TODO: It would be nice to use a more narrow time here, like "last 207 210 // activation or lease release", but we don't currently store that 208 211 // anywhere. 209 212 210 213 $updated = $resource->getDateModified(); 211 - $now = PhabricatorTime::getNow(); 212 - $ago = ($now - $updated); 213 - if ($ago < phutil_units('3 minutes in seconds')) { 214 + if ($updated > $max_epoch) { 214 215 return false; 215 216 } 216 217 ··· 227 228 ->setViewer($viewer) 228 229 ->withResourcePHIDs(array($resource->getPHID())) 229 230 ->withStatuses($statuses) 231 + ->setLimit(1) 232 + ->execute(); 233 + if ($leases) { 234 + return false; 235 + } 236 + 237 + // See T13676. Don't reclaim a resource if a lease recently released. 238 + $leases = id(new DrydockLeaseQuery()) 239 + ->setViewer($viewer) 240 + ->withResourcePHIDs(array($resource->getPHID())) 241 + ->withStatuses( 242 + array( 243 + DrydockLeaseStatus::STATUS_DESTROYED, 244 + )) 245 + ->withDateModifiedBetween($max_epoch, null) 230 246 ->setLimit(1) 231 247 ->execute(); 232 248 if ($leases) {