1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +01:00

Correct schema irregularities (including weird keys) with worker task tables

Summary:
Ref T13253. Fixes T6615. See that task for discussion.

  - Remove three keys which serve no real purpose: `dataID` doesn't do anything for us, and the two `leaseOwner` keys are unused.
  - Rename `leaseOwner_2` to `key_owner`.
  - Fix an issue where `dataID` was nullable in the active table and non-nullable in the archive table.

In practice, //all// workers have data, so all workers have a `dataID`: if they didn't, we'd already fatal when trying to move tasks to the archive table. Just clean this up for consistency, and remove the ancient codepath which imagined tasks with no data.

Test Plan:
  - Ran `bin/storage upgrade`, inspected tables.
  - Ran `bin/phd debug taskmaster`, worked through a bunch of tasks with no problems.

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13253, T6615

Differential Revision: https://secure.phabricator.com/D20175
This commit is contained in:
epriestley 2019-02-15 04:39:49 -08:00
parent c5e16f9bd9
commit 4b10bc2b64
4 changed files with 25 additions and 19 deletions

View file

@ -0,0 +1,21 @@
<?php
// See T6615. We're about to change the nullability on the "dataID" column,
// but it may have a UNIQUE KEY on it. Make sure we get rid of this key first
// so we don't run into trouble.
// There's no "IF EXISTS" modifier for "ALTER TABLE" so run this as a PHP patch
// instead of an SQL patch.
$table = new PhabricatorWorkerActiveTask();
$conn = $table->establishConnection('w');
try {
queryfx(
$conn,
'ALTER TABLE %R DROP KEY %T',
$table,
'dataID');
} catch (AphrontQueryException $ex) {
// Ignore.
}

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_worker.worker_activetask
CHANGE dataID dataID INT UNSIGNED NOT NULL;

View file

@ -14,35 +14,21 @@ final class PhabricatorWorkerActiveTask extends PhabricatorWorkerTask {
self::CONFIG_IDS => self::IDS_COUNTER,
self::CONFIG_TIMESTAMPS => false,
self::CONFIG_KEY_SCHEMA => array(
'dataID' => array(
'columns' => array('dataID'),
'unique' => true,
),
'taskClass' => array(
'columns' => array('taskClass'),
),
'leaseExpires' => array(
'columns' => array('leaseExpires'),
),
'leaseOwner' => array(
'columns' => array('leaseOwner(16)'),
),
'key_failuretime' => array(
'columns' => array('failureTime'),
),
'leaseOwner_2' => array(
'key_owner' => array(
'columns' => array('leaseOwner', 'priority', 'id'),
),
) + $parent[self::CONFIG_KEY_SCHEMA],
);
$config[self::CONFIG_COLUMN_SCHEMA] = array(
// T6203/NULLABILITY
// This isn't nullable in the archive table, so at a minimum these
// should be the same.
'dataID' => 'uint32?',
) + $parent[self::CONFIG_COLUMN_SCHEMA];
return $config + $parent;
}
@ -74,7 +60,7 @@ final class PhabricatorWorkerActiveTask extends PhabricatorWorkerTask {
$this->failureCount = 0;
}
if ($is_new && ($this->getData() !== null)) {
if ($is_new) {
$data = new PhabricatorWorkerTaskData();
$data->setData($this->getData());
$data->save();

View file

@ -28,9 +28,6 @@ final class PhabricatorWorkerArchiveTask extends PhabricatorWorkerTask {
'dateCreated' => array(
'columns' => array('dateCreated'),
),
'leaseOwner' => array(
'columns' => array('leaseOwner', 'priority', 'id'),
),
'key_modified' => array(
'columns' => array('dateModified'),
),