Skip to content

Commit 5b1262c

Browse files
author
epriestley
committed
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
1 parent 0aa9138 commit 5b1262c

File tree

6 files changed

+81
-1
lines changed

6 files changed

+81
-1
lines changed

bin/hunks

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../scripts/setup/manage_hunks.php

scripts/setup/manage_hunks.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
$root = dirname(dirname(dirname(__FILE__)));
5+
require_once $root.'/scripts/__init_script__.php';
6+
7+
$args = new PhutilArgumentParser($argv);
8+
$args->setTagline('manage hunks');
9+
$args->setSynopsis(<<<EOSYNOPSIS
10+
**hunks** __command__ [__options__]
11+
Manage Differential hunk storage.
12+
13+
EOSYNOPSIS
14+
);
15+
$args->parseStandardArguments();
16+
17+
$workflows = id(new PhutilSymbolLoader())
18+
->setAncestorClass('PhabricatorHunksManagementWorkflow')
19+
->loadObjects();
20+
$workflows[] = new PhutilHelpArgumentWorkflow();
21+
$args->parseWorkflows($workflows);

src/__phutil_library_map__.php

+4
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,8 @@
16651665
'PhabricatorHomeQuickCreateController' => 'applications/home/controller/PhabricatorHomeQuickCreateController.php',
16661666
'PhabricatorHovercardExample' => 'applications/uiexample/examples/PhabricatorHovercardExample.php',
16671667
'PhabricatorHovercardView' => 'view/widget/hovercard/PhabricatorHovercardView.php',
1668+
'PhabricatorHunksManagementMigrateWorkflow' => 'applications/differential/management/PhabricatorHunksManagementMigrateWorkflow.php',
1669+
'PhabricatorHunksManagementWorkflow' => 'applications/differential/management/PhabricatorHunksManagementWorkflow.php',
16681670
'PhabricatorIRCBot' => 'infrastructure/daemon/bot/PhabricatorIRCBot.php',
16691671
'PhabricatorIRCProtocolAdapter' => 'infrastructure/daemon/bot/adapter/PhabricatorIRCProtocolAdapter.php',
16701672
'PhabricatorIRCProtocolHandler' => 'infrastructure/daemon/bot/handler/PhabricatorIRCProtocolHandler.php',
@@ -4488,6 +4490,8 @@
44884490
'PhabricatorHomeQuickCreateController' => 'PhabricatorHomeController',
44894491
'PhabricatorHovercardExample' => 'PhabricatorUIExample',
44904492
'PhabricatorHovercardView' => 'AphrontView',
4493+
'PhabricatorHunksManagementMigrateWorkflow' => 'PhabricatorHunksManagementWorkflow',
4494+
'PhabricatorHunksManagementWorkflow' => 'PhabricatorManagementWorkflow',
44914495
'PhabricatorIRCBot' => 'PhabricatorDaemon',
44924496
'PhabricatorIRCProtocolAdapter' => 'PhabricatorBaseProtocolAdapter',
44934497
'PhabricatorIRCProtocolHandler' => 'PhabricatorBotHandler',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
final class PhabricatorHunksManagementMigrateWorkflow
4+
extends PhabricatorHunksManagementWorkflow {
5+
6+
protected function didConstruct() {
7+
$this
8+
->setName('migrate')
9+
->setExamples('**migrate**')
10+
->setSynopsis(pht('Migrate hunks to modern storage.'))
11+
->setArguments(array());
12+
}
13+
14+
public function execute(PhutilArgumentParser $args) {
15+
$saw_any_rows = false;
16+
$console = PhutilConsole::getConsole();
17+
18+
$table = new DifferentialHunkLegacy();
19+
foreach (new LiskMigrationIterator($table) as $hunk) {
20+
$saw_any_rows = true;
21+
22+
$id = $hunk->getID();
23+
$console->writeOut("%s\n", pht('Migrating hunk %d...', $id));
24+
25+
$new_hunk = id(new DifferentialHunkModern())
26+
->setChangesetID($hunk->getChangesetID())
27+
->setOldOffset($hunk->getOldOffset())
28+
->setOldLen($hunk->getOldLen())
29+
->setNewOffset($hunk->getNewOffset())
30+
->setNewLen($hunk->getNewLen())
31+
->setChanges($hunk->getChanges())
32+
->setDateCreated($hunk->getDateCreated())
33+
->setDateModified($hunk->getDateModified());
34+
35+
$hunk->openTransaction();
36+
$new_hunk->save();
37+
$hunk->delete();
38+
$hunk->saveTransaction();
39+
}
40+
41+
if ($saw_any_rows) {
42+
$console->writeOut("%s\n", pht('Done.'));
43+
} else {
44+
$console->writeOut("%s\n", pht('No rows to migrate.'));
45+
}
46+
}
47+
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
abstract class PhabricatorHunksManagementWorkflow
4+
extends PhabricatorManagementWorkflow {
5+
6+
}

src/applications/differential/storage/DifferentialHunk.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function getContentWithMask($mask) {
5757

5858
final private function makeContent($include) {
5959
$results = array();
60-
$lines = explode("\n", $this->changes);
60+
$lines = explode("\n", $this->getChanges());
6161

6262
// NOTE: To determine whether the recomposed file should have a trailing
6363
// newline, we look for a "\ No newline at end of file" line which appears

0 commit comments

Comments
 (0)