You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by to...@apache.org on 2019/09/23 09:52:03 UTC

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

Author: tomekr
Date: Mon Sep 23 09:52:03 2019
New Revision: 1867372

URL: http://svn.apache.org/viewvc?rev=1867372&view=rev
Log:
OAK-8640: Allow to only copy last journal entry 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=1867372&r1=1867371&r2=1867372&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 Mon Sep 23 09:52:03 2019
@@ -70,6 +70,8 @@ public class SegmentStoreMigrator implem
 
     private final boolean appendMode;
 
+    private final boolean onlyLastJournalEntry;
+
     private ExecutorService executor = Executors.newFixedThreadPool(READ_THREADS + 1);
 
     private SegmentStoreMigrator(Builder builder) {
@@ -78,6 +80,7 @@ public class SegmentStoreMigrator implem
         this.sourceName = builder.sourceName;
         this.targetName = builder.targetName;
         this.appendMode = builder.appendMode;
+        this.onlyLastJournalEntry = builder.onlyLastJournalEntry;
     }
 
     public void migrate() throws IOException, ExecutionException, InterruptedException {
@@ -94,13 +97,22 @@ public class SegmentStoreMigrator implem
             return;
         }
         List<String> journal = new ArrayList<>();
-        try (JournalFileReader reader = source.getJournalFile().openJournalReader()) {
-            String line;
-            while ((line = reader.readLine()) != null) {
-                journal.add(line);
+        if (onlyLastJournalEntry) {
+            try (JournalFileReader reader = source.getJournalFile().openJournalReader()) {
+                String line = reader.readLine();
+                if (line != null) {
+                    journal.add(line);
+                }
+            }
+        } else {
+            try (JournalFileReader reader = source.getJournalFile().openJournalReader()) {
+                String line;
+                while ((line = reader.readLine()) != null) {
+                    journal.add(line);
+                }
             }
+            Collections.reverse(journal);
         }
-        Collections.reverse(journal);
         try (JournalFileWriter writer = target.getJournalFile().openJournalWriter()) {
             writer.truncate();
             for (String line : journal) {
@@ -236,6 +248,8 @@ public class SegmentStoreMigrator implem
 
         private boolean appendMode;
 
+        private boolean onlyLastJournalEntry;
+
         public Builder withSource(File dir) {
             this.source = new TarPersistence(dir);
             this.sourceName = storeDescription(SegmentStoreType.TAR, dir.getPath());
@@ -277,6 +291,11 @@ public class SegmentStoreMigrator implem
             return this;
         }
 
+        public Builder withOnlyLastJournalEntry() {
+            this.onlyLastJournalEntry = onlyLastJournalEntry;
+            return this;
+        }
+
         public SegmentStoreMigrator build() {
             return new SegmentStoreMigrator(this);
         }