1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-19 16:58:48 +02:00

Add a bin/hunks script to manage migrations of hunk data

Summary:
Ref T4045. Ref T5179. While we'll eventually need to force a migration, we can let installs (particularly large installs) do an online migration for now. This moves hunks to the new storage format one at a time.

(Note that nothing writes to the new store yet, so this is the only way to populate it.)

WARNING: Installs, don't run this yet! It won't compress the data. Wait until it can also do compression.

Test Plan: Added a `break;` after migrating one row and moved a few rows over. Spot checked them in the database and viewed the affected diffs.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4045, T5179

Differential Revision: https://secure.phabricator.com/D9291
This commit is contained in:
epriestley 2014-05-25 09:54:12 -07:00
parent 0aa913805d
commit 5b1262c98b
6 changed files with 81 additions and 1 deletions

1
bin/hunks Symbolic link
View file

@ -0,0 +1 @@
../scripts/setup/manage_hunks.php

21
scripts/setup/manage_hunks.php Executable file
View file

@ -0,0 +1,21 @@
#!/usr/bin/env php
<?php
$root = dirname(dirname(dirname(__FILE__)));
require_once $root.'/scripts/__init_script__.php';
$args = new PhutilArgumentParser($argv);
$args->setTagline('manage hunks');
$args->setSynopsis(<<<EOSYNOPSIS
**hunks** __command__ [__options__]
Manage Differential hunk storage.
EOSYNOPSIS
);
$args->parseStandardArguments();
$workflows = id(new PhutilSymbolLoader())
->setAncestorClass('PhabricatorHunksManagementWorkflow')
->loadObjects();
$workflows[] = new PhutilHelpArgumentWorkflow();
$args->parseWorkflows($workflows);

View file

@ -1665,6 +1665,8 @@ phutil_register_library_map(array(
'PhabricatorHomeQuickCreateController' => 'applications/home/controller/PhabricatorHomeQuickCreateController.php',
'PhabricatorHovercardExample' => 'applications/uiexample/examples/PhabricatorHovercardExample.php',
'PhabricatorHovercardView' => 'view/widget/hovercard/PhabricatorHovercardView.php',
'PhabricatorHunksManagementMigrateWorkflow' => 'applications/differential/management/PhabricatorHunksManagementMigrateWorkflow.php',
'PhabricatorHunksManagementWorkflow' => 'applications/differential/management/PhabricatorHunksManagementWorkflow.php',
'PhabricatorIRCBot' => 'infrastructure/daemon/bot/PhabricatorIRCBot.php',
'PhabricatorIRCProtocolAdapter' => 'infrastructure/daemon/bot/adapter/PhabricatorIRCProtocolAdapter.php',
'PhabricatorIRCProtocolHandler' => 'infrastructure/daemon/bot/handler/PhabricatorIRCProtocolHandler.php',
@ -4488,6 +4490,8 @@ phutil_register_library_map(array(
'PhabricatorHomeQuickCreateController' => 'PhabricatorHomeController',
'PhabricatorHovercardExample' => 'PhabricatorUIExample',
'PhabricatorHovercardView' => 'AphrontView',
'PhabricatorHunksManagementMigrateWorkflow' => 'PhabricatorHunksManagementWorkflow',
'PhabricatorHunksManagementWorkflow' => 'PhabricatorManagementWorkflow',
'PhabricatorIRCBot' => 'PhabricatorDaemon',
'PhabricatorIRCProtocolAdapter' => 'PhabricatorBaseProtocolAdapter',
'PhabricatorIRCProtocolHandler' => 'PhabricatorBotHandler',

View file

@ -0,0 +1,48 @@
<?php
final class PhabricatorHunksManagementMigrateWorkflow
extends PhabricatorHunksManagementWorkflow {
protected function didConstruct() {
$this
->setName('migrate')
->setExamples('**migrate**')
->setSynopsis(pht('Migrate hunks to modern storage.'))
->setArguments(array());
}
public function execute(PhutilArgumentParser $args) {
$saw_any_rows = false;
$console = PhutilConsole::getConsole();
$table = new DifferentialHunkLegacy();
foreach (new LiskMigrationIterator($table) as $hunk) {
$saw_any_rows = true;
$id = $hunk->getID();
$console->writeOut("%s\n", pht('Migrating hunk %d...', $id));
$new_hunk = id(new DifferentialHunkModern())
->setChangesetID($hunk->getChangesetID())
->setOldOffset($hunk->getOldOffset())
->setOldLen($hunk->getOldLen())
->setNewOffset($hunk->getNewOffset())
->setNewLen($hunk->getNewLen())
->setChanges($hunk->getChanges())
->setDateCreated($hunk->getDateCreated())
->setDateModified($hunk->getDateModified());
$hunk->openTransaction();
$new_hunk->save();
$hunk->delete();
$hunk->saveTransaction();
}
if ($saw_any_rows) {
$console->writeOut("%s\n", pht('Done.'));
} else {
$console->writeOut("%s\n", pht('No rows to migrate.'));
}
}
}

View file

@ -0,0 +1,6 @@
<?php
abstract class PhabricatorHunksManagementWorkflow
extends PhabricatorManagementWorkflow {
}

View file

@ -57,7 +57,7 @@ abstract class DifferentialHunk extends DifferentialDAO
final private function makeContent($include) {
$results = array();
$lines = explode("\n", $this->changes);
$lines = explode("\n", $this->getChanges());
// NOTE: To determine whether the recomposed file should have a trailing
// newline, we look for a "\ No newline at end of file" line which appears