Checkpoints { @Nullable RevisionVector retrieve(@NotNull String checkpoint) throws IllegalArgumentException { Revision r; try { r = Revision.fromString(checkNotNull(checkpoint)); } catch (IllegalArgumentException e) { LOG.warn("Malformed checkpoint reference: {}", checkpoint); return null; } Info info = getCheckpoints().get(r); if (info == null) { return null; } RevisionVector rv = info.getCheckpoint(); if (rv == null) { rv = expand(r); } return rv; } Checkpoints(DocumentNodeStore store); Revision create(long lifetimeInMillis, Map<String, String> info); void release(String checkpoint); @SuppressWarnings("unchecked") @Nullable Revision getOldestRevisionToKeep();  }
@Test public void crossClusterCheckpointNewClusterNode() throws Exception { DocumentStore store = new MemoryDocumentStore(); DocumentNodeStore ns1 = builderProvider.newBuilder().setClusterId(1) .setDocumentStore(store).setAsyncDelay(0).getNodeStore(); NodeBuilder b1 = ns1.getRoot().builder(); b1.child("foo"); ns1.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY); String checkpoint = ns1.checkpoint(Long.MAX_VALUE); b1 = ns1.getRoot().builder(); b1.child("bar"); ns1.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY); ns1.runBackgroundOperations(); DocumentNodeStore ns2 = builderProvider.newBuilder().setClusterId(2) .setDocumentStore(store).setAsyncDelay(0).getNodeStore(); NodeBuilder b2 = ns2.getRoot().builder(); b2.child("baz"); ns2.merge(b2, EmptyHook.INSTANCE, CommitInfo.EMPTY); NodeState root = ns2.retrieve(checkpoint); assertNotNull(root); assertTrue(root.hasChildNode("foo")); assertFalse(root.hasChildNode("bar")); assertFalse(root.hasChildNode("baz")); }
@Test public void crossClusterReadOldCheckpoint() throws Exception { DocumentStore store = new MemoryDocumentStore(); DocumentNodeStore ns1 = builderProvider.newBuilder().setClusterId(1) .setDocumentStore(store).setAsyncDelay(0).getNodeStore(); NodeBuilder b1 = ns1.getRoot().builder(); b1.child("foo"); ns1.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY); ns1.runBackgroundOperations(); Revision headRev = Revision.fromString(ns1.getHeadRevision().toString()); long expires = Long.MAX_VALUE; String data = "{\"expires\":\"" + expires + "\"}"; UpdateOp update = new UpdateOp("checkpoint", false); update.setMapEntry("data", headRev, data); store.createOrUpdate(Collection.SETTINGS, update); DocumentNodeStore ns2 = builderProvider.newBuilder().setClusterId(2) .setDocumentStore(store).setAsyncDelay(0).getNodeStore(); NodeBuilder b2 = ns2.getRoot().builder(); b2.child("baz"); ns2.merge(b2, EmptyHook.INSTANCE, CommitInfo.EMPTY); NodeState root = ns2.retrieve(headRev.toString()); assertNotNull(root); assertTrue(root.hasChildNode("foo")); assertFalse(root.hasChildNode("baz")); }
@Test public void sameClusterReadOldCheckpoint() throws Exception { DocumentStore store = new MemoryDocumentStore(); DocumentNodeStore ns1 = builderProvider.newBuilder().setClusterId(1) .setDocumentStore(store).setAsyncDelay(0).getNodeStore(); NodeBuilder b1 = ns1.getRoot().builder(); b1.child("foo"); ns1.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY); ns1.runBackgroundOperations(); Revision headRev = Revision.fromString(ns1.getHeadRevision().toString()); long expires = Long.MAX_VALUE; String data = "{\"expires\":\"" + expires + "\"}"; UpdateOp update = new UpdateOp("checkpoint", false); update.setMapEntry("data", headRev, data); store.createOrUpdate(Collection.SETTINGS, update); NodeBuilder b2 = ns1.getRoot().builder(); b2.child("bar"); ns1.merge(b2, EmptyHook.INSTANCE, CommitInfo.EMPTY); NodeState root = ns1.retrieve(headRev.toString()); assertNotNull(root); assertTrue(root.hasChildNode("foo")); assertFalse(root.hasChildNode("bar")); }