Author: reschke
Date: Tue May 28 17:21:04 2019
New Revision: 1860291
URL: http://svn.apache.org/viewvc?rev=1860291&view=rev
Log:
OAK-8207: Read-only DocumentNodeStore tries to create root document (ported to
1.8)
Modified:
jackrabbit/oak/branches/1.8/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
jackrabbit/oak/branches/1.8/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
Modified:
jackrabbit/oak/branches/1.8/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.8/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java?rev=1860291&r1=1860290&r2=1860291&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.8/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
(original)
+++
jackrabbit/oak/branches/1.8/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
Tue May 28 17:21:04 2019
@@ -607,11 +607,15 @@ public final class DocumentNodeStore
builder.getWeigher(), builder.getChildrenCacheSize());
diffCache = builder.getDiffCache();
- checkpoints = new Checkpoints(this);
// check if root node exists
NodeDocument rootDoc = store.find(NODES, Utils.getIdFromPath("/"));
if (rootDoc == null) {
+ if (readOnlyMode) {
+ throw new DocumentStoreException("Unable to initialize a " +
+ "read-only DocumentNodeStore. The DocumentStore nodes
" +
+ "collection does not have a root document.");
+ }
// root node is missing: repository is not initialized
Revision commitRev = newRevision();
Commit commit = new Commit(this, commitRev, null);
@@ -653,6 +657,8 @@ public final class DocumentNodeStore
}
}
+ checkpoints = new Checkpoints(this);
+
// Renew the lease because it may have been stale
renewClusterIdLease();
Modified:
jackrabbit/oak/branches/1.8/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.8/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java?rev=1860291&r1=1860290&r2=1860291&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.8/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
(original)
+++
jackrabbit/oak/branches/1.8/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
Tue May 28 17:21:04 2019
@@ -3641,6 +3641,19 @@ public class DocumentNodeStoreTest {
);
}
+ @Test
+ public void readOnlyOnEmptyDocumentStore() {
+ DocumentStore store = new MemoryDocumentStore();
+ try {
+ builderProvider.newBuilder().setDocumentStore(store)
+ .setReadOnlyMode().build();
+ fail("must fail with DocumentStoreException");
+ } catch (Exception e) {
+ // must not hit last line of defence (ReadOnlyDocumentStoreWrapper)
+ assertFalse(Throwables.getRootCause(e) instanceof
UnsupportedOperationException);
+ }
+ }
+
private void getChildNodeCountTest(int numChildren,
Iterable<Long> maxValues,
Iterable<Long> expectedValues)