Author: tomekr
Date: Tue May 28 10:17:03 2019
New Revision: 1860237

URL: http://svn.apache.org/viewvc?rev=1860237&view=rev
Log:
OAK-8356: Support append mode in the SegmentStoreMigrator

Modified:
    
jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/SegmentStoreMigrator.java

Modified: 
jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/SegmentStoreMigrator.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/SegmentStoreMigrator.java?rev=1860237&r1=1860236&r2=1860237&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/SegmentStoreMigrator.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/SegmentStoreMigrator.java
 Tue May 28 10:17:03 2019
@@ -67,6 +67,8 @@ public class SegmentStoreMigrator implem
 
     private final String targetName;
 
+    private final boolean appendMode;
+
     private ExecutorService executor = 
Executors.newFixedThreadPool(READ_THREADS + 1);
 
     private SegmentStoreMigrator(Builder builder) {
@@ -74,6 +76,7 @@ public class SegmentStoreMigrator implem
         this.target = builder.target;
         this.sourceName = builder.sourceName;
         this.targetName = builder.targetName;
+        this.appendMode = builder.appendMode;
     }
 
     public void migrate() throws IOException, ExecutionException, 
InterruptedException {
@@ -98,6 +101,7 @@ public class SegmentStoreMigrator implem
         }
         Collections.reverse(journal);
         try (JournalFileWriter writer = 
target.getJournalFile().openJournalWriter()) {
+            writer.truncate();
             for (String line : journal) {
                 writer.writeLine(line);
             }
@@ -107,6 +111,9 @@ public class SegmentStoreMigrator implem
     private void migrateGCJournal() throws IOException {
         log.info("{}/gc.log -> {}", sourceName, targetName);
         GCJournalFile targetGCJournal = target.getGCJournalFile();
+        if (appendMode) {
+            targetGCJournal.truncate();
+        }
         for (String line : source.getGCJournalFile().readLines()) {
             targetGCJournal.writeLine(line);
         }
@@ -131,8 +138,13 @@ public class SegmentStoreMigrator implem
                 new FileStoreMonitorAdapter());
         SegmentArchiveManager targetManager = 
target.createArchiveManager(false, false, new IOMonitorAdapter(),
                 new FileStoreMonitorAdapter());
+        List<String> targetArchives = targetManager.listArchives();
         for (String archiveName : sourceManager.listArchives()) {
             log.info("{}/{} -> {}", sourceName, archiveName, targetName);
+            if (appendMode && targetArchives.contains(archiveName)) {
+                log.info("Already exists, skipping.");
+                continue;
+            }
             try (SegmentArchiveReader reader = 
sourceManager.forceOpen(archiveName)) {
                 SegmentArchiveWriter writer = 
targetManager.create(archiveName);
                 try {
@@ -221,6 +233,8 @@ public class SegmentStoreMigrator implem
 
         private String targetName;
 
+        private boolean appendMode;
+
         public Builder withSource(File dir) {
             this.source = new TarPersistence(dir);
             this.sourceName = storeDescription(SegmentStoreType.TAR, 
dir.getPath());
@@ -257,6 +271,11 @@ public class SegmentStoreMigrator implem
             return this;
         }
 
+        public Builder setAppendMode() {
+            this.appendMode = true;
+            return this;
+        }
+
         public SegmentStoreMigrator build() {
             return new SegmentStoreMigrator(this);
         }


Reply via email to