1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-17 18:21:11 +01:00

Prevent a race in Phabricator workers

Summary: See D133. Workers can also be subject to the same race, invert the
row relationship in the same way.

Test Plan: Launched repository master daemons and some taskmasters and used
the Daemon console to veify that they were able to process tasks. Manually
checked the database to make sure data got linked correctly and that new data
was inserted correctly.

Reviewers: jungejason

CC: tuomaspelkonen

Differential Revision: 135
This commit is contained in:
epriestley 2011-04-14 12:07:57 -07:00
parent ee1e2da8fb
commit ca7a0de1cf
5 changed files with 22 additions and 10 deletions

View file

@ -0,0 +1,13 @@
ALTER TABLE phabricator_worker.worker_task
ADD dataID int unsigned;
ALTER TABLE phabricator_worker.worker_task
ADD UNIQUE KEY (dataID);
UPDATE phabricator_worker.worker_task t,
phabricator_worker.worker_taskdata d
SET t.dataID = d.id
WHERE d.taskID = t.id;
ALTER TABLE phabricator_worker.worker_taskdata
DROP taskID;

View file

@ -44,8 +44,8 @@ class PhabricatorWorkerTaskDetailController
} }
$data = id(new PhabricatorWorkerTaskData())->loadOneWhere( $data = id(new PhabricatorWorkerTaskData())->loadOneWhere(
'taskID = %d', 'id = %d',
$task->getID()); $task->getDataID());
if ($data) { if ($data) {
$data = json_encode($data->getData()); $data = json_encode($data->getData());
} }

View file

@ -22,6 +22,7 @@ class PhabricatorWorkerTask extends PhabricatorWorkerDAO {
protected $leaseOwner; protected $leaseOwner;
protected $leaseExpires; protected $leaseExpires;
protected $failureCount; protected $failureCount;
protected $dataID;
private $serverTime; private $serverTime;
private $localTime; private $localTime;
@ -58,16 +59,15 @@ class PhabricatorWorkerTask extends PhabricatorWorkerDAO {
$this->failureCount = 0; $this->failureCount = 0;
} }
$ret = parent::save();
if ($is_new && $this->data) { if ($is_new && $this->data) {
$data = new PhabricatorWorkerTaskData(); $data = new PhabricatorWorkerTaskData();
$data->setTaskID($this->getID());
$data->setData($this->data); $data->setData($this->data);
$data->save(); $data->save();
$this->setDataID($data->getID());
} }
return $ret; return parent::save();
} }
public function setData($data) { public function setData($data) {

View file

@ -18,7 +18,6 @@
class PhabricatorWorkerTaskData extends PhabricatorWorkerDAO { class PhabricatorWorkerTaskData extends PhabricatorWorkerDAO {
protected $taskID;
protected $data; protected $data;
public function getConfiguration() { public function getConfiguration() {

View file

@ -50,7 +50,7 @@ class PhabricatorTaskmasterDaemon extends PhabricatorDaemon {
$conn_w, $conn_w,
'SELECT task.*, taskdata.data _taskData, UNIX_TIMESTAMP() _serverTime 'SELECT task.*, taskdata.data _taskData, UNIX_TIMESTAMP() _serverTime
FROM %T task LEFT JOIN %T taskdata FROM %T task LEFT JOIN %T taskdata
ON taskdata.taskID = task.id ON taskdata.id = task.dataID
WHERE leaseOwner = %s AND leaseExpires > UNIX_TIMESTAMP() WHERE leaseOwner = %s AND leaseExpires > UNIX_TIMESTAMP()
LIMIT 1', LIMIT 1',
$task_table->getTableName(), $task_table->getTableName(),
@ -97,9 +97,9 @@ class PhabricatorTaskmasterDaemon extends PhabricatorDaemon {
if ($data !== null) { if ($data !== null) {
queryfx( queryfx(
$conn_w, $conn_w,
'DELETE FROM %T WHERE taskID = %d', 'DELETE FROM %T WHERE id = %d',
$taskdata_table->getTableName(), $taskdata_table->getTableName(),
$task->getID()); $task->getDataID());
} }
} catch (Exception $ex) { } catch (Exception $ex) {
$task->setFailureCount($task->getFailureCount() + 1); $task->setFailureCount($task->getFailureCount() + 1);