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 2016/05/19 12:16:32 UTC

svn commit: r1744558 - in /jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run: BackupCommand.java SegmentTarUtils.java SegmentUtils.java

Author: frm
Date: Thu May 19 12:16:31 2016
New Revision: 1744558

URL: http://svn.apache.org/viewvc?rev=1744558&view=rev
Log:
OAK-4326 - Add a flag to choose between segment store implementations in the "backup" command

Added:
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/SegmentTarUtils.java   (with props)
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/SegmentUtils.java   (with props)
Modified:
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/BackupCommand.java

Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/BackupCommand.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/BackupCommand.java?rev=1744558&r1=1744557&r2=1744558&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/BackupCommand.java (original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/BackupCommand.java Thu May 19 12:16:31 2016
@@ -17,39 +17,42 @@
 
 package org.apache.jackrabbit.oak.run;
 
-import static org.apache.jackrabbit.oak.plugins.segment.FileStoreHelper.newBasicReadOnlyBlobStore;
-import static org.apache.jackrabbit.oak.plugins.segment.FileStoreHelper.openReadOnlyFileStore;
-import static org.apache.jackrabbit.oak.run.Utils.asCloseable;
-
 import java.io.File;
 
-import com.google.common.io.Closer;
-import org.apache.jackrabbit.oak.plugins.backup.FileStoreBackup;
-import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStore;
-import org.apache.jackrabbit.oak.plugins.segment.file.FileStore;
-import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import joptsimple.OptionParser;
+import joptsimple.OptionSet;
+import joptsimple.OptionSpec;
 
 class BackupCommand implements Command {
 
     @Override
     public void execute(String... args) throws Exception {
-        boolean fakeBlobStore = FileStoreBackup.USE_FAKE_BLOBSTORE;
-        Closer closer = Closer.create();
-        try {
-            FileStore fs;
-            if (fakeBlobStore) {
-                fs = openReadOnlyFileStore(new File(args[0]),
-                        newBasicReadOnlyBlobStore());
-            } else {
-                fs = openReadOnlyFileStore(new File(args[0]));
-            }
-            closer.register(asCloseable(fs));
-            NodeStore store = SegmentNodeStore.builder(fs).build();
-            FileStoreBackup.backup(store, new File(args[1]));
-        } catch (Throwable e) {
-            throw closer.rethrow(e);
-        } finally {
-            closer.close();
+        OptionParser parser = new OptionParser();
+
+        OptionSpec<File> folders = parser
+                .nonOptions("source and target folders")
+                .ofType(File.class);
+
+        OptionSpec<Boolean> segmentTar = parser
+                .accepts("segment-tar", "use new segment store implementation")
+                .withOptionalArg()
+                .ofType(Boolean.class)
+                .defaultsTo(false);
+
+        OptionSet options = parser.parse(args);
+
+        if (folders.values(options).size() < 2) {
+            parser.printHelpOn(System.err);
+            System.exit(1);
+        }
+
+        File source = folders.values(options).get(0);
+        File target = folders.values(options).get(1);
+
+        if (segmentTar.value(options) == Boolean.TRUE) {
+            SegmentTarUtils.backup(source, target);
+        } else {
+            SegmentUtils.backup(source, target);
         }
     }
 

Added: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/SegmentTarUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/SegmentTarUtils.java?rev=1744558&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/SegmentTarUtils.java (added)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/SegmentTarUtils.java Thu May 19 12:16:31 2016
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.oak.run;
+
+import static org.apache.jackrabbit.oak.plugins.segment.FileStoreHelper.isValidFileStoreOrFail;
+import static org.apache.jackrabbit.oak.plugins.segment.FileStoreHelper.newBasicReadOnlyBlobStore;
+
+import java.io.Closeable;
+import java.io.File;
+import java.io.IOException;
+
+import com.google.common.io.Closer;
+import org.apache.jackrabbit.oak.backup.FileStoreBackup;
+import org.apache.jackrabbit.oak.segment.SegmentNodeStore;
+import org.apache.jackrabbit.oak.segment.file.FileStore;
+import org.apache.jackrabbit.oak.spi.blob.BlobStore;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+
+class SegmentTarUtils {
+
+    private static final boolean TAR_STORAGE_MEMORY_MAPPED = Boolean.getBoolean("tar.memoryMapped");
+
+    private static final int TAR_SEGMENT_CACHE_SIZE = Integer.getInteger("cache", 256);
+
+    private SegmentTarUtils() {
+        // Prevent instantiation
+    }
+
+    static void backup(File source, File target) throws IOException {
+        Closer closer = Closer.create();
+        try {
+            FileStore fs;
+            if (FileStoreBackup.USE_FAKE_BLOBSTORE) {
+                fs = openReadOnlyFileStore(source, newBasicReadOnlyBlobStore());
+            } else {
+                fs = openReadOnlyFileStore(source);
+            }
+            closer.register(asCloseable(fs));
+            NodeStore store = SegmentNodeStore.builder(fs).build();
+            FileStoreBackup.backup(store, target);
+        } catch (Throwable e) {
+            throw closer.rethrow(e);
+        } finally {
+            closer.close();
+        }
+    }
+
+    private static FileStore openReadOnlyFileStore(File path, BlobStore blobStore) throws IOException {
+        return FileStore.builder(isValidFileStoreOrFail(path))
+                .withCacheSize(TAR_SEGMENT_CACHE_SIZE)
+                .withMemoryMapping(TAR_STORAGE_MEMORY_MAPPED)
+                .withBlobStore(blobStore)
+                .buildReadOnly();
+    }
+
+    private static FileStore openReadOnlyFileStore(File path) throws IOException {
+        return FileStore.builder(isValidFileStoreOrFail(path))
+                .withCacheSize(TAR_SEGMENT_CACHE_SIZE)
+                .withMemoryMapping(TAR_STORAGE_MEMORY_MAPPED)
+                .buildReadOnly();
+    }
+
+    private static Closeable asCloseable(final FileStore fs) {
+        return new Closeable() {
+
+            @Override
+            public void close() throws IOException {
+                fs.close();
+            }
+
+        };
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/SegmentTarUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/SegmentUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/SegmentUtils.java?rev=1744558&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/SegmentUtils.java (added)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/SegmentUtils.java Thu May 19 12:16:31 2016
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.oak.run;
+
+import static org.apache.jackrabbit.oak.plugins.segment.FileStoreHelper.newBasicReadOnlyBlobStore;
+import static org.apache.jackrabbit.oak.plugins.segment.FileStoreHelper.openReadOnlyFileStore;
+import static org.apache.jackrabbit.oak.run.Utils.asCloseable;
+
+import java.io.File;
+import java.io.IOException;
+
+import com.google.common.io.Closer;
+import org.apache.jackrabbit.oak.plugins.backup.FileStoreBackup;
+import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStore;
+import org.apache.jackrabbit.oak.plugins.segment.file.FileStore;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+
+class SegmentUtils {
+
+    private SegmentUtils() {
+        // Prevent instantiation
+    }
+
+    static void backup(File source, File target) throws IOException {
+        Closer closer = Closer.create();
+        try {
+            FileStore fs;
+            if (FileStoreBackup.USE_FAKE_BLOBSTORE) {
+                fs = openReadOnlyFileStore(source, newBasicReadOnlyBlobStore());
+            } else {
+                fs = openReadOnlyFileStore(source);
+            }
+            closer.register(asCloseable(fs));
+            NodeStore store = SegmentNodeStore.builder(fs).build();
+            FileStoreBackup.backup(store, target);
+        } catch (Throwable e) {
+            throw closer.rethrow(e);
+        } finally {
+            closer.close();
+        }
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/SegmentUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native



Re: svn commit: r1744558 - in /jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run: BackupCommand.java SegmentTarUtils.java SegmentUtils.java

Posted by Michael Dürig <md...@apache.org>.
Hi,

On 19.5.16 2:16 , frm@apache.org wrote:
> Author: frm
> Date: Thu May 19 12:16:31 2016
> New Revision: 1744558
>

> +                .accepts("segment-tar", "use new segment store implementation")


I think this wording is (or will be) confusing. I would prefer something 
along the lines of "use segment-tar repository (defaults to segmentMK)".

Michael