Search in sources :

Example 6 with StringSort

use of org.apache.jackrabbit.oak.commons.sort.StringSort in project jackrabbit-oak by apache.

the class JournalEntryTest method applyToWithPath.

@Test
public void applyToWithPath() throws Exception {
    DiffCache cache = new MemoryDiffCache(new DocumentMK.Builder());
    StringSort sort = JournalEntry.newSorter();
    sort.add("/");
    sort.add("/foo");
    sort.add("/foo/a");
    sort.add("/foo/b");
    sort.add("/bar");
    sort.add("/bar/a");
    sort.add("/bar/b");
    RevisionVector from = new RevisionVector(Revision.newRevision(1));
    RevisionVector to = new RevisionVector(Revision.newRevision(1));
    sort.sort();
    JournalEntry.applyTo(sort, cache, "/foo", from, to);
    assertNotNull(cache.getChanges(from, to, "/foo", null));
    assertNotNull(cache.getChanges(from, to, "/foo/a", null));
    assertNotNull(cache.getChanges(from, to, "/foo/b", null));
    assertNull(cache.getChanges(from, to, "/bar", null));
    assertNull(cache.getChanges(from, to, "/bar/a", null));
    assertNull(cache.getChanges(from, to, "/bar/b", null));
}
Also used : StringSort(org.apache.jackrabbit.oak.commons.sort.StringSort) Test(org.junit.Test)

Example 7 with StringSort

use of org.apache.jackrabbit.oak.commons.sort.StringSort in project jackrabbit-oak by apache.

the class JournalEntryTest method addToWithPath.

@Test
public void addToWithPath() throws Exception {
    DocumentStore store = new MemoryDocumentStore();
    JournalEntry entry = JOURNAL.newDocument(store);
    entry.modified("/");
    entry.modified("/foo");
    entry.modified("/foo/a");
    entry.modified("/foo/b");
    entry.modified("/foo/c");
    entry.modified("/bar");
    entry.modified("/bar/a");
    entry.modified("/bar/b");
    entry.modified("/bar/c");
    StringSort sort = JournalEntry.newSorter();
    entry.addTo(sort, "/foo");
    assertEquals(4, sort.getSize());
    sort.close();
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) StringSort(org.apache.jackrabbit.oak.commons.sort.StringSort) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) Test(org.junit.Test)

Example 8 with StringSort

use of org.apache.jackrabbit.oak.commons.sort.StringSort in project jackrabbit-oak by apache.

the class JournalDiffLoader method readTrunkChanges.

private void readTrunkChanges(String path, RevisionVector beforeRev, RevisionVector afterRev, StringSort changes) throws IOException {
    JournalEntry localPending = ns.getCurrentJournalEntry();
    DocumentStore store = ns.getDocumentStore();
    NodeDocument root = Utils.getRootDocument(store);
    int clusterId = ns.getClusterId();
    Map<Integer, Revision> lastRevs = root.getLastRev();
    Revision localLastRev;
    if (clusterId == 0) {
        // read-only node store
        localLastRev = afterRev.getRevision(clusterId);
    } else {
        localLastRev = lastRevs.get(clusterId);
    }
    if (localLastRev == null) {
        throw new IllegalStateException("Root document does not have a " + "lastRev entry for local clusterId " + clusterId);
    }
    if (ns.isDisableBranches()) {
        beforeRev = beforeRev.asTrunkRevision();
        afterRev = afterRev.asTrunkRevision();
    } else {
        beforeRev = getBaseRevision(beforeRev);
        afterRev = getBaseRevision(afterRev);
    }
    if (beforeRev.equals(afterRev)) {
        return;
    }
    RevisionVector max = beforeRev.pmax(afterRev);
    RevisionVector min = beforeRev.pmin(afterRev);
    // do we need to include changes from pending local changes?
    if (!max.isRevisionNewer(localLastRev) && !localLastRev.equals(max.getRevision(clusterId))) {
        // journal does not contain all local changes
        localPending.addTo(changes, path);
        stats.numJournalEntries++;
    }
    for (Revision to : max) {
        Revision from = min.getRevision(to.getClusterId());
        if (from == null) {
            // there is no min revision with this clusterId
            // use revision with a timestamp of zero
            from = new Revision(0, 0, to.getClusterId());
        }
        StringSort invalidateOnly = JournalEntry.newSorter();
        try {
            stats.numJournalEntries += fillExternalChanges(changes, invalidateOnly, path, from, to, ns.getDocumentStore(), null, null);
        } finally {
            invalidateOnly.close();
        }
    }
}
Also used : StringSort(org.apache.jackrabbit.oak.commons.sort.StringSort)

Example 9 with StringSort

use of org.apache.jackrabbit.oak.commons.sort.StringSort in project jackrabbit-oak by apache.

the class JournalEntryTest method fillExternalChanges.

@Test
public void fillExternalChanges() throws Exception {
    DocumentStore store = new MemoryDocumentStore();
    JournalEntry entry = JOURNAL.newDocument(store);
    Set<String> paths = Sets.newHashSet();
    addRandomPaths(paths);
    entry.modified(paths);
    Revision r1 = new Revision(1, 0, 1);
    Revision r2 = new Revision(2, 0, 1);
    Revision r3 = new Revision(3, 0, 1);
    UpdateOp op = entry.asUpdateOp(r2);
    assertTrue(store.create(JOURNAL, Collections.singletonList(op)));
    StringSort sort = JournalEntry.newSorter();
    StringSort inv = JournalEntry.newSorter();
    JournalEntry.fillExternalChanges(sort, inv, r2, r3, store);
    assertEquals(0, sort.getSize());
    assertEquals(0, inv.getSize());
    JournalEntry.fillExternalChanges(sort, inv, r1, r2, store);
    assertEquals(paths.size(), sort.getSize());
    assertEquals(0, inv.getSize());
    sort.close();
    sort = JournalEntry.newSorter();
    JournalEntry.fillExternalChanges(sort, inv, r1, r3, store);
    assertEquals(paths.size(), sort.getSize());
    assertEquals(0, inv.getSize());
    sort.close();
    inv.close();
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) StringSort(org.apache.jackrabbit.oak.commons.sort.StringSort) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) Test(org.junit.Test)

Example 10 with StringSort

use of org.apache.jackrabbit.oak.commons.sort.StringSort in project jackrabbit-oak by apache.

the class JournalEntryTest method externalChanges.

private static StringSort externalChanges(Revision from, Revision to, DocumentStore store) throws IOException {
    StringSort changes = JournalEntry.newSorter();
    StringSort invalidate = JournalEntry.newSorter();
    try {
        JournalEntry.fillExternalChanges(changes, invalidate, from, to, store);
    } finally {
        invalidate.close();
    }
    return changes;
}
Also used : StringSort(org.apache.jackrabbit.oak.commons.sort.StringSort)

Aggregations

StringSort (org.apache.jackrabbit.oak.commons.sort.StringSort)13 Test (org.junit.Test)9 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)5 IOException (java.io.IOException)2 Map (java.util.Map)1 CacheStats (org.apache.jackrabbit.oak.cache.CacheStats)1 ChangeSetBuilder (org.apache.jackrabbit.oak.plugins.observation.ChangeSetBuilder)1 Clock (org.apache.jackrabbit.oak.stats.Clock)1