Examples of RevisionComparator


Examples of org.apache.jackrabbit.oak.plugins.mongomk.Revision.RevisionComparator

        if (doc == null) {
            return;
        }
        Map<Integer, Revision> lastRevMap = doc.getLastRev();
       
        RevisionComparator revisionComparator = getRevisionComparator();
        boolean hasNewRevisions = false;
        // the (old) head occurred first
        Revision headSeen = Revision.newRevision(0);
        // then we saw this new revision (from another cluster node)
        Revision otherSeen = Revision.newRevision(0);
        for (Entry<Integer, Revision> e : lastRevMap.entrySet()) {
            int machineId = e.getKey();
            if (machineId == clusterId) {
                continue;
            }
            Revision r = e.getValue();
            Revision last = lastKnownRevision.get(machineId);
            if (last == null || r.compareRevisionTime(last) > 0) {
                lastKnownRevision.put(machineId, r);
                hasNewRevisions = true;
                revisionComparator.add(r, otherSeen);
            }
        }
        if (hasNewRevisions) {
            // TODO invalidating the whole cache is not really needed,
            // instead only those children that are cached could be checked
            store.invalidateCache();
            // TODO only invalidate affected items
            docChildrenCache.invalidateAll();
            // add a new revision, so that changes are visible
            Revision r = Revision.newRevision(clusterId);
            // the latest revisions of the current cluster node
            // happened before the latest revisions of other cluster nodes
            revisionComparator.add(r, headSeen);
            // the head revision is after other revisions
            headRevision = Revision.newRevision(clusterId);
        }
        revisionComparator.purge(Revision.getCurrentTimestamp() - REMEMBER_REVISION_ORDER_MILLIS);
    }
View Full Code Here

Examples of org.apache.jackrabbit.oak.plugins.mongomk.Revision.RevisionComparator

        return revisionComparator;
    }

    @Override
    public void publishRevision(Revision foreignRevision, Revision changeRevision) {
        RevisionComparator revisionComparator = getRevisionComparator();
        if (revisionComparator.compare(headRevision, foreignRevision) >= 0) {
            // already visible
            return;
        }
        int clusterNodeId = foreignRevision.getClusterId();
        if (clusterNodeId == this.clusterId) {
            return;
        }
        // the (old) head occurred first
        Revision headSeen = Revision.newRevision(0);
        // then we saw this new revision (from another cluster node)
        Revision otherSeen = Revision.newRevision(0);
        // and after that, the current change
        Revision changeSeen = Revision.newRevision(0);
        revisionComparator.add(foreignRevision, otherSeen);
        // TODO invalidating the whole cache is not really needed,
        // but how to ensure we invalidate the right part of the cache?
        // possibly simply wait for the background thread to pick
        // up the changes, but this depends on how often this method is called
        store.invalidateCache();
        // the latest revisions of the current cluster node
        // happened before the latest revisions of other cluster nodes
        revisionComparator.add(headRevision, headSeen);
        revisionComparator.add(changeRevision, changeSeen);
        // the head revision is after other revisions
        headRevision = Revision.newRevision(clusterId);
    }
View Full Code Here

Examples of org.apache.jackrabbit.oak.plugins.mongomk.Revision.RevisionComparator

        }
    }
   
    @Test
    public void revisionComparatorSimple() {
        RevisionComparator comp = new RevisionComparator(0);
        Revision r1 = Revision.newRevision(0);
        Revision r2 = Revision.newRevision(0);
        assertEquals(r1.compareRevisionTime(r2), comp.compare(r1, r2));
        assertEquals(r2.compareRevisionTime(r1), comp.compare(r2, r1));
        assertEquals(r1.compareRevisionTime(r1), comp.compare(r1, r1));
    }
View Full Code Here

