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 2015/10/06 17:30:29 UTC
svn commit: r1707075 - in /jackrabbit/oak/trunk/oak-core/src:
main/java/org/apache/jackrabbit/oak/plugins/document/
test/java/org/apache/jackrabbit/oak/plugins/document/
test/java/org/apache/jackrabbit/oak/plugins/document/mongo/
Author: mreutegg
Date: Tue Oct 6 15:30:29 2015
New Revision: 1707075
URL: http://svn.apache.org/viewvc?rev=1707075&view=rev
Log:
OAK-3405: Avoid instanceof check in LastRevRecoveryAgent
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoMissingLastRevSeekerTest.java (with props)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgent.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoUtils.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java?rev=1707075&r1=1707074&r2=1707075&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java Tue Oct 6 15:30:29 2015
@@ -48,6 +48,7 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.plugins.document.mongo.MongoBlobReferenceIterator;
import org.apache.jackrabbit.oak.plugins.document.mongo.MongoBlobStore;
import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.mongo.MongoMissingLastRevSeeker;
import org.apache.jackrabbit.oak.plugins.document.mongo.MongoVersionGCSupport;
import org.apache.jackrabbit.oak.plugins.document.persistentCache.CacheType;
import org.apache.jackrabbit.oak.plugins.document.persistentCache.PersistentCache;
@@ -851,6 +852,15 @@ public class DocumentMK {
};
}
+ public MissingLastRevSeeker createMissingLastRevSeeker() {
+ final DocumentStore store = getDocumentStore();
+ if (store instanceof MongoDocumentStore) {
+ return new MongoMissingLastRevSeeker((MongoDocumentStore) store);
+ } else {
+ return new MissingLastRevSeeker(store);
+ }
+ }
+
/**
* Open the DocumentMK instance using the configured options.
*
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java?rev=1707075&r1=1707074&r2=1707075&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java Tue Oct 6 15:30:29 2015
@@ -450,7 +450,8 @@ public final class DocumentNodeStore
this, builder.createVersionGCSupport());
this.journalGarbageCollector = new JournalGarbageCollector(this);
this.referencedBlobs = builder.createReferencedBlobs(this);
- this.lastRevRecoveryAgent = new LastRevRecoveryAgent(this);
+ this.lastRevRecoveryAgent = new LastRevRecoveryAgent(this,
+ builder.createMissingLastRevSeeker());
this.disableBranches = builder.isDisableBranches();
this.missing = new DocumentNodeState(this, "MISSING", new Revision(0, 0, 0)) {
@Override
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgent.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgent.java?rev=1707075&r1=1707074&r2=1707075&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgent.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgent.java Tue Oct 6 15:30:29 2015
@@ -38,8 +38,6 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.apache.jackrabbit.oak.commons.PathUtils;
-import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore;
-import org.apache.jackrabbit.oak.plugins.document.mongo.MongoMissingLastRevSeeker;
import org.apache.jackrabbit.oak.plugins.document.util.MapFactory;
import org.apache.jackrabbit.oak.plugins.document.util.Utils;
import org.slf4j.Logger;
@@ -56,15 +54,14 @@ public class LastRevRecoveryAgent {
private final MissingLastRevSeeker missingLastRevUtil;
- public LastRevRecoveryAgent(DocumentNodeStore nodeStore) {
+ public LastRevRecoveryAgent(DocumentNodeStore nodeStore,
+ MissingLastRevSeeker seeker) {
this.nodeStore = nodeStore;
+ this.missingLastRevUtil = seeker;
+ }
- if (nodeStore.getDocumentStore() instanceof MongoDocumentStore) {
- this.missingLastRevUtil =
- new MongoMissingLastRevSeeker((MongoDocumentStore) nodeStore.getDocumentStore());
- } else {
- this.missingLastRevUtil = new MissingLastRevSeeker(nodeStore.getDocumentStore());
- }
+ public LastRevRecoveryAgent(DocumentNodeStore nodeStore) {
+ this(nodeStore, new MissingLastRevSeeker(nodeStore.getDocumentStore()));
}
/**
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoUtils.java?rev=1707075&r1=1707074&r2=1707075&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoUtils.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoUtils.java Tue Oct 6 15:30:29 2015
@@ -70,6 +70,25 @@ public class MongoUtils {
}
/**
+ * Drop all user defined collections in the given database. System
+ * collections are not dropped. This method returns silently if MongoDB is
+ * not available.
+ *
+ * @param dbName the database name.
+ */
+ public static void dropCollections(String dbName) {
+ MongoConnection c = getConnection(dbName);
+ if (c == null) {
+ return;
+ }
+ try {
+ dropCollections(c.getDB());
+ } finally {
+ c.close();
+ }
+ }
+
+ /**
* Drop all user defined collections. System collections are not dropped.
*
* @param db the connection
@@ -82,4 +101,22 @@ public class MongoUtils {
}
}
+ /**
+ * Drops the database with the given name. This method returns silently if
+ * MongoDB is not available.
+ *
+ * @param dbName the name of the database to drop.
+ */
+ public static void dropDatabase(String dbName) {
+ MongoConnection c = getConnection(dbName);
+ if (c == null) {
+ return;
+ }
+ try {
+ c.getDB().dropDatabase();
+ } finally {
+ c.close();
+ }
+ }
+
}
Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoMissingLastRevSeekerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoMissingLastRevSeekerTest.java?rev=1707075&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoMissingLastRevSeekerTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoMissingLastRevSeekerTest.java Tue Oct 6 15:30:29 2015
@@ -0,0 +1,59 @@
+/*
+ * 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.plugins.document.mongo;
+
+import org.apache.jackrabbit.oak.plugins.document.DocumentMK;
+import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
+import org.apache.jackrabbit.oak.plugins.document.MongoUtils;
+import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeNotNull;
+
+public class MongoMissingLastRevSeekerTest {
+
+ private MongoConnection c;
+ private String dbName;
+ private DocumentMK.Builder builder;
+ private DocumentNodeStore ns;
+
+ @Before
+ public void before() throws Exception {
+ c = MongoUtils.getConnection();
+ assumeNotNull(c);
+ dbName = c.getDB().getName();
+ builder = new DocumentMK.Builder().setMongoDB(c.getDB());
+ ns = builder.getNodeStore();
+ }
+
+ @After
+ public void after() throws Exception {
+ ns.dispose();
+ c.close();
+ MongoUtils.dropDatabase(dbName);
+ }
+
+ @Test
+ public void missingLastRevSeeker() throws Exception {
+ assertTrue(builder.createMissingLastRevSeeker() instanceof MongoMissingLastRevSeeker);
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoMissingLastRevSeekerTest.java
------------------------------------------------------------------------------
svn:eol-style = native