Search in sources :

Example 1 with Clock

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;
}
Also used : Clock(org.apache.jackrabbit.oak.stats.Clock)

Example 2 with 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));
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) JournalGarbageCollector(org.apache.jackrabbit.oak.plugins.document.JournalGarbageCollector) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) MemoryBlobStore(org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore) Clock(org.apache.jackrabbit.oak.stats.Clock)

Example 3 with Clock

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;
}
Also used : StringSort(org.apache.jackrabbit.oak.commons.sort.StringSort) ChangeSetBuilder(org.apache.jackrabbit.oak.plugins.observation.ChangeSetBuilder) Clock(org.apache.jackrabbit.oak.stats.Clock) IOException(java.io.IOException) Map(java.util.Map)

Example 4 with Clock

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();
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) Clock(org.apache.jackrabbit.oak.stats.Clock) Before(org.junit.Before)

Example 5 with Clock

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();
}
Also used : Virtual(org.apache.jackrabbit.oak.stats.Clock.Virtual) Clock(org.apache.jackrabbit.oak.stats.Clock) Before(org.junit.Before)

Aggregations

Clock (org.apache.jackrabbit.oak.stats.Clock)39 Test (org.junit.Test)24 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)21 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)19 Before (org.junit.Before)8 ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)3 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)2 BlobStore (org.apache.jackrabbit.oak.spi.blob.BlobStore)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 Calendar (java.util.Calendar)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 InitialContent (org.apache.jackrabbit.oak.InitialContent)1 Oak (org.apache.jackrabbit.oak.Oak)1 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)1 CONSTRAINT (org.apache.jackrabbit.oak.api.CommitFailedException.CONSTRAINT)1