From 001694bd21a1deb085140379976e25ea030bd9dd Mon Sep 17 00:00:00 2001 From: Luca Milanesio Date: Thu, 22 Aug 2019 00:48:01 +0100 Subject: [PATCH] Output NoteDb migration progress to Flogger Allow to track the progress of the conversion to NoteDb by sending the progress output to Flogger instead of throwing it away. This allows Gerrit admins to keep track of the status of the migration to NoteDb and predict the ETA of the conversion completion. Bug: Issue 11348 Change-Id: I398a118c966faebab64c0dfa718ee268191eae5c --- .../server/notedb/rebuild/NoteDbMigrator.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/java/com/google/gerrit/server/notedb/rebuild/NoteDbMigrator.java b/java/com/google/gerrit/server/notedb/rebuild/NoteDbMigrator.java index 1ac1da2a6b..ef157d6a10 100644 --- a/java/com/google/gerrit/server/notedb/rebuild/NoteDbMigrator.java +++ b/java/com/google/gerrit/server/notedb/rebuild/NoteDbMigrator.java @@ -109,7 +109,6 @@ import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.storage.file.FileBasedConfig; import org.eclipse.jgit.transport.ReceiveCommand; import org.eclipse.jgit.util.FS; -import org.eclipse.jgit.util.io.NullOutputStream; /** One stop shop for migrating a site's change storage from ReviewDb to NoteDb. */ public class NoteDbMigrator implements AutoCloseable { @@ -134,6 +133,20 @@ public class NoteDbMigrator implements AutoCloseable { cfg.setBoolean(SECTION_NOTE_DB, NoteDbTable.CHANGES.key(), TRIAL, trial); } + private static class NoteDbMigrationLoggerOut extends OutputStream { + private StringBuilder outputBuffer = new StringBuilder(); + + @Override + public synchronized void write(int b) throws IOException { + if (b == '\r' || b == '\n') { + logger.atInfo().log(outputBuffer.toString()); + outputBuffer = new StringBuilder(); + } else { + outputBuffer.append(b); + } + } + } + public static class Builder { private final Config cfg; private final SitePaths sitePaths; @@ -156,7 +169,7 @@ public class NoteDbMigrator implements AutoCloseable { private ImmutableList projects = ImmutableList.of(); private ImmutableList skipProjects = ImmutableList.of(); private ImmutableList changes = ImmutableList.of(); - private OutputStream progressOut = NullOutputStream.INSTANCE; + private OutputStream progressOut = new NoteDbMigrationLoggerOut(); private NotesMigrationState stopAtState; private boolean trial; private boolean forceRebuild;