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 mr...@apache.org on 2017/03/21 10:42:12 UTC
svn commit: r1787931 - in /jackrabbit/oak/trunk:
oak-doc/src/site/markdown/nodestore/ oak-run/
oak-run/src/main/java/org/apache/jackrabbit/oak/run/
oak-run/src/test/java/org/apache/jackrabbit/oak/run/
Author: mreutegg
Date: Tue Mar 21 10:42:12 2017
New Revision: 1787931
URL: http://svn.apache.org/viewvc?rev=1787931&view=rev
Log:
OAK-4529: DocumentNodeStore does not have a repository software version range check
New 'unlockUpgrade' command and documentation
Added:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/UnlockUpgradeCommand.java (with props)
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/UnlockUpgradeCommandTest.java (with props)
Modified:
jackrabbit/oak/trunk/oak-doc/src/site/markdown/nodestore/documentmk.md
jackrabbit/oak/trunk/oak-run/README.md
jackrabbit/oak/trunk/oak-run/pom.xml
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Mode.java
Modified: jackrabbit/oak/trunk/oak-doc/src/site/markdown/nodestore/documentmk.md
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-doc/src/site/markdown/nodestore/documentmk.md?rev=1787931&r1=1787930&r2=1787931&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-doc/src/site/markdown/nodestore/documentmk.md (original)
+++ jackrabbit/oak/trunk/oak-doc/src/site/markdown/nodestore/documentmk.md Tue Mar 21 10:42:12 2017
@@ -572,6 +572,26 @@ Further make use of the persistent cache
instances off heap with slight decrease in performance compared to keeping them
on heap.
+### Unlock upgrade <a name="unlockUpgrade"/>
+
+On startup the DocumentNodeStore checks if its version is compatible with the
+format version currently in use. A read-only DocumentNodeStore can read the
+current version as well as older versions. A read-write DocumentNodeStore on the
+other hand can only write to the DocumentStore when the format version matches
+its own version. The DocumentNodeStore maintains this format version in the
+`settings` collection accessible to all cluster nodes.
+
+Upgrading to a newer Oak version may therefore first require an update of the
+format version before a newer version of a DocumentNodeStore can be started on
+existing data. The oak-run tools contains an `unlockUpgrade` mode to perform
+this operation. Use the oak-run tool with the version matching the target
+upgrade version to unlock an upgrade with the following command. The below
+example unlocks an upgrade to 1.8 with a DocumentNodeStore on MongoDB:
+
+ > java -jar oak-run-1.8.0.jar unlockUpgrade mongodb://example.com:27017/oak
+
+Please note that unlocking an upgrade is only possible when all cluster nodes
+are inactive, otherwise the command will refuse to change the format version.
[1]: http://docs.mongodb.org/manual/core/read-preference/
[2]: http://docs.mongodb.org/manual/core/write-concern/
Modified: jackrabbit/oak/trunk/oak-run/README.md
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/README.md?rev=1787931&r1=1787930&r2=1787931&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/README.md (original)
+++ jackrabbit/oak/trunk/oak-run/README.md Tue Mar 21 10:42:12 2017
@@ -27,6 +27,7 @@ The following runmodes are currently ava
* tarmkdiff : Show changes between revisions on TarMk
* tarmkrecovery : Lists candidates for head journal entries
* tika : Performs text extraction
+ * unlockUpgrade : Unlock a DocumentMK upgrade to a newer version
* upgrade : Migrate existing Jackrabbit 2.x repository to Oak.
@@ -907,6 +908,11 @@ Upgrades the JR2 DataStore cache by movi
--moveCache <true|false> \
--deleteMapFile <true|false>
+Unlock DocumentMK upgrade
+-------------------------
+
+See the [official documentation](http://jackrabbit.apache.org/oak/docs/nodestore/documentmk.html#unlockUpgrade).
+
License
-------
Modified: jackrabbit/oak/trunk/oak-run/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/pom.xml?rev=1787931&r1=1787930&r2=1787931&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-run/pom.xml Tue Mar 21 10:42:12 2017
@@ -431,6 +431,13 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>oak-core</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</profile>
</profiles>
Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Mode.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Mode.java?rev=1787931&r1=1787930&r2=1787931&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Mode.java (original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Mode.java Tue Mar 21 10:42:12 2017
@@ -30,6 +30,7 @@ enum Mode {
COMPACT("compact", new CompactCommand()),
SERVER("server", new ServerCommand()),
UPGRADE("upgrade", new UpgradeCommand()),
+ UNLOCKUPGRADE("unlockUpgrade", new UnlockUpgradeCommand()),
SCALABILITY("scalability", new ScalabilityCommand()),
EXPLORE("explore", new ExploreCommand()),
CHECKPOINTS("checkpoints", new CheckpointsCommand()),
Added: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/UnlockUpgradeCommand.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/UnlockUpgradeCommand.java?rev=1787931&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/UnlockUpgradeCommand.java (added)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/UnlockUpgradeCommand.java Tue Mar 21 10:42:12 2017
@@ -0,0 +1,102 @@
+/*
+ * 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 java.util.List;
+
+import javax.sql.DataSource;
+
+import com.mongodb.MongoClientURI;
+
+import org.apache.jackrabbit.oak.plugins.document.DocumentMK;
+import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException;
+import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDataSourceFactory;
+import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
+
+import joptsimple.OptionParser;
+import joptsimple.OptionSet;
+import joptsimple.OptionSpec;
+
+import static com.mongodb.MongoURI.MONGODB_PREFIX;
+import static java.util.Arrays.asList;
+import static org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore.VERSION;
+
+/**
+ * Unlocks the DocumentStore for an upgrade to the current DocumentNodeStore
+ * version.
+ */
+class UnlockUpgradeCommand implements Command {
+
+ @Override
+ public void execute(String... args) throws Exception {
+ OptionParser parser = new OptionParser();
+ // RDB specific options
+ OptionSpec<String> rdbjdbcuser = parser.accepts("rdbjdbcuser", "RDB JDBC user").withOptionalArg().defaultsTo("");
+ OptionSpec<String> rdbjdbcpasswd = parser.accepts("rdbjdbcpasswd", "RDB JDBC password").withOptionalArg().defaultsTo("");
+
+ OptionSpec<String> nonOption = parser.nonOptions("unlockUpgrade {<jdbc-uri> | <mongodb-uri>}");
+ OptionSpec help = parser.acceptsAll(asList("h", "?", "help"), "show help").forHelp();
+
+ OptionSet options = parser.parse(args);
+ List<String> nonOptions = nonOption.values(options);
+
+ if (options.has(help)) {
+ parser.printHelpOn(System.out);
+ return;
+ }
+
+ if (nonOptions.isEmpty()) {
+ parser.printHelpOn(System.err);
+ return;
+ }
+
+ DocumentStore store = null;
+ try {
+ String uri = nonOptions.get(0);
+ if (uri.startsWith(MONGODB_PREFIX)) {
+ MongoClientURI clientURI = new MongoClientURI(uri);
+ if (clientURI.getDatabase() == null) {
+ System.err.println("Database missing in MongoDB URI: " + clientURI.getURI());
+ } else {
+ MongoConnection mongo = new MongoConnection(clientURI.getURI());
+ store = new MongoDocumentStore(mongo.getDB(), new DocumentMK.Builder());
+ }
+ } else if (uri.startsWith("jdbc")) {
+ DataSource ds = RDBDataSourceFactory.forJdbcUrl(uri,
+ rdbjdbcuser.value(options), rdbjdbcpasswd.value(options));
+ store = new RDBDocumentStore(ds, new DocumentMK.Builder());
+ } else {
+ System.err.println("Unrecognized URI: " + uri);
+ }
+
+ if (store != null && VERSION.writeTo(store)) {
+ System.out.println("Format version set to " + VERSION);
+ }
+ } catch (DocumentStoreException e) {
+ System.err.println(e.getMessage());
+ } finally {
+ if (store != null) {
+ store.dispose();
+ }
+ }
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/UnlockUpgradeCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/UnlockUpgradeCommandTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/UnlockUpgradeCommandTest.java?rev=1787931&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/UnlockUpgradeCommandTest.java (added)
+++ jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/UnlockUpgradeCommandTest.java Tue Mar 21 10:42:12 2017
@@ -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 org.apache.jackrabbit.oak.plugins.document.Collection;
+import org.apache.jackrabbit.oak.plugins.document.DocumentMK;
+import org.apache.jackrabbit.oak.plugins.document.DocumentMKBuilderProvider;
+import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
+import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.FormatVersion;
+import org.apache.jackrabbit.oak.plugins.document.MongoConnectionFactory;
+import org.apache.jackrabbit.oak.plugins.document.MongoUtils;
+import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.apache.jackrabbit.oak.plugins.document.FormatVersion.versionOf;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
+
+public class UnlockUpgradeCommandTest {
+
+ @Rule
+ public MongoConnectionFactory connectionFactory = new MongoConnectionFactory();
+
+ @Rule
+ public DocumentMKBuilderProvider builderProvider = new DocumentMKBuilderProvider();
+
+ private DocumentNodeStore ns;
+
+ @BeforeClass
+ public static void assumeMongoDB() {
+ assumeTrue(MongoUtils.isAvailable());
+ }
+
+ @Before
+ public void before() {
+ ns = createDocumentNodeStore();
+ }
+
+ @Test
+ public void unlockUpgrade() throws Exception {
+ ns.dispose();
+ // revert format version back to something old
+ resetFormatVersion(FormatVersion.valueOf("0.0.1"));
+ // execute command
+ UnlockUpgradeCommand cmd = new UnlockUpgradeCommand();
+ cmd.execute(MongoUtils.URL);
+ // verify
+
+ FormatVersion v = versionOf(createDocumentNodeStore().getDocumentStore());
+ assertEquals(DocumentNodeStore.VERSION, v);
+ }
+
+ private DocumentNodeStore createDocumentNodeStore() {
+ MongoConnection c = connectionFactory.getConnection();
+ MongoUtils.dropCollections(c.getDB().getName());
+ return builderProvider.newBuilder().setMongoDB(c.getDB()).getNodeStore();
+ }
+
+ private void resetFormatVersion(FormatVersion v) {
+ MongoConnection c = connectionFactory.getConnection();
+ DocumentStore s = new MongoDocumentStore(c.getDB(), new DocumentMK.Builder());
+ s.remove(Collection.SETTINGS, "version");
+ assertTrue(v.writeTo(s));
+ s.dispose();
+ }
+
+}
Propchange: jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/UnlockUpgradeCommandTest.java
------------------------------------------------------------------------------
svn:eol-style = native