Checkpoints { @SuppressWarnings("unchecked") @Nullable public Revision getOldestRevisionToKeep() { SortedMap<Revision, Info> checkpoints = getCheckpoints(); if(checkpoints.isEmpty()){ log.debug("No checkpoint registered so far"); return null; } final long currentTime = nodeStore.getClock().getTime(); UpdateOp op = new UpdateOp(ID, false); Revision lastAliveRevision = null; for (Map.Entry<Revision, Info> e : checkpoints.entrySet()) { long expiryTime = e.getValue().getExpiryTime(); if (currentTime > expiryTime) { op.removeMapEntry(PROP_CHECKPOINT, e.getKey()); } else { Revision cpRev = e.getKey(); RevisionVector rv = e.getValue().getCheckpoint(); if (rv != null) { cpRev = rv.getRevision(cpRev.getClusterId()); } lastAliveRevision = Utils.min(lastAliveRevision, cpRev); } } if (op.hasChanges()) { store.findAndUpdate(Collection.SETTINGS, op); log.debug("Purged {} expired checkpoints", op.getChanges().size()); } return lastAliveRevision; } Checkpoints(DocumentNodeStore store); Revision create(long lifetimeInMillis, Map<String, String> info); void release(String checkpoint); @SuppressWarnings("unchecked") @Nullable Revision getOldestRevisionToKeep();  }
@Test public void testGetOldestRevisionToKeep() throws Exception { long et1 = 1000, et2 = et1 + 1000; String r1 = store.getHeadRevision().toString(); Revision c1 = Revision.fromString(store.checkpoint(et1)); NodeBuilder b2 = store.getRoot().builder(); b2.child("x"); store.merge(b2, EmptyHook.INSTANCE, CommitInfo.EMPTY); String r2 = store.getHeadRevision().toString(); Revision c2 = Revision.fromString(store.checkpoint(et2)); assertNotEquals(c1, c2); assertEquals(r1, store.getCheckpoints().getOldestRevisionToKeep().toString()); long starttime = clock.getTime(); clock.waitUntil(starttime + et1 + 1); assertEquals(r2, store.getCheckpoints().getOldestRevisionToKeep().toString()); clock.waitUntil(starttime + et2 + 1); assertNull(store.getCheckpoints().getOldestRevisionToKeep()); }