Author: mreutegg
Date: Mon Apr 3 11:53:29 2017
New Revision: 1789975
URL: http://svn.apache.org/viewvc?rev=1789975&view=rev
Log:
OAK-6016: DocumentNodeStore.compare() fails with IllegalStateException in
read-only mode
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/JournalDiffLoader.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ReadOnlyDocumentNodeStoreTest.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/JournalDiffLoader.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/JournalDiffLoader.java?rev=1789975&r1=1789974&r2=1789975&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/JournalDiffLoader.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/JournalDiffLoader.java
Mon Apr 3 11:53:29 2017
@@ -72,20 +72,9 @@ class JournalDiffLoader implements DiffC
RevisionVector beforeRev = base.getRootRevision();
stats = new Stats(path, beforeRev, afterRev);
- JournalEntry localPending = ns.getCurrentJournalEntry();
- DocumentStore store = ns.getDocumentStore();
- NodeDocument root = Utils.getRootDocument(store);
- Map<Integer, Revision> lastRevs = root.getLastRev();
- int clusterId = ns.getClusterId();
- Revision localLastRev = lastRevs.get(clusterId);
- if (localLastRev == null) {
- throw new IllegalStateException("Root document does not have a " +
- "lastRev entry for local clusterId " + clusterId);
- }
-
StringSort changes = JournalEntry.newSorter();
try {
- readTrunkChanges(path, beforeRev, afterRev, localPending,
localLastRev, changes);
+ readTrunkChanges(path, beforeRev, afterRev, changes);
readBranchChanges(path, beforeRev, changes);
readBranchChanges(path, afterRev, changes);
@@ -135,9 +124,24 @@ class JournalDiffLoader implements DiffC
private void readTrunkChanges(String path,
RevisionVector beforeRev,
RevisionVector afterRev,
- JournalEntry localPending,
- Revision localLastRev,
StringSort changes) throws IOException {
+ JournalEntry localPending = ns.getCurrentJournalEntry();
+ DocumentStore store = ns.getDocumentStore();
+ NodeDocument root = Utils.getRootDocument(store);
+ int clusterId = ns.getClusterId();
+ Map<Integer, Revision> lastRevs = root.getLastRev();
+ Revision localLastRev;
+ if (clusterId == 0) {
+ // read-only node store
+ localLastRev = afterRev.getRevision(clusterId);
+ } else {
+ localLastRev = lastRevs.get(clusterId);
+ }
+ if (localLastRev == null) {
+ throw new IllegalStateException("Root document does not have a " +
+ "lastRev entry for local clusterId " + clusterId);
+ }
+
if (ns.isDisableBranches()) {
beforeRev = beforeRev.asTrunkRevision();
afterRev = afterRev.asTrunkRevision();
@@ -149,9 +153,17 @@ class JournalDiffLoader implements DiffC
return;
}
- int clusterId = ns.getClusterId();
RevisionVector max = beforeRev.pmax(afterRev);
RevisionVector min = beforeRev.pmin(afterRev);
+
+ // do we need to include changes from pending local changes?
+ if (!max.isRevisionNewer(localLastRev)
+ && !localLastRev.equals(max.getRevision(clusterId))) {
+ // journal does not contain all local changes
+ localPending.addTo(changes, path);
+ stats.numJournalEntries++;
+ }
+
for (Revision to : max) {
Revision from = min.getRevision(to.getClusterId());
if (from == null) {
@@ -167,13 +179,6 @@ class JournalDiffLoader implements DiffC
invalidateOnly.close();
}
}
- // do we need to include changes from pending local changes?
- if (!max.isRevisionNewer(localLastRev)
- && !localLastRev.equals(max.getRevision(clusterId))) {
- // journal does not contain all local changes
- localPending.addTo(changes, path);
- stats.numJournalEntries++;
- }
}
@Nonnull
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ReadOnlyDocumentNodeStoreTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ReadOnlyDocumentNodeStoreTest.java?rev=1789975&r1=1789974&r2=1789975&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ReadOnlyDocumentNodeStoreTest.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ReadOnlyDocumentNodeStoreTest.java
Mon Apr 3 11:53:29 2017
@@ -18,12 +18,11 @@ package org.apache.jackrabbit.oak.plugin
import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
-import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import static org.apache.jackrabbit.oak.plugins.document.TestUtils.merge;
-import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
@@ -33,7 +32,6 @@ public class ReadOnlyDocumentNodeStoreTe
@Rule
public DocumentMKBuilderProvider builderProvider = new
DocumentMKBuilderProvider();
- @Ignore("OAK-6016")
@Test
public void readOnlyCompare() throws Exception {
DocumentStore store = new MemoryDocumentStore();
@@ -63,7 +61,7 @@ public class ReadOnlyDocumentNodeStoreTe
s2.compareAgainstBaseState(s1, diff);
assertThat(diff.deleted, is(empty()));
assertThat(diff.modified, is(empty()));
- assertThat(diff.added, contains("foo", "bar"));
+ assertThat(diff.added, containsInAnyOrder("/foo", "/bar"));
}
}