1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-16 03:42:41 +01:00
phorge-phorge/resources/sql/patches/liskcounters.php
epriestley ee2e85a0bb 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
2012-11-16 10:19:22 -08:00

40 lines
1,023 B
PHP

<?php
// Switch PhabricatorWorkerActiveTask from autoincrement IDs to counter IDs.
// Set the initial counter ID to be larger than any known task ID.
$active_table = new PhabricatorWorkerActiveTask();
$archive_table = new PhabricatorWorkerArchiveTask();
$old_table = 'worker_task';
$conn_w = $active_table->establishConnection('w');
$active_auto = head(queryfx_one(
$conn_w,
'SELECT auto_increment FROM information_schema.tables
WHERE table_name = %s
AND table_schema = DATABASE()',
$old_table));
$active_max = head(queryfx_one(
$conn_w,
'SELECT MAX(id) FROM %T',
$old_table));
$archive_max = head(queryfx_one(
$conn_w,
'SELECT MAX(id) FROM %T',
$archive_table->getTableName()));
$initial_counter = max((int)$active_auto, (int)$active_max, (int)$archive_max);
queryfx(
$conn_w,
'INSERT INTO %T (counterName, counterValue)
VALUES (%s, %d)
ON DUPLICATE KEY UPDATE counterValue = %d',
LiskDAO::COUNTER_TABLE_NAME,
$old_table,
$initial_counter + 1,
$initial_counter + 1);