Examples of org.apache.jackrabbit.oak.plugins.mongomk.Revision.RevisionComparator

    }
   
    @Test
    public void revisionComparatorCluster() {
       
        RevisionComparator comp = new RevisionComparator(0);
       
        Revision r1c1 = new Revision(0x110, 0, 1);
        Revision r2c1 = new Revision(0x120, 0, 1);
        Revision r3c1 = new Revision(0x130, 0, 1);
        Revision r1c2 = new Revision(0x100, 0, 2);
        Revision r2c2 = new Revision(0x200, 0, 2);
        Revision r3c2 = new Revision(0x300, 0, 2);

        // first, only timestamps are compared
        assertEquals(1, comp.compare(r1c1, r1c2));
        assertEquals(-1, comp.compare(r2c1, r2c2));
        assertEquals(-1, comp.compare(r3c1, r3c2));

        // now we declare r2+r3 of c1 to be after r2+r3 of c2
        comp.add(r2c1, new Revision(0x20, 0, 0));
        comp.add(r2c2, new Revision(0x10, 0, 0));

        assertEquals(
                "1:\n r120-0-1:r20-0-0\n" +
                "2:\n r200-0-2:r10-0-0\n", comp.toString());

        assertEquals(1, comp.compare(r1c1, r1c2));
        assertEquals(1, comp.compare(r2c1, r2c2));
        // both r3cx are still "in the future"
        assertEquals(-1, comp.compare(r3c1, r3c2));
       
        // now we declare r3 of c1 to be before r3 of c2
        // (with the same range timestamp,
        // the revision timestamps are compared)
        comp.add(r3c1, new Revision(0x30, 0, 0));
        comp.add(r3c2, new Revision(0x30, 0, 0));

        assertEquals(
                "1:\n r120-0-1:r20-0-0 r130-0-1:r30-0-0\n" +
                "2:\n r200-0-2:r10-0-0 r300-0-2:r30-0-0\n", comp.toString());

        assertEquals(1, comp.compare(r1c1, r1c2));
        assertEquals(1, comp.compare(r2c1, r2c2));
        assertEquals(-1, comp.compare(r3c1, r3c2));
        // reverse
        assertEquals(-1, comp.compare(r1c2, r1c1));
        assertEquals(-1, comp.compare(r2c2, r2c1));
        assertEquals(1, comp.compare(r3c2, r3c1));
       
        // get rid of old timestamps
        comp.purge(0x10);
        assertEquals(
                "1:\n r120-0-1:r20-0-0 r130-0-1:r30-0-0\n" +
                "2:\n r300-0-2:r30-0-0\n", comp.toString());
        comp.purge(0x20);
        assertEquals(
                "1:\n r130-0-1:r30-0-0\n" +
                "2:\n r300-0-2:r30-0-0\n", comp.toString());
       
        // update an entry
        comp.add(new Revision(0x301, 1, 2), new Revision(0x30, 0, 0));
        assertEquals(
                "1:\n r130-0-1:r30-0-0\n" +
                "2:\n r301-1-2:r30-0-0\n", comp.toString());
       
        comp.purge(0x30);
        assertEquals("", comp.toString());

    }
View Full Code Here

Examples of org.apache.jackrabbit.oak.plugins.mongomk.Revision.RevisionComparator

        }
    }
   
    @Test
    public void revisionComparatorSimple() {
        RevisionComparator comp = new RevisionComparator(0);
        Revision r1 = Revision.newRevision(0);
        Revision r2 = Revision.newRevision(0);
        assertEquals(r1.compareRevisionTime(r2), comp.compare(r1, r2));
        assertEquals(r2.compareRevisionTime(r1), comp.compare(r2, r1));
        assertEquals(r1.compareRevisionTime(r1), comp.compare(r1, r1));
    }
View Full Code Here

Examples of org.apache.jackrabbit.oak.plugins.mongomk.Revision.RevisionComparator

    }

    @Test
    public void revisionComparatorCluster() {

        RevisionComparator comp = new RevisionComparator(0);

        Revision r0c1 = new Revision(0x010, 0, 1);
        Revision r0c2 = new Revision(0x010, 0, 2);
       
        Revision r1c1 = new Revision(0x110, 0, 1);
        Revision r2c1 = new Revision(0x120, 0, 1);
        Revision r3c1 = new Revision(0x130, 0, 1);
        Revision r1c2 = new Revision(0x100, 0, 2);
        Revision r2c2 = new Revision(0x200, 0, 2);
        Revision r3c2 = new Revision(0x300, 0, 2);

        // first, only timestamps are compared
        assertEquals(1, comp.compare(r1c1, r1c2));
        assertEquals(-1, comp.compare(r2c1, r2c2));
        assertEquals(-1, comp.compare(r3c1, r3c2));

        // now we declare r2+r3 of c1 to be after r2+r3 of c2
        comp.add(r2c1, new Revision(0x20, 0, 0));
        comp.add(r2c2, new Revision(0x10, 0, 0));

        assertEquals(
                "1:\n r120-0-1:r20-0-0\n" +
                "2:\n r200-0-2:r10-0-0\n", comp.toString());

        assertEquals(-1, comp.compare(r0c1, r0c2));

        assertEquals(1, comp.compare(r1c1, r1c2));
        assertEquals(1, comp.compare(r2c1, r2c2));
        // both r3cx are still "in the future"
        assertEquals(-1, comp.compare(r3c1, r3c2));

        // now we declare r3 of c1 to be before r3 of c2
        // (with the same range timestamp,
        // the revision timestamps are compared)
        comp.add(r3c1, new Revision(0x30, 0, 0));
        comp.add(r3c2, new Revision(0x30, 0, 0));

        assertEquals(
                "1:\n r120-0-1:r20-0-0 r130-0-1:r30-0-0\n" +
                "2:\n r200-0-2:r10-0-0 r300-0-2:r30-0-0\n", comp.toString());

        assertEquals(1, comp.compare(r1c1, r1c2));
        assertEquals(1, comp.compare(r2c1, r2c2));
        assertEquals(-1, comp.compare(r3c1, r3c2));
        // reverse
        assertEquals(-1, comp.compare(r1c2, r1c1));
        assertEquals(-1, comp.compare(r2c2, r2c1));
        assertEquals(1, comp.compare(r3c2, r3c1));

        // get rid of old timestamps
        comp.purge(0x10);
        assertEquals(
                "1:\n r120-0-1:r20-0-0 r130-0-1:r30-0-0\n" +
                "2:\n r300-0-2:r30-0-0\n", comp.toString());
        comp.purge(0x20);
        assertEquals(
                "1:\n r130-0-1:r30-0-0\n" +
                "2:\n r300-0-2:r30-0-0\n", comp.toString());

        // update an entry
        comp.add(new Revision(0x301, 1, 2), new Revision(0x30, 0, 0));
        assertEquals(
                "1:\n r130-0-1:r30-0-0\n" +
                "2:\n r301-1-2:r30-0-0\n", comp.toString());

        comp.purge(0x30);
        assertEquals("", comp.toString());

    }
