@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

Fix several migration issues with the Task/Counter patch

Summary:
People hit three issues with D3914:

- As per T2059, we applied a schema change from a `.php` patch, which currently does not work if you use a different user to make schema changes than for normal use.
- Since the change in question is idempotent, just move it to a `.sql` patch. We'll follow up in T2059 and fix it properly.
- Rogue daemons at several installs used old code (expecting autoincrement) to insert into the new table (no autoincrement), thereby creating tasks with ID 0.
- Rename the table so they'll fail.
- This also makes the code a little more consistent.
- Some installs now have tasks with ID 0.
- Use checks against null rather than against 0 so we can process these tasks.

The major issues this fixes are the schema upgrade failure in T2059, and the infinite loops in T2072 and elsewhere.

This isn't really a fully statisfactory fix. I'll discuss some next steps in T2072.

Test Plan: Created new tasks via MetaMTA/Differential. Ran tasks with `phd debug taskmaster`. Inserted a task 0 and verified it ran and archived correctly.

Reviewers: btrahan, vrana, nh

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2072, T2059

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

+19 -15
+8
resources/sql/patches/liskcounters-task.sql
··· 1 + ALTER TABLE `{$NAMESPACE}_worker`.worker_task 2 + CHANGE id id INT UNSIGNED NOT NULL; 3 + 4 + RENAME TABLE `{$NAMESPACE}_worker`.worker_task 5 + TO `{$NAMESPACE}_worker`.worker_activetask; 6 + 7 + UPDATE `{$NAMESPACE}_worker`.lisk_counter 8 + SET counterName = 'worker_activetask' WHERE counterName = 'worker_task';
+5 -9
resources/sql/patches/liskcounters.php
··· 6 6 $active_table = new PhabricatorWorkerActiveTask(); 7 7 $archive_table = new PhabricatorWorkerArchiveTask(); 8 8 9 + $old_table = 'worker_task'; 10 + 9 11 $conn_w = $active_table->establishConnection('w'); 10 12 11 13 $active_auto = head(queryfx_one( ··· 13 15 'SELECT auto_increment FROM information_schema.tables 14 16 WHERE table_name = %s 15 17 AND table_schema = DATABASE()', 16 - $active_table->getTableName())); 18 + $old_table)); 17 19 18 20 $active_max = head(queryfx_one( 19 21 $conn_w, 20 22 'SELECT MAX(id) FROM %T', 21 - $active_table->getTableName())); 23 + $old_table)); 22 24 23 25 $archive_max = head(queryfx_one( 24 26 $conn_w, ··· 33 35 VALUES (%s, %d) 34 36 ON DUPLICATE KEY UPDATE counterValue = %d', 35 37 LiskDAO::COUNTER_TABLE_NAME, 36 - $active_table->getTableName(), 38 + $old_table, 37 39 $initial_counter + 1, 38 40 $initial_counter + 1); 39 - 40 - // Drop AUTO_INCREMENT from the ID column. 41 - queryfx( 42 - $conn_w, 43 - 'ALTER TABLE %T CHANGE id id INT UNSIGNED NOT NULL', 44 - $active_table->getTableName());
+1 -5
src/infrastructure/daemon/workers/storage/PhabricatorWorkerActiveTask.php
··· 5 5 private $serverTime; 6 6 private $localTime; 7 7 8 - public function getTableName() { 9 - return 'worker_task'; 10 - } 11 - 12 8 public function getConfiguration() { 13 9 return array( 14 10 self::CONFIG_IDS => self::IDS_COUNTER, ··· 71 67 } 72 68 73 69 public function archiveTask($result, $duration) { 74 - if (!$this->getID()) { 70 + if ($this->getID() === null) { 75 71 throw new Exception( 76 72 "Attempting to archive a task which hasn't been save()d!"); 77 73 }
+1 -1
src/infrastructure/daemon/workers/storage/PhabricatorWorkerArchiveTask.php
··· 10 10 protected $result; 11 11 12 12 public function save() { 13 - if (!$this->getID()) { 13 + if ($this->getID() === null) { 14 14 throw new Exception( 15 15 "Trying to archive a task with no ID."); 16 16 }
+4
src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
··· 1028 1028 'type' => 'sql', 1029 1029 'name' => $this->getPatchPath('repository-lint.sql'), 1030 1030 ), 1031 + 'liskcounters-task.sql' => array( 1032 + 'type' => 'sql', 1033 + 'name' => $this->getPatchPath('liskcounters-task.sql'), 1034 + ), 1031 1035 ); 1032 1036 } 1033 1037