use of org.apache.jackrabbit.oak.stats.Clock in project jackrabbit-oak by apache.
the class DataStoreTrackerGCTest method getTestClock.
protected Clock getTestClock() throws InterruptedException {
Clock clock = new Clock.Virtual();
clock.waitUntil(getCurrentTimestamp());
return clock;
}
use of org.apache.jackrabbit.oak.stats.Clock in project jackrabbit-oak by apache.
the class JournalIT method doLargeCleanupTest.
private void doLargeCleanupTest(int offset, int size) throws Exception {
Clock clock = new Clock.Virtual();
DocumentMK mk1 = createMK(0, /* clusterId: 0 => uses clusterNodes collection */
0, new MemoryDocumentStore(), new MemoryBlobStore());
DocumentNodeStore ns1 = mk1.getNodeStore();
// make sure we're visible and marked as active
renewClusterIdLease(ns1);
JournalGarbageCollector gc = new JournalGarbageCollector(ns1);
clock.getTimeIncreasing();
clock.getTimeIncreasing();
// cleanup everything that might still be there
gc.gc(0, TimeUnit.MILLISECONDS);
// create entries as parametrized:
for (int i = offset; i < size + offset; i++) {
mk1.commit("/", "+\"regular" + i + "\": {}", null, null);
// always run background ops to 'flush' the change
// into the journal:
ns1.runBackgroundOperations();
}
// sleep 100millis
Thread.sleep(100);
// should now be able to clean up everything
assertEquals(size, gc.gc(0, TimeUnit.MILLISECONDS));
}
use of org.apache.jackrabbit.oak.stats.Clock in project jackrabbit-oak by apache.
the class ExternalChange method process.
/**
* Processes external changes if there are any.
*
* @return statistics about the background read operation.
*/
BackgroundReadStats process() {
Clock clock = store.getClock();
int clusterId = store.getClusterId();
long time = clock.getTime();
String id = Utils.getIdFromPath("/");
NodeDocument doc = store.getDocumentStore().find(NODES, id, store.getAsyncDelay());
if (doc == null) {
return stats;
}
try {
alignWithExternalRevisions(doc, clock, clusterId);
} catch (InterruptedException e) {
throw new RuntimeException("Background read interrupted", e);
}
StringSort externalSort = newSorter();
StringSort invalidate = newSorter();
Map<Integer, Revision> lastRevMap = doc.getLastRev();
try {
changeSetBuilder = new ChangeSetBuilder(store.getChangeSetMaxItems(), store.getChangeSetMaxDepth());
RevisionVector headRevision = store.getHeadRevision();
Set<Revision> externalChanges = newHashSet();
for (Map.Entry<Integer, Revision> e : lastRevMap.entrySet()) {
int machineId = e.getKey();
if (machineId == clusterId) {
// ignore own lastRev
continue;
}
Revision r = e.getValue();
Revision last = headRevision.getRevision(machineId);
if (last == null) {
// make sure we see all changes when a cluster node joins
last = new Revision(0, 0, machineId);
}
if (r.compareRevisionTime(last) > 0) {
// OAK-2345
// only consider as external change if
// the revision changed for the machineId
externalChanges.add(r);
// collect external changes
if (externalSort != null) {
// add changes for this particular clusterId to the externalSort
try {
fillExternalChanges(externalSort, invalidate, PathUtils.ROOT_PATH, last, r, store.getDocumentStore(), changeSetBuilder, journalPropertyHandler);
} catch (Exception e1) {
LOG.error("backgroundRead: Exception while reading external changes from journal: " + e1, e1);
closeQuietly(externalSort);
closeQuietly(invalidate);
externalSort = null;
invalidate = null;
}
}
}
}
stats.readHead = clock.getTime() - time;
time = clock.getTime();
// invalidate cache
if (cacheInvalidationNeeded(externalSort, invalidate)) {
// invalidate caches
if (externalSort == null) {
// if no externalSort available, then invalidate everything
invalidateCache();
} else {
stats.numExternalChanges = externalSort.getSize();
try {
sortAndInvalidate(externalSort);
sortAndInvalidate(invalidate);
} catch (Exception ioe) {
LOG.error("backgroundRead: got IOException during external sorting/cache invalidation (as a result, invalidating entire cache): " + ioe, ioe);
invalidateCache();
}
}
stats.cacheInvalidationTime = clock.getTime() - time;
}
// update head
if (!externalChanges.isEmpty()) {
updateHead(externalChanges, doc.getSweepRevisions(), externalSort);
}
} finally {
closeQuietly(externalSort);
closeQuietly(invalidate);
}
return stats;
}
use of org.apache.jackrabbit.oak.stats.Clock in project jackrabbit-oak by apache.
the class DocumentDiscoveryLiteServiceCrashTest method setup.
@Before
public void setup() throws Exception {
clock = new Clock.Virtual();
clock.waitUntil(System.currentTimeMillis());
ClusterNodeInfo.setClock(clock);
store = new MemoryDocumentStore();
wd1 = UUID.randomUUID().toString();
wd2 = UUID.randomUUID().toString();
}
use of org.apache.jackrabbit.oak.stats.Clock in project jackrabbit-oak by apache.
the class DocumentLeaseUpdateRetryTest method setup.
@Before
public void setup() throws Exception {
clock = new Clock.Virtual();
ClusterNodeInfo.setClock(clock);
ds = new TestStore();
ns = new DocumentMK.Builder().clock(clock).setDocumentStore(ds).setLeaseCheck(true).getNodeStore();
}
Aggregations