Author: mreutegg
Date: Mon Apr 8 12:21:22 2019
New Revision: 1857104
URL: http://svn.apache.org/viewvc?rev=1857104&view=rev
Log:
OAK-8200: MongoDocumentStore in ReadOnly mode should never modify persistence
Modified:
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreTest.java
Modified:
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java?rev=1857104&r1=1857103&r2=1857104&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
Mon Apr 8 12:21:22 2019
@@ -274,6 +274,24 @@ public class MongoDocumentStore implemen
useClientSession = !builder.isClientSessionDisabled()
&&
Boolean.parseBoolean(System.getProperty("oak.mongo.clientSession", "true"));
+ if (!readOnly) {
+ ensureIndexes(mongoStatus);
+ }
+
+ this.nodeLocks = new StripedNodeDocumentLocks();
+ this.nodesCache = builder.buildNodeDocumentCache(this, nodeLocks);
+
+ LOG.info("Connected to MongoDB {} with maxReplicationLagMillis {}, " +
+ "maxDeltaForModTimeIdxSecs {}, disableIndexHint {}, " +
+ "clientSessionSupported {}, clientSessionInUse {}, {}, " +
+ "serverStatus {}",
+ mongoStatus.getVersion(), maxReplicationLagMillis,
+ maxDeltaForModTimeIdxSecs, disableIndexHint,
+ status.isClientSessionSupported(), useClientSession,
+ db.getWriteConcern(), mongoStatus.getServerDetails());
+ }
+
+ private void ensureIndexes(@NotNull MongoStatus mongoStatus) {
// reading documents in the nodes collection and checking
// existing indexes is performed against the MongoDB primary
// this ensures the information is up-to-date and accurate
@@ -288,11 +306,9 @@ public class MongoDocumentStore implemen
} else if
(!hasIndex(nodes.withReadPreference(ReadPreference.primary()),
NodeDocument.MODIFIED_IN_SECS, Document.ID)) {
hasModifiedIdCompoundIndex = false;
- if (!builder.getReadOnlyMode()) {
- LOG.warn("Detected an upgrade from Oak version <= 1.2. For
optimal " +
- "performance it is recommended to create a compound
index " +
- "for the 'nodes' collection on {_modified:1, _id:1}.");
- }
+ LOG.warn("Detected an upgrade from Oak version <= 1.2. For optimal
" +
+ "performance it is recommended to create a compound index
" +
+ "for the 'nodes' collection on {_modified:1, _id:1}.");
}
// index on the _bin flag to faster access nodes with binaries for GC
@@ -309,14 +325,12 @@ public class MongoDocumentStore implemen
}
} else if
(!hasIndex(nodes.withReadPreference(ReadPreference.primary()),
DELETED_ONCE, MODIFIED_IN_SECS)) {
- if (!builder.getReadOnlyMode()) {
- LOG.warn("Detected an upgrade from Oak version <= 1.6. For
optimal " +
- "Revision GC performance it is recommended to create a
" +
- "partial index for the 'nodes' collection on " +
- "{_deletedOnce:1, _modified:1} with a
partialFilterExpression " +
- "{_deletedOnce:true}. Partial indexes require MongoDB
3.2 " +
- "or higher.");
- }
+ LOG.warn("Detected an upgrade from Oak version <= 1.6. For optimal
" +
+ "Revision GC performance it is recommended to create a " +
+ "partial index for the 'nodes' collection on " +
+ "{_deletedOnce:1, _modified:1} with a
partialFilterExpression " +
+ "{_deletedOnce:true}. Partial indexes require MongoDB 3.2
" +
+ "or higher.");
}
// compound index on _sdType and _sdMaxRevTime
@@ -327,28 +341,14 @@ public class MongoDocumentStore implemen
new boolean[]{true, true}, false, true);
} else if
(!hasIndex(nodes.withReadPreference(ReadPreference.primary()),
SD_TYPE, SD_MAX_REV_TIME_IN_SECS)) {
- if (!builder.getReadOnlyMode()) {
- LOG.warn("Detected an upgrade from Oak version <= 1.6. For
optimal " +
- "Revision GC performance it is recommended to create a
" +
- "sparse compound index for the 'nodes' collection on "
+
- "{_sdType:1, _sdMaxRevTime:1}.");
- }
+ LOG.warn("Detected an upgrade from Oak version <= 1.6. For optimal
" +
+ "Revision GC performance it is recommended to create a " +
+ "sparse compound index for the 'nodes' collection on " +
+ "{_sdType:1, _sdMaxRevTime:1}.");
}
// index on _modified for journal entries
createIndex(journal, JournalEntry.MODIFIED, true, false, false);
-
- this.nodeLocks = new StripedNodeDocumentLocks();
- this.nodesCache = builder.buildNodeDocumentCache(this, nodeLocks);
-
- LOG.info("Connected to MongoDB {} with maxReplicationLagMillis {}, " +
- "maxDeltaForModTimeIdxSecs {}, disableIndexHint {}, " +
- "clientSessionSupported {}, clientSessionInUse {}, {}, " +
- "serverStatus {}",
- mongoStatus.getVersion(), maxReplicationLagMillis,
- maxDeltaForModTimeIdxSecs, disableIndexHint,
- status.isClientSessionSupported(), useClientSession,
- db.getWriteConcern(), mongoStatus.getServerDetails());
}
public boolean isReadOnly() {
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreTest.java?rev=1857104&r1=1857103&r2=1857104&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreTest.java
Mon Apr 8 12:21:22 2019
@@ -18,6 +18,8 @@ package org.apache.jackrabbit.oak.plugin
import java.util.Map;
+import com.mongodb.client.MongoCollection;
+
import org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest;
import org.apache.jackrabbit.oak.plugins.document.Collection;
import org.apache.jackrabbit.oak.plugins.document.Document;
@@ -28,6 +30,7 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
import org.junit.Test;
+import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES;
import static
org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.hasIndex;
import static org.hamcrest.Matchers.hasItem;
import static org.junit.Assert.assertFalse;
@@ -90,6 +93,28 @@ public class MongoDocumentStoreTest exte
assertThat(info.keySet(), hasItem("settings.count"));
}
+ @Test
+ public void readOnly() throws Exception {
+ // setup must have created nodes collection with index on _bin
+ MongoCollection<?> mc = mongoConnection.getDatabase()
+ .getCollection(NODES.toString());
+ assertTrue(hasIndex(mc, NodeDocument.HAS_BINARY_FLAG));
+ mk.dispose();
+ // remove the indexes
+ mongoConnection = connectionFactory.getConnection();
+ assertNotNull(mongoConnection);
+ mc = mongoConnection.getDatabase().getCollection(NODES.toString());
+ mc.dropIndexes();
+ // must be gone now
+ assertFalse(hasIndex(mc, NodeDocument.HAS_BINARY_FLAG));
+
+ // start a new read-only DocumentNodeStore
+ mk = newBuilder(mongoConnection.getMongoClient(),
+ mongoConnection.getDBName()).setReadOnlyMode().open();
+ // must still not exist when started in read-only mode
+ assertFalse(hasIndex(mc, NodeDocument.HAS_BINARY_FLAG));
+ }
+
static final class TestStore extends MongoDocumentStore {
TestStore(MongoConnection c, DocumentMK.Builder builder) {
super(c.getMongoClient(), c.getDatabase(), builder);