Author: mreutegg
Date: Tue May 9 13:36:29 2017
New Revision: 1794577
URL: http://svn.apache.org/viewvc?rev=1794577&view=rev
Log:
OAK-3711: Clean up _revision entries on commit root documents
Set an initial sweep revision when a new clusterId is used
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
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=1794577&r1=1794576&r2=1794577&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 May 9 13:36:29 2017
@@ -634,7 +634,16 @@ public final class DocumentNodeStore
initializeRootState(rootDoc);
// check if _lastRev for our clusterId exists
if (!rootDoc.getLastRev().containsKey(clusterId)) {
- unsavedLastRevisions.put("/",
getRoot().getRootRevision().getRevision(clusterId));
+ RevisionVector rootRev = getRoot().getRootRevision();
+ Revision initialRev = rootRev.getRevision(clusterId);
+ if (initialRev == null) {
+ throw new IllegalStateException(
+ "missing revision for clusterId " + clusterId +
+ ": " + rootRev);
+ }
+ unsavedLastRevisions.put("/", initialRev);
+ // set initial sweep revision
+ sweepRevisions = sweepRevisions.pmax(new
RevisionVector(initialRev));
if (!readOnlyMode) {
backgroundWrite();
}
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java?rev=1794577&r1=1794576&r2=1794577&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
Tue May 9 13:36:29 2017
@@ -3023,6 +3023,41 @@ public class DocumentNodeStoreTest {
assertTrue(head1.compareRevisionTime(head3) < 0);
}
+ @Test
+ public void noSweepOnNewClusterNode() throws Exception {
+ Clock clock = new Clock.Virtual();
+ clock.waitUntil(System.currentTimeMillis());
+ Revision.setClock(clock);
+ DocumentStore store = new MemoryDocumentStore();
+ builderProvider.newBuilder().clock(clock)
+ .setDocumentStore(store).setAsyncDelay(0).setClusterId(1)
+ .getNodeStore();
+
+ // now startup second node store with a custom lastRev seeker
+ final AtomicInteger candidateCalls = new AtomicInteger();
+ DocumentMK.Builder nsBuilder = new DocumentMK.Builder() {
+ @Override
+ public MissingLastRevSeeker createMissingLastRevSeeker() {
+ return new MissingLastRevSeeker(getDocumentStore(),
getClock()) {
+ @Nonnull
+ @Override
+ public Iterable<NodeDocument> getCandidates(long
startTime) {
+ candidateCalls.incrementAndGet();
+ return super.getCandidates(startTime);
+ }
+ };
+ }
+ };
+ DocumentNodeStore ns2 = nsBuilder.clock(clock)
+ .setDocumentStore(store).setAsyncDelay(0).setClusterId(2)
+ .getNodeStore();
+ try {
+ assertEquals(0, candidateCalls.get());
+ } finally {
+ ns2.dispose();
+ }
+ }
+
private static class WriteCountingStore extends MemoryDocumentStore {
private final ThreadLocal<Boolean> createMulti = new ThreadLocal<>();
int count;