@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.

Record how long storage patches took to apply

Summary:
It's hard for us to predict how long patches and migrations will take in the general case since it varies a lot from install to install, but we can give installs some kind of rough heads up about longer patches. I'm planning to just put a sort of hint for things in the changelog, something like this:

{F905579}

To make this easier, start storing how long stuff took. I'll write a little script to dump this into a table for the changelog.

Test Plan:
Ran `bin/storage status`:

{F905580}

Reviewers: chad

Reviewed By: chad

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

+55 -5
+2
resources/sql/autopatches/20151023.patchduration.sql
··· 1 + ALTER TABLE {$NAMESPACE}_meta_data.patch_status 2 + ADD duration BIGINT UNSIGNED;
+36 -4
src/infrastructure/storage/management/PhabricatorStorageManagementAPI.php
··· 17 17 const COLLATE_SORT = 'COLLATE_SORT'; 18 18 const COLLATE_FULLTEXT = 'COLLATE_FULLTEXT'; 19 19 20 + const TABLE_STATUS = 'patch_status'; 21 + 20 22 public function setDisableUTF8MB4($disable_utf8_mb4) { 21 23 $this->disableUTF8MB4 = $disable_utf8_mb4; 22 24 return $this; ··· 118 120 try { 119 121 $applied = queryfx_all( 120 122 $this->getConn('meta_data'), 121 - 'SELECT patch FROM patch_status'); 123 + 'SELECT patch FROM %T', 124 + self::TABLE_STATUS); 122 125 return ipull($applied, 'patch'); 123 126 } catch (AphrontQueryException $ex) { 124 127 return null; 128 + } 129 + } 130 + 131 + public function getPatchDurations() { 132 + try { 133 + $rows = queryfx_all( 134 + $this->getConn('meta_data'), 135 + 'SELECT patch, duration FROM %T WHERE duration IS NOT NULL', 136 + self::TABLE_STATUS); 137 + return ipull($rows, 'duration', 'patch'); 138 + } catch (AphrontQueryException $ex) { 139 + return array(); 125 140 } 126 141 } 127 142 ··· 168 183 return $legacy; 169 184 } 170 185 171 - public function markPatchApplied($patch) { 186 + public function markPatchApplied($patch, $duration = null) { 187 + $conn = $this->getConn('meta_data'); 188 + 172 189 queryfx( 173 - $this->getConn('meta_data'), 190 + $conn, 174 191 'INSERT INTO %T (patch, applied) VALUES (%s, %d)', 175 - 'patch_status', 192 + self::TABLE_STATUS, 176 193 $patch, 177 194 time()); 195 + 196 + // We didn't add this column for a long time, so it may not exist yet. 197 + if ($duration !== null) { 198 + try { 199 + queryfx( 200 + $conn, 201 + 'UPDATE %T SET duration = %d WHERE patch = %s', 202 + self::TABLE_STATUS, 203 + (int)floor($duration * 1000000), 204 + $patch); 205 + } catch (AphrontQueryException $ex) { 206 + // Just ignore this, as it almost certainly indicates that we just 207 + // don't have the column yet. 208 + } 209 + } 178 210 } 179 211 180 212 public function applyPatch(PhabricatorStoragePatch $patch) {
+11
src/infrastructure/storage/management/workflow/PhabricatorStorageManagementStatusWorkflow.php
··· 29 29 ->setShowHeader(false) 30 30 ->addColumn('id', array('title' => pht('ID'))) 31 31 ->addColumn('status', array('title' => pht('Status'))) 32 + ->addColumn('duration', array('title' => pht('Duration'))) 32 33 ->addColumn('type', array('title' => pht('Type'))) 33 34 ->addColumn('name', array('title' => pht('Name'))); 35 + 36 + $durations = $api->getPatchDurations(); 34 37 35 38 foreach ($patches as $patch) { 39 + $duration = idx($durations, $patch->getFullKey()); 40 + if ($duration === null) { 41 + $duration = '-'; 42 + } else { 43 + $duration = pht('%s us', new PhutilNumber($duration)); 44 + } 45 + 36 46 $table->addRow(array( 37 47 'id' => $patch->getFullKey(), 38 48 'status' => in_array($patch->getFullKey(), $applied) 39 49 ? pht('Applied') 40 50 : pht('Not Applied'), 51 + 'duration' => $duration, 41 52 'type' => $patch->getType(), 42 53 'name' => $patch->getName(), 43 54 ));
+5 -1
src/infrastructure/storage/management/workflow/PhabricatorStorageManagementUpgradeWorkflow.php
··· 187 187 echo pht("DRYRUN: Would apply patch '%s'.", $key)."\n"; 188 188 } else { 189 189 echo pht("Applying patch '%s'...", $key)."\n"; 190 + 191 + $t_begin = microtime(true); 190 192 $api->applyPatch($patch); 193 + $t_end = microtime(true); 194 + 191 195 if (!$skip_mark) { 192 - $api->markPatchApplied($key); 196 + $api->markPatchApplied($key, ($t_end - $t_begin)); 193 197 } 194 198 } 195 199
+1
src/infrastructure/storage/schema/PhabricatorStorageSchemaSpec.php
··· 10 10 array( 11 11 'patch' => 'text128', 12 12 'applied' => 'uint32', 13 + 'duration' => 'uint64?', 13 14 ), 14 15 array( 15 16 'PRIMARY' => array(