VersionGCSupport { public long getOldestDeletedOnceTimestamp(Clock clock, long precisionMs) { long ts = 0; long now = clock.getTime(); long duration = (now - ts) / 2; Iterable<NodeDocument> docs; while (duration > precisionMs) { LOG.debug("find oldest _deletedOnce, check < {}", Utils.timestampToString(ts + duration)); docs = getPossiblyDeletedDocs(ts, ts + duration); if (docs.iterator().hasNext()) { duration /= 2; } else { ts = ts + duration; duration /= 2; } Utils.closeIfCloseable(docs); } LOG.debug("find oldest _deletedOnce to be {}", Utils.timestampToString(ts)); return ts; } VersionGCSupport(DocumentStore store); Iterable<NodeDocument> getPossiblyDeletedDocs(final long fromModified,
                                                         final long toModified); @NotNull DocumentStore getDocumentStore(); long getOldestDeletedOnceTimestamp(Clock clock, long precisionMs); long getDeletedOnceCount();  }
@Test public void findOldest() { long secs = 123456; long offset = SECONDS.toMillis(secs); Revision r = new Revision(offset, 0, 1); String id = Utils.getIdFromPath("/doc-del"); ids.add(id); UpdateOp op = new UpdateOp(id, true); NodeDocument.setModified(op, r); NodeDocument.setDeleted(op, r, true); store.create(Collection.NODES, Lists.newArrayList(op)); long reportedsecs = gcSupport.getOldestDeletedOnceTimestamp(Clock.SIMPLE, 1) / SECONDS.toMillis(1); assertTrue("diff (s) should be < 5: " + Math.abs(secs - reportedsecs), Math.abs(secs - reportedsecs) < 5); }