Search in sources :

Example 1 with ChangeSetBuilder

use of org.apache.jackrabbit.oak.plugins.observation.ChangeSetBuilder in project jackrabbit-oak by apache.

the class ChangeSetFilterImplTest method testIncludeOnParentNodeTypeOverflow.

@Test
public void testIncludeOnParentNodeTypeOverflow() throws Exception {
    ChangeSetBuilder builder = sampleBuilder();
    ChangeSetFilterImpl prefilter = new ChangeSetFilterImpl(s("/"), true, null, s("/excluded"), s("foo", "bars"), s("nt:file"), s());
    assertTrue(prefilter.excludes(builder.build()));
    overflowParentNodeTypes(builder);
    assertFalse(prefilter.excludes(builder.build()));
}
Also used : ChangeSetBuilder(org.apache.jackrabbit.oak.plugins.observation.ChangeSetBuilder) Test(org.junit.Test)

Example 2 with ChangeSetBuilder

use of org.apache.jackrabbit.oak.plugins.observation.ChangeSetBuilder in project jackrabbit-oak by apache.

the class ChangeSetFilterImplTest method testIncludeOnAllNodeTypeOverflow.

@Test
public void testIncludeOnAllNodeTypeOverflow() throws Exception {
    ChangeSetBuilder builder = sampleBuilder();
    ChangeSetFilterImpl prefilter = new ChangeSetFilterImpl(s("/"), true, null, s("/excluded"), s("foo", "bars"), s("nt:file"), s());
    assertTrue(prefilter.excludes(builder.build()));
    overflowAllNodeTypes(builder);
    assertFalse(prefilter.excludes(builder.build()));
}
Also used : ChangeSetBuilder(org.apache.jackrabbit.oak.plugins.observation.ChangeSetBuilder) Test(org.junit.Test)

Example 3 with ChangeSetBuilder

use of org.apache.jackrabbit.oak.plugins.observation.ChangeSetBuilder in project jackrabbit-oak by apache.

the class ChangeSetFilterImplTest method testIncludeOnPropertyNamesOverflow.

@Test
public void testIncludeOnPropertyNamesOverflow() throws Exception {
    ChangeSetBuilder builder = sampleBuilder();
    ChangeSetFilterImpl prefilter = new ChangeSetFilterImpl(s("/"), true, null, s("/excluded"), s("foo", "bars"), s("nt:file"), s());
    assertTrue(prefilter.excludes(builder.build()));
    overflowPropertyNames(builder);
    assertFalse(prefilter.excludes(builder.build()));
}
Also used : ChangeSetBuilder(org.apache.jackrabbit.oak.plugins.observation.ChangeSetBuilder) Test(org.junit.Test)

Example 4 with ChangeSetBuilder

use of org.apache.jackrabbit.oak.plugins.observation.ChangeSetBuilder in project jackrabbit-oak by apache.

the class ChangeSetFilterImplTest method testOverflowing.

@Test
public void testOverflowing() throws Exception {
    ChangeSetBuilder builder = newBuilder(5, 5);
    assertTrue(overflowAllNodeTypes(builder).isAllNodeTypeOverflown());
    assertTrue(overflowParentNodeTypes(builder).isParentNodeTypeOverflown());
    assertTrue(overflowParentNodeNames(builder).isParentNodeNameOverflown());
    assertTrue(overflowParentPaths(builder).isParentPathOverflown());
    assertTrue(overflowPropertyNames(builder).isPropertyNameOverflown());
}
Also used : ChangeSetBuilder(org.apache.jackrabbit.oak.plugins.observation.ChangeSetBuilder) Test(org.junit.Test)

Example 5 with ChangeSetBuilder

use of org.apache.jackrabbit.oak.plugins.observation.ChangeSetBuilder 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)

Aggregations

ChangeSetBuilder (org.apache.jackrabbit.oak.plugins.observation.ChangeSetBuilder)11 Test (org.junit.Test)8 Stopwatch (com.google.common.base.Stopwatch)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 StringSort (org.apache.jackrabbit.oak.commons.sort.StringSort)1 ChangeSet (org.apache.jackrabbit.oak.plugins.observation.ChangeSet)1 Clock (org.apache.jackrabbit.oak.stats.Clock)1