Author: chetanm
Date: Tue Mar 25 12:02:04 2014
New Revision: 1581297
URL: http://svn.apache.org/r1581297
Log:
OAK-1586 - Implement checkpoint support in DocumentNodeStore
Adding a separate collection named 'settings' which stores the checkpoint data.
It can be later used to store other state information related to
DocumentNodeStore
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Checkpoints.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Collection.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/memory/MemoryDocumentStore.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/CheckpointsTest.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Checkpoints.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Checkpoints.java?rev=1581297&r1=1581296&r2=1581297&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Checkpoints.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Checkpoints.java
Tue Mar 25 12:02:04 2014
@@ -38,12 +38,12 @@ class Checkpoints {
* Id of checkpoint document. It differs from normal convention of ID used
for NodeDocument
* which back JCR Nodes as it is internal to DocumentNodeStore
*/
- private static final String ID = "/checkpoint";
+ private static final String ID = "checkpoint";
/**
* Property name to store all checkpoint data. The data is stored as
Revision => expiryTime
*/
- private static final String PROP_CHECKPOINT = "checkpoint";
+ private static final String PROP_CHECKPOINT = "data";
private final DocumentNodeStore nodeStore;
@@ -62,7 +62,7 @@ class Checkpoints {
UpdateOp op = new UpdateOp(ID, false);
long endTime = nodeStore.getClock().getTime() + lifetimeInMillis;
op.setMapEntry(PROP_CHECKPOINT, r, Long.toString(endTime));
- store.createOrUpdate(NODES, op);
+ store.createOrUpdate(Collection.SETTINGS, op);
return r;
}
@@ -73,11 +73,12 @@ class Checkpoints {
* @return oldest valid checkpoint registered. Might return null if no
valid
* checkpoint found
*/
+ @SuppressWarnings("unchecked")
@CheckForNull
public Revision getOldestRevisionToKeep() {
//Get uncached doc
- NodeDocument cdoc = store.find(NODES, ID, 0);
- SortedMap<Revision, String> checkpoints =
cdoc.getLocalMap(PROP_CHECKPOINT);
+ Document cdoc = store.find(Collection.SETTINGS, ID, 0);
+ SortedMap<Revision, String> checkpoints = (SortedMap<Revision,
String>) cdoc.get(PROP_CHECKPOINT);
final long currentTime = nodeStore.getClock().getTime();
UpdateOp op = new UpdateOp(ID, false);
@@ -95,7 +96,7 @@ class Checkpoints {
}
if (op.hasChanges()) {
- store.findAndUpdate(NODES, op);
+ store.findAndUpdate(Collection.SETTINGS, op);
log.info("Purged {} expired checkpoints", op.getChanges().size());
}
@@ -106,7 +107,7 @@ class Checkpoints {
if (store.find(NODES, ID) == null) {
UpdateOp updateOp = new UpdateOp(ID, true);
updateOp.set(Document.ID, ID);
- store.createOrUpdate(NODES, updateOp);
+ store.createOrUpdate(Collection.SETTINGS, updateOp);
}
}
}
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Collection.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Collection.java?rev=1581297&r1=1581296&r2=1581297&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Collection.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Collection.java
Tue Mar 25 12:02:04 2014
@@ -58,6 +58,18 @@ public abstract class Collection<T exten
}
};
+ /**
+ * The 'settings' collection contains setting/state data required for
DocumentNodeStore
+ */
+ public static final Collection<Document> SETTINGS =
+ new Collection<Document>("settings") {
+ @Override
+ @Nonnull
+ public Document newDocument(DocumentStore store) {
+ return new Document();
+ }
+ };
+
private final String name;
public Collection(String name) {
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/memory/MemoryDocumentStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/memory/MemoryDocumentStore.java?rev=1581297&r1=1581296&r2=1581297&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/memory/MemoryDocumentStore.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/memory/MemoryDocumentStore.java
Tue Mar 25 12:02:04 2014
@@ -61,6 +61,12 @@ public class MemoryDocumentStore impleme
private ConcurrentSkipListMap<String, Document> clusterNodes =
new ConcurrentSkipListMap<String, Document>();
+ /**
+ * The 'settings' collection.
+ */
+ private ConcurrentSkipListMap<String, Document> settings =
+ new ConcurrentSkipListMap<String, Document>();
+
private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
/**
@@ -169,6 +175,8 @@ public class MemoryDocumentStore impleme
return (ConcurrentSkipListMap<String, T>) nodes;
} else if (collection == Collection.CLUSTER_NODES) {
return (ConcurrentSkipListMap<String, T>) clusterNodes;
+ }else if (collection == Collection.SETTINGS) {
+ return (ConcurrentSkipListMap<String, T>) settings;
} else {
throw new IllegalArgumentException(
"Unknown collection: " + collection.toString());
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java?rev=1581297&r1=1581296&r2=1581297&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
Tue Mar 25 12:02:04 2014
@@ -88,6 +88,7 @@ public class MongoDocumentStore implemen
private final DBCollection nodes;
private final DBCollection clusterNodes;
+ private final DBCollection settings;
/**
* The sum of all milliseconds this class waited for MongoDB.
@@ -115,6 +116,8 @@ public class MongoDocumentStore implemen
Collection.NODES.toString());
clusterNodes = db.getCollection(
Collection.CLUSTER_NODES.toString());
+ settings = db.getCollection(
+ Collection.SETTINGS.toString());
// indexes:
// the _id field is the primary key, so we don't need to define it
@@ -613,7 +616,9 @@ public class MongoDocumentStore implemen
return nodes;
} else if (collection == Collection.CLUSTER_NODES) {
return clusterNodes;
- } else {
+ } else if (collection == Collection.SETTINGS) {
+ return settings;
+ }else {
throw new IllegalArgumentException(
"Unknown collection: " + collection.toString());
}
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/CheckpointsTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/CheckpointsTest.java?rev=1581297&r1=1581296&r2=1581297&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/CheckpointsTest.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/CheckpointsTest.java
Tue Mar 25 12:02:04 2014
@@ -22,6 +22,7 @@ import org.apache.jackrabbit.oak.spi.com
import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.stats.Clock;
+import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -30,10 +31,15 @@ import static org.junit.Assert.assertNul
public class CheckpointsTest {
- private final Clock clock = new Clock.Virtual();
+ private Clock clock;
- private final DocumentNodeStore store =
- new DocumentMK.Builder().clock(clock).getNodeStore();
+ private DocumentNodeStore store;
+
+ @Before
+ public void setUp() throws InterruptedException {
+ clock = new Clock.Virtual();
+ store = new DocumentMK.Builder().clock(clock).getNodeStore();
+ }
@Test
public void testCheckpointPurge() throws Exception {