View Full Code Here

Examples of org.apache.jackrabbit.oak.plugins.mongomk.Revision.RevisionComparator

    }

    @Test
    public void clusterCompare() {
        RevisionComparator comp = new RevisionComparator(1);

        // sequence of revisions as added to comparator later
        Revision r1c1 = new Revision(0x10, 0, 1);
        Revision r1c2 = new Revision(0x20, 0, 2);
        Revision r2c1 = new Revision(0x30, 0, 1);
        Revision r2c2 = new Revision(0x40, 0, 2);
       
        comp.add(r1c1, new Revision(0x10, 0, 0));
        comp.add(r2c1, new Revision(0x20, 0, 0));

        // there's no range for c2, and therefore this
        // revision must be considered to be in the future
        assertTrue(comp.compare(r1c2, r2c1) > 0);
       
        // add a range for r2r2
        comp.add(r2c2, new Revision(0x30, 0, 0));

        // now there is a range for c2, but the revision is old,
        // so it must be considered to be in the past
        assertTrue(comp.compare(r1c2, r2c1) < 0);
    }
View Full Code Here

Examples of org.apache.jackrabbit.oak.plugins.mongomk.Revision.RevisionComparator

        assertTrue(comp.compare(r1c2, r2c1) < 0);
    }

    @Test
    public void revisionSeen() {
        RevisionComparator comp = new RevisionComparator(1);

        Revision r0 = new Revision(0x01, 0, 1);
        Revision r1 = new Revision(0x10, 0, 1);
        Revision r2 = new Revision(0x20, 0, 1);
        Revision r21 = new Revision(0x21, 0, 1);
        Revision r3 = new Revision(0x30, 0, 1);
        Revision r4 = new Revision(0x40, 0, 1);
        Revision r5 = new Revision(0x50, 0, 1);

        comp.add(r1, new Revision(0x10, 0, 0));
        comp.add(r2, new Revision(0x20, 0, 0));
        comp.add(r3, new Revision(0x30, 0, 0));
        comp.add(r4, new Revision(0x40, 0, 0));

        // older than first range -> must return null
        assertNull(comp.getRevisionSeen(r0));

        // exact range start matches
        assertEquals(new Revision(0x10, 0, 0), comp.getRevisionSeen(r1));
        assertEquals(new Revision(0x20, 0, 0), comp.getRevisionSeen(r2));
        assertEquals(new Revision(0x30, 0, 0), comp.getRevisionSeen(r3));
        assertEquals(new Revision(0x40, 0, 0), comp.getRevisionSeen(r4));

        // revision newer than most recent range -> NEWEST
        assertEquals(RevisionComparator.NEWEST, comp.getRevisionSeen(r5));

        // within a range -> must return lower bound of next higher range
        assertEquals(new Revision(0x30, 0, 0), comp.getRevisionSeen(r21));
    }
View Full Code Here

Examples of org.apache.jackrabbit.oak.plugins.mongomk.Revision.RevisionComparator

        } else {
            clusterNodeInfo = null;
        }
        this.clusterId = cid;
       
        this.revisionComparator = new RevisionComparator(clusterId);
        this.asyncDelay = builder.getAsyncDelay();
        this.branches = new UnmergedBranches(revisionComparator);

        //TODO Make stats collection configurable as it add slight overhead
        //TODO Expose the stats as JMX beans
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.