From 5b1262c98b8ff0c9532f94d572752860d88a7002 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 25 May 2014 09:54:12 -0700 Subject: [PATCH] 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 --- bin/hunks | 1 + scripts/setup/manage_hunks.php | 21 ++++++++ src/__phutil_library_map__.php | 4 ++ ...bricatorHunksManagementMigrateWorkflow.php | 48 +++++++++++++++++++ .../PhabricatorHunksManagementWorkflow.php | 6 +++ .../differential/storage/DifferentialHunk.php | 2 +- 6 files changed, 81 insertions(+), 1 deletion(-) create mode 120000 bin/hunks create mode 100755 scripts/setup/manage_hunks.php create mode 100644 src/applications/differential/management/PhabricatorHunksManagementMigrateWorkflow.php create mode 100644 src/applications/differential/management/PhabricatorHunksManagementWorkflow.php diff --git a/bin/hunks b/bin/hunks new file mode 120000 index 0000000000..dc2cf5492e --- /dev/null +++ b/bin/hunks @@ -0,0 +1 @@ +../scripts/setup/manage_hunks.php \ No newline at end of file diff --git a/scripts/setup/manage_hunks.php b/scripts/setup/manage_hunks.php new file mode 100755 index 0000000000..c4750ece73 --- /dev/null +++ b/scripts/setup/manage_hunks.php @@ -0,0 +1,21 @@ +#!/usr/bin/env php +setTagline('manage hunks'); +$args->setSynopsis(<<parseStandardArguments(); + +$workflows = id(new PhutilSymbolLoader()) + ->setAncestorClass('PhabricatorHunksManagementWorkflow') + ->loadObjects(); +$workflows[] = new PhutilHelpArgumentWorkflow(); +$args->parseWorkflows($workflows); diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index f39e8dfb75..95187206dd 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/differential/management/PhabricatorHunksManagementMigrateWorkflow.php b/src/applications/differential/management/PhabricatorHunksManagementMigrateWorkflow.php new file mode 100644 index 0000000000..3065658743 --- /dev/null +++ b/src/applications/differential/management/PhabricatorHunksManagementMigrateWorkflow.php @@ -0,0 +1,48 @@ +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.')); + } + } + +} diff --git a/src/applications/differential/management/PhabricatorHunksManagementWorkflow.php b/src/applications/differential/management/PhabricatorHunksManagementWorkflow.php new file mode 100644 index 0000000000..b8a66bfe7d --- /dev/null +++ b/src/applications/differential/management/PhabricatorHunksManagementWorkflow.php @@ -0,0 +1,6 @@ +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