mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-24 06:20:56 +01:00
Use write connection and transactions in SQL patches
Summary: Patches often read from slaves (possibly stale data) and use that information to write on master. It causes problems when applying more patches quickly after each other because data created in previous patch may not be replicated yet. Test Plan: $ bin/storage upgrade Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D4483
This commit is contained in:
parent
f896696fde
commit
e10fdbe77e
15 changed files with 91 additions and 32 deletions
|
@ -1,14 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$conn = $schema_conn;
|
|
||||||
|
|
||||||
echo "Indexing username tokens for typeaheads...\n";
|
echo "Indexing username tokens for typeaheads...\n";
|
||||||
|
|
||||||
$users = id(new PhabricatorUser())->loadAll();
|
$table = new PhabricatorUser();
|
||||||
|
$table->openTransaction();
|
||||||
|
$table->beginReadLocking();
|
||||||
|
|
||||||
|
$users = $table->loadAll();
|
||||||
echo count($users)." users to index";
|
echo count($users)." users to index";
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
$user->updateNameTokens();
|
$user->updateNameTokens();
|
||||||
echo ".";
|
echo ".";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$table->endReadLocking();
|
||||||
|
$table->saveTransaction();
|
||||||
echo "\nDone.\n";
|
echo "\nDone.\n";
|
||||||
|
|
|
@ -1,15 +1,22 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
echo "Generating file keys...\n";
|
echo "Generating file keys...\n";
|
||||||
$files = id(new PhabricatorFile())->loadAllWhere('secretKey IS NULL');
|
$table = new PhabricatorFile();
|
||||||
|
$table->openTransaction();
|
||||||
|
$table->beginReadLocking();
|
||||||
|
|
||||||
|
$files = $table->loadAllWhere('secretKey IS NULL');
|
||||||
echo count($files).' files to generate keys for';
|
echo count($files).' files to generate keys for';
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
queryfx(
|
queryfx(
|
||||||
$file->establishConnection('r'),
|
$file->establishConnection('w'),
|
||||||
'UPDATE %T SET secretKey = %s WHERE id = %d',
|
'UPDATE %T SET secretKey = %s WHERE id = %d',
|
||||||
$file->getTableName(),
|
$file->getTableName(),
|
||||||
$file->generateSecretKey(),
|
$file->generateSecretKey(),
|
||||||
$file->getID());
|
$file->getID());
|
||||||
echo '.';
|
echo '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$table->endReadLocking();
|
||||||
|
$table->saveTransaction();
|
||||||
echo "\nDone.\n";
|
echo "\nDone.\n";
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
echo "Ensuring project names are unique enough...\n";
|
echo "Ensuring project names are unique enough...\n";
|
||||||
$projects = id(new PhabricatorProject())->loadAll();
|
$table = new PhabricatorProject();
|
||||||
|
$table->openTransaction();
|
||||||
|
$table->beginReadLocking();
|
||||||
|
|
||||||
|
$projects = $table->loadAll();
|
||||||
|
|
||||||
$slug_map = array();
|
$slug_map = array();
|
||||||
|
|
||||||
|
@ -66,6 +70,8 @@ while ($update) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$table->endReadLocking();
|
||||||
|
$table->saveTransaction();
|
||||||
echo "Done.\n";
|
echo "Done.\n";
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,12 @@
|
||||||
echo "Stripping remotes from repository default branches...\n";
|
echo "Stripping remotes from repository default branches...\n";
|
||||||
|
|
||||||
$table = new PhabricatorRepository();
|
$table = new PhabricatorRepository();
|
||||||
|
$table->openTransaction();
|
||||||
$conn_w = $table->establishConnection('w');
|
$conn_w = $table->establishConnection('w');
|
||||||
|
|
||||||
$repos = queryfx_all(
|
$repos = queryfx_all(
|
||||||
$conn_w,
|
$conn_w,
|
||||||
'SELECT id, name, details FROM %T WHERE versionControlSystem = %s',
|
'SELECT id, name, details FROM %T WHERE versionControlSystem = %s FOR UPDATE',
|
||||||
$table->getTableName(),
|
$table->getTableName(),
|
||||||
'git');
|
'git');
|
||||||
|
|
||||||
|
@ -39,4 +40,5 @@ foreach ($repos as $repo) {
|
||||||
$id);
|
$id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$table->saveTransaction();
|
||||||
echo "Done.\n";
|
echo "Done.\n";
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
echo "Checking for rules that can be converted to 'personal'. ";
|
echo "Checking for rules that can be converted to 'personal'. ";
|
||||||
|
$table = new HeraldRule();
|
||||||
|
$table->openTransaction();
|
||||||
|
$table->beginReadLocking();
|
||||||
|
|
||||||
$rules = id(new HeraldRule())->loadAll();
|
$rules = $table->loadAll();
|
||||||
|
|
||||||
foreach ($rules as $rule) {
|
foreach ($rules as $rule) {
|
||||||
if ($rule->getRuleType() !== HeraldRuleTypeConfig::RULE_TYPE_PERSONAL) {
|
if ($rule->getRuleType() !== HeraldRuleTypeConfig::RULE_TYPE_PERSONAL) {
|
||||||
|
@ -43,4 +46,6 @@ foreach ($rules as $rule) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Done. ";
|
$table->endReadLocking();
|
||||||
|
$table->saveTransaction();
|
||||||
|
echo "Done.\n";
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
echo "Cleaning up old Herald rule applied rows...\n";
|
echo "Cleaning up old Herald rule applied rows...\n";
|
||||||
|
$table = new HeraldRule();
|
||||||
|
$table->openTransaction();
|
||||||
|
$table->beginReadLocking();
|
||||||
|
|
||||||
$rules = id(new HeraldRule())->loadAll();
|
$rules = $table->loadAll();
|
||||||
foreach ($rules as $key => $rule) {
|
foreach ($rules as $key => $rule) {
|
||||||
$first_policy = HeraldRepetitionPolicyConfig::toInt(
|
$first_policy = HeraldRepetitionPolicyConfig::toInt(
|
||||||
HeraldRepetitionPolicyConfig::FIRST);
|
HeraldRepetitionPolicyConfig::FIRST);
|
||||||
|
@ -11,7 +14,7 @@ foreach ($rules as $key => $rule) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$conn_w = id(new HeraldRule())->establishConnection('w');
|
$conn_w = $table->establishConnection('w');
|
||||||
|
|
||||||
$clause = '';
|
$clause = '';
|
||||||
if ($rules) {
|
if ($rules) {
|
||||||
|
@ -31,5 +34,6 @@ do {
|
||||||
echo ".";
|
echo ".";
|
||||||
} while ($conn_w->getAffectedRows());
|
} while ($conn_w->getAffectedRows());
|
||||||
|
|
||||||
echo "\n";
|
$table->endReadLocking();
|
||||||
echo "Done.\n";
|
$table->saveTransaction();
|
||||||
|
echo "\nDone.\n";
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
echo "Updating old commit authors...\n";
|
echo "Updating old commit authors...\n";
|
||||||
|
|
||||||
$table = new PhabricatorRepositoryCommit();
|
$table = new PhabricatorRepositoryCommit();
|
||||||
|
$table->openTransaction();
|
||||||
|
|
||||||
$conn = $table->establishConnection('w');
|
$conn = $table->establishConnection('w');
|
||||||
$data = new PhabricatorRepositoryCommitData();
|
$data = new PhabricatorRepositoryCommitData();
|
||||||
$commits = queryfx_all(
|
$commits = queryfx_all(
|
||||||
$conn,
|
$conn,
|
||||||
'SELECT c.id id, c.authorPHID authorPHID, d.commitDetails details
|
'SELECT c.id id, c.authorPHID authorPHID, d.commitDetails details
|
||||||
FROM %T c JOIN %T d ON d.commitID = c.id
|
FROM %T c JOIN %T d ON d.commitID = c.id
|
||||||
WHERE c.authorPHID IS NULL',
|
WHERE c.authorPHID IS NULL
|
||||||
|
FOR UPDATE',
|
||||||
$table->getTableName(),
|
$table->getTableName(),
|
||||||
$data->getTableName());
|
$data->getTableName());
|
||||||
|
|
||||||
|
@ -28,16 +30,16 @@ foreach ($commits as $commit) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$table->saveTransaction();
|
||||||
echo "Done.\n";
|
echo "Done.\n";
|
||||||
|
|
||||||
|
|
||||||
echo "Updating old commit mailKeys...\n";
|
echo "Updating old commit mailKeys...\n";
|
||||||
|
$table->openTransaction();
|
||||||
|
|
||||||
$table = new PhabricatorRepositoryCommit();
|
|
||||||
$conn = $table->establishConnection('w');
|
|
||||||
$commits = queryfx_all(
|
$commits = queryfx_all(
|
||||||
$conn,
|
$conn,
|
||||||
'SELECT id FROM %T WHERE mailKey = %s',
|
'SELECT id FROM %T WHERE mailKey = %s FOR UPDATE',
|
||||||
$table->getTableName(),
|
$table->getTableName(),
|
||||||
'');
|
'');
|
||||||
|
|
||||||
|
@ -52,4 +54,5 @@ foreach ($commits as $commit) {
|
||||||
echo "#{$id}\n";
|
echo "#{$id}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$table->saveTransaction();
|
||||||
echo "Done.\n";
|
echo "Done.\n";
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$table = new DifferentialRevision();
|
$table = new DifferentialRevision();
|
||||||
|
$table->openTransaction();
|
||||||
|
$table->beginReadLocking();
|
||||||
$conn_w = $table->establishConnection('w');
|
$conn_w = $table->establishConnection('w');
|
||||||
|
|
||||||
echo "Migrating revisions";
|
echo "Migrating revisions";
|
||||||
do {
|
do {
|
||||||
$revisions = id(new DifferentialRevision())
|
$revisions = $table->loadAllWhere('branchName IS NULL LIMIT 1000');
|
||||||
->loadAllWhere('branchName IS NULL LIMIT 1000');
|
|
||||||
|
|
||||||
foreach ($revisions as $revision) {
|
foreach ($revisions as $revision) {
|
||||||
echo ".";
|
echo ".";
|
||||||
|
@ -28,4 +29,7 @@ do {
|
||||||
$revision->getID());
|
$revision->getID());
|
||||||
}
|
}
|
||||||
} while (count($revisions) == 1000);
|
} while (count($revisions) == 1000);
|
||||||
|
|
||||||
|
$table->endReadLocking();
|
||||||
|
$table->saveTransaction();
|
||||||
echo "\nDone.\n";
|
echo "\nDone.\n";
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
echo "Giving image macros PHIDs";
|
echo "Giving image macros PHIDs";
|
||||||
foreach (new LiskMigrationIterator(new PhabricatorFileImageMacro()) as $macro) {
|
$table = new PhabricatorFileImageMacro();
|
||||||
|
$table->openTransaction();
|
||||||
|
|
||||||
|
foreach (new LiskMigrationIterator($table) as $macro) {
|
||||||
if ($macro->getPHID()) {
|
if ($macro->getPHID()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -9,10 +12,12 @@ foreach (new LiskMigrationIterator(new PhabricatorFileImageMacro()) as $macro) {
|
||||||
echo ".";
|
echo ".";
|
||||||
|
|
||||||
queryfx(
|
queryfx(
|
||||||
$macro->establishConnection('r'),
|
$macro->establishConnection('w'),
|
||||||
'UPDATE %T SET phid = %s WHERE id = %d',
|
'UPDATE %T SET phid = %s WHERE id = %d',
|
||||||
$macro->getTableName(),
|
$macro->getTableName(),
|
||||||
$macro->generatePHID(),
|
$macro->generatePHID(),
|
||||||
$macro->getID());
|
$macro->getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$table->saveTransaction();
|
||||||
echo "\nDone.\n";
|
echo "\nDone.\n";
|
||||||
|
|
|
@ -3,16 +3,16 @@
|
||||||
echo "Migrating user emails...\n";
|
echo "Migrating user emails...\n";
|
||||||
|
|
||||||
$table = new PhabricatorUser();
|
$table = new PhabricatorUser();
|
||||||
$conn = $table->establishConnection('r');
|
$table->openTransaction();
|
||||||
|
$conn = $table->establishConnection('w');
|
||||||
|
|
||||||
$emails = queryfx_all(
|
$emails = queryfx_all(
|
||||||
$conn,
|
$conn,
|
||||||
'SELECT phid, email FROM %T',
|
'SELECT phid, email FROM %T LOCK IN SHARE MODE',
|
||||||
$table->getTableName());
|
$table->getTableName());
|
||||||
$emails = ipull($emails, 'email', 'phid');
|
$emails = ipull($emails, 'email', 'phid');
|
||||||
|
|
||||||
$etable = new PhabricatorUserEmail();
|
$etable = new PhabricatorUserEmail();
|
||||||
$econn = $etable->establishConnection('w');
|
|
||||||
|
|
||||||
foreach ($emails as $phid => $email) {
|
foreach ($emails as $phid => $email) {
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ foreach ($emails as $phid => $email) {
|
||||||
|
|
||||||
echo "Migrating '{$phid}'...\n";
|
echo "Migrating '{$phid}'...\n";
|
||||||
queryfx(
|
queryfx(
|
||||||
$econn,
|
$conn,
|
||||||
'INSERT INTO %T (userPHID, address, verificationCode, isVerified, isPrimary)
|
'INSERT INTO %T (userPHID, address, verificationCode, isVerified, isPrimary)
|
||||||
VALUES (%s, %s, %s, 1, 1)',
|
VALUES (%s, %s, %s, 1, 1)',
|
||||||
$etable->getTableName(),
|
$etable->getTableName(),
|
||||||
|
@ -30,4 +30,5 @@ foreach ($emails as $phid => $email) {
|
||||||
Filesystem::readRandomCharacters(24));
|
Filesystem::readRandomCharacters(24));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$table->saveTransaction();
|
||||||
echo "Done.\n";
|
echo "Done.\n";
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
echo "Migrating differential dependencies to edges...\n";
|
echo "Migrating differential dependencies to edges...\n";
|
||||||
foreach (new LiskMigrationIterator(new DifferentialRevision()) as $rev) {
|
$table = new DifferentialRevision();
|
||||||
|
$table->openTransaction();
|
||||||
|
|
||||||
|
foreach (new LiskMigrationIterator($table) as $rev) {
|
||||||
$id = $rev->getID();
|
$id = $rev->getID();
|
||||||
echo "Revision {$id}: ";
|
echo "Revision {$id}: ";
|
||||||
|
|
||||||
|
@ -23,4 +26,5 @@ foreach (new LiskMigrationIterator(new DifferentialRevision()) as $rev) {
|
||||||
echo "OKAY\n";
|
echo "OKAY\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$table->saveTransaction();
|
||||||
echo "Done.\n";
|
echo "Done.\n";
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
echo "Migrating task dependencies to edges...\n";
|
echo "Migrating task dependencies to edges...\n";
|
||||||
foreach (new LiskMigrationIterator(new ManiphestTask()) as $task) {
|
$table = new ManiphestTask();
|
||||||
|
$table->openTransaction();
|
||||||
|
|
||||||
|
foreach (new LiskMigrationIterator($table) as $task) {
|
||||||
$id = $task->getID();
|
$id = $task->getID();
|
||||||
echo "Task {$id}: ";
|
echo "Task {$id}: ";
|
||||||
|
|
||||||
|
@ -23,4 +26,5 @@ foreach (new LiskMigrationIterator(new ManiphestTask()) as $task) {
|
||||||
echo "OKAY\n";
|
echo "OKAY\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$table->saveTransaction();
|
||||||
echo "Done.\n";
|
echo "Done.\n";
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
echo "Migrating task revisions to edges...\n";
|
echo "Migrating task revisions to edges...\n";
|
||||||
foreach (new LiskMigrationIterator(new ManiphestTask()) as $task) {
|
$table = new ManiphestTask();
|
||||||
|
$table->establishConnection('w');
|
||||||
|
|
||||||
|
foreach (new LiskMigrationIterator($table) as $task) {
|
||||||
$id = $task->getID();
|
$id = $task->getID();
|
||||||
echo "Task {$id}: ";
|
echo "Task {$id}: ";
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
echo "Migrating project members to edges...\n";
|
echo "Migrating project members to edges...\n";
|
||||||
foreach (new LiskMigrationIterator(new PhabricatorProject()) as $proj) {
|
$table = new PhabricatorProject();
|
||||||
|
$table->establishConnection('w');
|
||||||
|
|
||||||
|
foreach (new LiskMigrationIterator($table) as $proj) {
|
||||||
$id = $proj->getID();
|
$id = $proj->getID();
|
||||||
echo "Project {$id}: ";
|
echo "Project {$id}: ";
|
||||||
|
|
||||||
$members = queryfx_all(
|
$members = queryfx_all(
|
||||||
$proj->establishConnection('r'),
|
$proj->establishConnection('w'),
|
||||||
'SELECT userPHID FROM %T WHERE projectPHID = %s',
|
'SELECT userPHID FROM %T WHERE projectPHID = %s',
|
||||||
'project_affiliation',
|
'project_affiliation',
|
||||||
$proj->getPHID());
|
$proj->getPHID());
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
echo "Populating Questions with mail keys...\n";
|
echo "Populating Questions with mail keys...\n";
|
||||||
foreach (new LiskMigrationIterator(new PonderQuestion()) as $question) {
|
$table = new PonderQuestion();
|
||||||
|
$table->openTransaction();
|
||||||
|
|
||||||
|
foreach (new LiskMigrationIterator($table) as $question) {
|
||||||
$id = $question->getID();
|
$id = $question->getID();
|
||||||
|
|
||||||
echo "Question {$id}: ";
|
echo "Question {$id}: ";
|
||||||
|
@ -18,4 +21,5 @@ foreach (new LiskMigrationIterator(new PonderQuestion()) as $question) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$table->saveTransaction();
|
||||||
echo "Done.\n";
|
echo "Done.\n";
|
||||||
|
|
Loading…
Reference in a new issue