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 fr...@apache.org on 2019/01/03 14:11:25 UTC

svn commit: r1850238 - in /jackrabbit/oak/trunk: oak-run/src/main/java/org/apache/jackrabbit/oak/run/ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/ oak-se...

Author: frm
Date: Thu Jan  3 14:11:24 2019
New Revision: 1850238

URL: http://svn.apache.org/viewvc?rev=1850238&view=rev
Log:
OAK-7719 - Let check use the specified journal consistently

Modified:
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/CheckCommand.java
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStoreBuilder.java
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarPersistence.java
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Check.java
    jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/tool/CheckInvalidRepositoryTest.java
    jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/tool/CheckValidRepositoryTest.java

Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/CheckCommand.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/CheckCommand.java?rev=1850238&r1=1850237&r2=1850238&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/CheckCommand.java (original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/CheckCommand.java Thu Jan  3 14:11:24 2019
@@ -17,15 +17,12 @@
 
 package org.apache.jackrabbit.oak.run;
 
-import static org.apache.jackrabbit.oak.segment.FileStoreHelper.isValidFileStoreOrFail;
-
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.LinkedHashSet;
 import java.util.Set;
 
-import joptsimple.ArgumentAcceptingOptionSpec;
 import joptsimple.OptionParser;
 import joptsimple.OptionSet;
 import joptsimple.OptionSpec;
@@ -37,66 +34,80 @@ class CheckCommand implements Command {
     @Override
     public void execute(String... args) throws Exception {
         OptionParser parser = new OptionParser();
-        ArgumentAcceptingOptionSpec<String> journal = parser.accepts(
-                "journal", "journal file")
-                .withRequiredArg().ofType(String.class).defaultsTo("journal.log");
-        ArgumentAcceptingOptionSpec<Long> notify = parser.accepts(
-                "notify", "number of seconds between progress notifications")
-                .withRequiredArg().ofType(Long.class).defaultsTo(Long.MAX_VALUE);
+        OptionSpec<File> journal = parser.accepts("journal", "journal file")
+            .withRequiredArg()
+            .ofType(File.class);
+        OptionSpec<Long> notify = parser.accepts("notify", "number of seconds between progress notifications")
+            .withRequiredArg()
+            .ofType(Long.class)
+            .defaultsTo(Long.MAX_VALUE);
         OptionSpec<?> bin = parser.accepts("bin", "read the content of binary properties");
-        ArgumentAcceptingOptionSpec<String> filter = parser.accepts(
-                "filter", "comma separated content paths to be checked")
-                .withRequiredArg().ofType(String.class).withValuesSeparatedBy(',').defaultsTo("/");
+        OptionSpec<String> filter = parser.accepts("filter", "comma separated content paths to be checked")
+            .withRequiredArg()
+            .ofType(String.class)
+            .withValuesSeparatedBy(',')
+            .defaultsTo("/");
         OptionSpec<?> head = parser.accepts("head", "checks only latest /root (i.e without checkpoints)");
-        ArgumentAcceptingOptionSpec<String> cp = parser.accepts(
-                "checkpoints", "checks only specified checkpoints (comma separated); use --checkpoints all to check all checkpoints")
-                .withOptionalArg().ofType(String.class).withValuesSeparatedBy(',').defaultsTo("all");
+        OptionSpec<String> cp = parser.accepts("checkpoints", "checks only specified checkpoints (comma separated); use --checkpoints all to check all checkpoints")
+            .withOptionalArg()
+            .ofType(String.class)
+            .withValuesSeparatedBy(',')
+            .defaultsTo("all");
         OptionSpec<?> ioStatistics = parser.accepts("io-stats", "Print I/O statistics (only for oak-segment-tar)");
-
+        OptionSpec<File> dir = parser.nonOptions()
+            .describedAs("path")
+            .ofType(File.class);
         OptionSet options = parser.parse(args);
-        
-        PrintWriter out = new PrintWriter(System.out, true);
-        PrintWriter err = new PrintWriter(System.err, true);
 
-        if (options.nonOptionArguments().size() != 1) {
-            printUsage(parser, err);
+        if (options.valuesOf(dir).isEmpty()) {
+            printUsageAndExit(parser, "Segment Store path not specified");
         }
 
-        File dir = isValidFileStoreOrFail(new File(options.nonOptionArguments().get(0).toString()));
-        String journalFileName = journal.value(options);
-        long debugLevel = notify.value(options);
-        Set<String> filterPaths = new LinkedHashSet<String>(filter.values(options));
-        Set<String> checkpoints = new LinkedHashSet<>();
-        if (options.has(cp) || !options.has(head)) {
-            checkpoints.addAll(cp.values(options));
+        if (options.valuesOf(dir).size() > 1) {
+            printUsageAndExit(parser, "Too many Segment Store paths specified");
         }
 
-        boolean checkHead = !options.has(cp) || options.has(head);
-
-        int statusCode = Check.builder()
-            .withPath(dir)
-            .withJournal(journalFileName)
-            .withDebugInterval(debugLevel)
+        Check.Builder builder = Check.builder()
+            .withPath(options.valueOf(dir))
+            .withDebugInterval(notify.value(options))
             .withCheckBinaries(options.has(bin))
-            .withCheckHead(checkHead)
-            .withCheckpoints(checkpoints)
-            .withFilterPaths(filterPaths)
+            .withCheckHead(shouldCheckHead(options, head, cp))
+            .withCheckpoints(toCheckpointsSet(options, head, cp))
+            .withFilterPaths(toSet(options, filter))
             .withIOStatistics(options.has(ioStatistics))
-            .withOutWriter(out)
-            .withErrWriter(err)
-            .build()
-            .run();
-        System.exit(statusCode);
+            .withOutWriter(new PrintWriter(System.out, true))
+            .withErrWriter(new PrintWriter(System.err, true));
+
+        if (options.has(journal)) {
+            builder.withJournal(journal.value(options));
+        }
+
+        System.exit(builder.build().run());
     }
 
-    private void printUsage(OptionParser parser, PrintWriter err, String... messages) throws IOException {
+    private void printUsageAndExit(OptionParser parser, String... messages) throws IOException {
         for (String message : messages) {
-            err.println(message);
+            System.err.println(message);
         }
-        
-        err.println("usage: check path/to/segmentstore <options>");
-        parser.printHelpOn(err);
+        System.err.println("usage: check path/to/segmentstore <options>");
+        parser.printHelpOn(System.err);
         System.exit(1);
     }
 
+    private static Set<String> toSet(OptionSet options, OptionSpec<String> option) {
+        return new LinkedHashSet<>(option.values(options));
+    }
+
+    private static Set<String> toCheckpointsSet(OptionSet options, OptionSpec<?> head, OptionSpec<String> cp) {
+        Set<String> checkpoints = new LinkedHashSet<>();
+        if (options.has(cp) || !options.has(head)) {
+            checkpoints.addAll(cp.values(options));
+        }
+        return checkpoints;
+    }
+
+    private static boolean shouldCheckHead(OptionSet options, OptionSpec<?> head, OptionSpec<String> cp) {
+        return !options.has(cp) || options.has(head);
+    }
+
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStoreBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStoreBuilder.java?rev=1850238&r1=1850237&r2=1850238&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStoreBuilder.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStoreBuilder.java Thu Jan  3 14:11:24 2019
@@ -37,7 +37,6 @@ import java.io.IOException;
 import java.util.Set;
 
 import com.google.common.base.Predicate;
-
 import org.apache.jackrabbit.oak.segment.CacheWeights.NodeCacheWeigher;
 import org.apache.jackrabbit.oak.segment.CacheWeights.StringCacheWeigher;
 import org.apache.jackrabbit.oak.segment.CacheWeights.TemplateCacheWeigher;
@@ -353,7 +352,7 @@ public class FileStoreBuilder {
         return this;
     }
 
-    public FileStoreBuilder withCustomPersistence(SegmentNodeStorePersistence persistence) throws IOException {
+    public FileStoreBuilder withCustomPersistence(SegmentNodeStorePersistence persistence) {
         this.persistence = persistence;
         return this;
     }

Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarPersistence.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarPersistence.java?rev=1850238&r1=1850237&r2=1850238&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarPersistence.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarPersistence.java Thu Jan  3 14:11:24 2019
@@ -18,6 +18,13 @@
  */
 package org.apache.jackrabbit.oak.segment.file.tar;
 
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.channels.FileLock;
+import java.nio.channels.OverlappingFileLockException;
+import java.util.Collection;
+
 import org.apache.commons.io.FileUtils;
 import org.apache.jackrabbit.oak.segment.file.LocalGCJournalFile;
 import org.apache.jackrabbit.oak.segment.file.LocalManifestFile;
@@ -30,13 +37,6 @@ import org.apache.jackrabbit.oak.segment
 import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveManager;
 import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentNodeStorePersistence;
 
-import java.io.File;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.nio.channels.FileLock;
-import java.nio.channels.OverlappingFileLockException;
-import java.util.Collection;
-
 public class TarPersistence implements SegmentNodeStorePersistence {
 
     private static final String LOCK_FILE_NAME = "repo.lock";
@@ -49,8 +49,15 @@ public class TarPersistence implements S
 
     private final File directory;
 
+    private final File journal;
+
     public TarPersistence(File directory) {
+        this(directory, new File(directory, JOURNAL_FILE_NAME));
+    }
+
+    public TarPersistence(File directory, File journal) {
         this.directory = directory;
+        this.journal = journal;
     }
 
     @Override
@@ -67,7 +74,7 @@ public class TarPersistence implements S
 
     @Override
     public JournalFile getJournalFile() {
-        return new LocalJournalFile(directory, JOURNAL_FILE_NAME);
+        return new LocalJournalFile(journal);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Check.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Check.java?rev=1850238&r1=1850237&r2=1850238&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Check.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/Check.java Thu Jan  3 14:11:24 2019
@@ -41,6 +41,7 @@ import org.apache.jackrabbit.oak.segment
 import org.apache.jackrabbit.oak.segment.file.JournalReader;
 import org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore;
 import org.apache.jackrabbit.oak.segment.file.tar.LocalJournalFile;
+import org.apache.jackrabbit.oak.segment.file.tar.TarPersistence;
 import org.apache.jackrabbit.oak.segment.file.tooling.ConsistencyChecker;
 import org.apache.jackrabbit.oak.segment.file.tooling.ConsistencyChecker.ConsistencyCheckResult;
 import org.apache.jackrabbit.oak.segment.file.tooling.ConsistencyChecker.Revision;
@@ -67,7 +68,7 @@ public class Check {
 
         private File path;
 
-        private String journal;
+        private File journal;
 
         private long debugInterval = Long.MAX_VALUE;
 
@@ -102,12 +103,13 @@ public class Check {
 
         /**
          * The path to the journal of the segment store. This parameter is
-         * required.
+         * optional. If not provided, the journal in the default location is
+         * used.
          *
          * @param journal the path to the journal of the segment store.
          * @return this builder.
          */
-        public Builder withJournal(String journal) {
+        public Builder withJournal(File journal) {
             this.journal = checkNotNull(journal);
             return this;
         }
@@ -219,7 +221,6 @@ public class Check {
          */
         public Check build() {
             checkNotNull(path);
-            checkNotNull(journal);
             return new Check(this);
         }
 
@@ -244,7 +245,7 @@ public class Check {
 
     private final File path;
 
-    private final String journal;
+    private final File journal;
 
     private final long debugInterval;
 
@@ -270,7 +271,6 @@ public class Check {
 
     private Check(Builder builder) {
         this.path = builder.path;
-        this.journal = builder.journal;
         this.debugInterval = builder.debugInterval;
         this.checkHead = builder.checkHead;
         this.checkBinaries = builder.checkBinaries;
@@ -279,12 +279,21 @@ public class Check {
         this.ioStatistics = builder.ioStatistics;
         this.out = builder.outWriter;
         this.err = builder.errWriter;
+        this.journal = journalPath(builder.path, builder.journal);
+    }
+
+    private static File journalPath(File segmentStore, File journal) {
+        if (journal == null) {
+            return new File(segmentStore, "journal.log");
+        }
+        return journal;
     }
 
     public int run() {
         StatisticsIOMonitor ioMonitor = new StatisticsIOMonitor();
 
-        FileStoreBuilder builder = fileStoreBuilder(path);
+        FileStoreBuilder builder = fileStoreBuilder(path)
+            .withCustomPersistence(new TarPersistence(this.path, this.journal));
 
         if (ioStatistics) {
             builder.withIOMonitor(ioMonitor);
@@ -292,7 +301,7 @@ public class Check {
 
         try (
             ReadOnlyFileStore store = builder.buildReadOnly();
-            JournalReader journal = new JournalReader(new LocalJournalFile(path, this.journal))
+            JournalReader journal = new JournalReader(new LocalJournalFile(this.journal))
         ) {
             run(store, journal);
 

Modified: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/tool/CheckInvalidRepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/tool/CheckInvalidRepositoryTest.java?rev=1850238&r1=1850237&r2=1850238&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/tool/CheckInvalidRepositoryTest.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/tool/CheckInvalidRepositoryTest.java Thu Jan  3 14:11:24 2019
@@ -60,7 +60,6 @@ public class CheckInvalidRepositoryTest
 
         Check.builder()
             .withPath(new File(temporaryFolder.getRoot().getAbsolutePath()))
-            .withJournal("journal.log")
             .withDebugInterval(Long.MAX_VALUE)
             .withCheckHead(true)
             .withCheckpoints(checkpoints)
@@ -94,7 +93,6 @@ public class CheckInvalidRepositoryTest
 
         Check.builder()
             .withPath(new File(temporaryFolder.getRoot().getAbsolutePath()))
-            .withJournal("journal.log")
             .withDebugInterval(Long.MAX_VALUE)
             .withCheckBinaries(true)
             .withCheckHead(true)
@@ -128,7 +126,6 @@ public class CheckInvalidRepositoryTest
 
         Check.builder()
             .withPath(new File(temporaryFolder.getRoot().getAbsolutePath()))
-            .withJournal("journal.log")
             .withDebugInterval(Long.MAX_VALUE)
             .withCheckBinaries(true)
             .withCheckHead(true)
@@ -161,7 +158,6 @@ public class CheckInvalidRepositoryTest
 
         Check.builder()
             .withPath(new File(temporaryFolder.getRoot().getAbsolutePath()))
-            .withJournal("journal.log")
             .withDebugInterval(Long.MAX_VALUE)
             .withCheckBinaries(true)
             .withCheckHead(true)
@@ -199,7 +195,6 @@ public class CheckInvalidRepositoryTest
 
         Check.builder()
             .withPath(new File(temporaryFolder.getRoot().getAbsolutePath()))
-            .withJournal("journal.log")
             .withDebugInterval(Long.MAX_VALUE)
             .withCheckBinaries(true)
             .withCheckpoints(cps)
@@ -240,7 +235,7 @@ public class CheckInvalidRepositoryTest
 
         Check.builder()
             .withPath(segmentStoreFolder)
-            .withJournal("journal.log.large")
+            .withJournal(largeJournalFile)
             .withDebugInterval(Long.MAX_VALUE)
             .withCheckBinaries(true)
             .withCheckHead(true)

Modified: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/tool/CheckValidRepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/tool/CheckValidRepositoryTest.java?rev=1850238&r1=1850237&r2=1850238&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/tool/CheckValidRepositoryTest.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/tool/CheckValidRepositoryTest.java Thu Jan  3 14:11:24 2019
@@ -47,7 +47,6 @@ public class CheckValidRepositoryTest ex
 
         Check.builder()
             .withPath(new File(temporaryFolder.getRoot().getAbsolutePath()))
-            .withJournal("journal.log")
             .withDebugInterval(Long.MAX_VALUE)
             .withCheckBinaries(true)
             .withCheckHead(true)
@@ -85,7 +84,6 @@ public class CheckValidRepositoryTest ex
 
         Check.builder()
             .withPath(new File(temporaryFolder.getRoot().getAbsolutePath()))
-            .withJournal("journal.log")
             .withDebugInterval(Long.MAX_VALUE)
             .withCheckBinaries(true)
             .withCheckHead(true)
@@ -120,7 +118,6 @@ public class CheckValidRepositoryTest ex
 
         Check.builder()
             .withPath(new File(temporaryFolder.getRoot().getAbsolutePath()))
-            .withJournal("journal.log")
             .withDebugInterval(Long.MAX_VALUE)
             .withCheckHead(true)
             .withCheckpoints(new HashSet<String>())
@@ -155,7 +152,6 @@ public class CheckValidRepositoryTest ex
 
         Check.builder()
             .withPath(new File(temporaryFolder.getRoot().getAbsolutePath()))
-            .withJournal("journal.log")
             .withDebugInterval(Long.MAX_VALUE)
             .withCheckHead(true)
             .withCheckpoints(new HashSet<String>())
@@ -188,7 +184,6 @@ public class CheckValidRepositoryTest ex
 
         Check.builder()
             .withPath(new File(temporaryFolder.getRoot().getAbsolutePath()))
-            .withJournal("journal.log")
             .withDebugInterval(Long.MAX_VALUE)
             .withCheckHead(true)
             .withCheckpoints(new HashSet<String>())
@@ -224,7 +219,6 @@ public class CheckValidRepositoryTest ex
 
         Check.builder()
             .withPath(new File(temporaryFolder.getRoot().getAbsolutePath()))
-            .withJournal("journal.log")
             .withDebugInterval(Long.MAX_VALUE)
             .withFilterPaths(filterPaths)
             .withCheckBinaries(true)
@@ -259,7 +253,6 @@ public class CheckValidRepositoryTest ex
 
         Check.builder()
             .withPath(new File(temporaryFolder.getRoot().getAbsolutePath()))
-            .withJournal("journal.log")
             .withDebugInterval(Long.MAX_VALUE)
             .withFilterPaths(filterPaths)
             .withCheckBinaries(true)
@@ -292,7 +285,6 @@ public class CheckValidRepositoryTest ex
 
         Check.builder()
             .withPath(new File(temporaryFolder.getRoot().getAbsolutePath()))
-            .withJournal("journal.log")
             .withDebugInterval(Long.MAX_VALUE)
             .withFilterPaths(filterPaths)
             .withCheckBinaries(true)
@@ -328,7 +320,6 @@ public class CheckValidRepositoryTest ex
 
         Check.builder()
             .withPath(new File(temporaryFolder.getRoot().getAbsolutePath()))
-            .withJournal("journal.log")
             .withDebugInterval(Long.MAX_VALUE)
             .withFilterPaths(filterPaths)
             .withCheckBinaries(true)