Search in sources :

Example 6 with RevisionVector

use of org.apache.jackrabbit.oak.plugins.document.RevisionVector in project jackrabbit-oak by apache.

the class BroadcastTest method benchmark.

private static void benchmark() throws IOException {
    FileUtils.deleteDirectory(new File("target/broadcastTest"));
    new File("target/broadcastTest").mkdirs();
    String type = "tcp:key 1;ports 9700 9800";
    ArrayList<PersistentCache> nodeList = new ArrayList<PersistentCache>();
    for (int nodes = 1; nodes < 20; nodes++) {
        PersistentCache pc = new PersistentCache("target/broadcastTest/p" + nodes + ",broadcast=" + type);
        Cache<PathRev, StringValue> cache = openCache(pc);
        String key = "/test" + Math.random();
        PathRev k = new PathRev(key, new RevisionVector(new Revision(0, 0, 0)));
        long time = System.currentTimeMillis();
        for (int i = 0; i < 2000; i++) {
            cache.put(k, new StringValue("Hello World " + i));
            cache.invalidate(k);
            cache.getIfPresent(k);
        }
        time = System.currentTimeMillis() - time;
        System.out.println("nodes: " + nodes + " time: " + time);
        nodeList.add(pc);
    }
    for (PersistentCache c : nodeList) {
        c.close();
    }
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) PathRev(org.apache.jackrabbit.oak.plugins.document.PathRev) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) ArrayList(java.util.ArrayList) StringValue(org.apache.jackrabbit.oak.plugins.document.util.StringValue) File(java.io.File)

Example 7 with RevisionVector

use of org.apache.jackrabbit.oak.plugins.document.RevisionVector in project jackrabbit-oak by apache.

the class BroadcastTest method broadcastTry.

private static boolean broadcastTry(String type, int minPercentCorrect, boolean tryOnly) throws Exception {
    FileUtils.deleteDirectory(new File("target/broadcastTest"));
    new File("target/broadcastTest").mkdirs();
    PersistentCache p1 = new PersistentCache("target/broadcastTest/p1,broadcast=" + type);
    PersistentCache p2 = new PersistentCache("target/broadcastTest/p2,broadcast=" + type);
    Cache<PathRev, StringValue> c1 = openCache(p1);
    Cache<PathRev, StringValue> c2 = openCache(p2);
    String key = "/test" + Math.random();
    PathRev k = new PathRev(key, new RevisionVector(new Revision(0, 0, 0)));
    int correct = 0;
    for (int i = 0; i < 50; i++) {
        c1.put(k, new StringValue("Hello World " + i));
        waitFor(c2, k, 10000);
        StringValue v2 = c2.getIfPresent(k);
        if (v2 != null && v2.toString().equals("Hello World " + i)) {
            correct++;
        }
        c2.invalidate(k);
        assertNull(c2.getIfPresent(k));
        waitFor(c1, k, null, 10000);
        StringValue v1 = c1.getIfPresent(k);
        if (v1 == null) {
            correct++;
        }
    }
    p1.close();
    p2.close();
    if (correct >= minPercentCorrect) {
        return true;
    }
    if (tryOnly) {
        return false;
    }
    Assert.fail("min: " + minPercentCorrect + " got: " + correct);
    return false;
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) PathRev(org.apache.jackrabbit.oak.plugins.document.PathRev) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) StringValue(org.apache.jackrabbit.oak.plugins.document.util.StringValue) File(java.io.File)

Example 8 with RevisionVector

use of org.apache.jackrabbit.oak.plugins.document.RevisionVector in project jackrabbit-oak by apache.

the class ReadPreferenceIT method testMongoReadPreferences.

@Test
public void testMongoReadPreferences() throws Exception {
    ReadPreference testPref = ReadPreference.secondary();
    mongoDS.getDBCollection(NODES).getDB().setReadPreference(testPref);
    NodeStore extNodeStore = mk2.getNodeStore();
    NodeBuilder b1 = extNodeStore.getRoot().builder();
    b1.child("x").child("y").setProperty("xyz", "123");
    extNodeStore.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // wait until the change is visible
    NodeStore nodeStore = mk.getNodeStore();
    while (true) {
        if (nodeStore.getRoot().hasChildNode("x")) {
            break;
        } else {
            Thread.sleep(100);
        }
    }
    // the change hasn't been replicated yet, primary must be used
    assertEquals(ReadPreference.primary(), mongoDS.getMongoReadPreference(NODES, null, "/x/y", DocumentReadPreference.PREFER_SECONDARY_IF_OLD_ENOUGH));
    // make the secondary up-to-date
    DocumentNodeState ns = (DocumentNodeState) nodeStore.getRoot().getChildNode("x").getChildNode("y");
    // add revision for the local cluster node
    RevisionVector lastSeenRev = ns.getLastRevision().update(new Revision(Revision.getCurrentTimestamp(), 0, 1));
    primary.set(lastSeenRev);
    secondary.set(lastSeenRev);
    replica.updateRevisions();
    // change has been replicated by now, it's fine to use secondary
    assertEquals(testPref, mongoDS.getMongoReadPreference(NODES, null, "/x/y", DocumentReadPreference.PREFER_SECONDARY_IF_OLD_ENOUGH));
}
Also used : ReadPreference(com.mongodb.ReadPreference) DocumentReadPreference(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore.DocumentReadPreference) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) Revision(org.apache.jackrabbit.oak.plugins.document.Revision) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test) AbstractMongoConnectionTest(org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest)

Example 9 with RevisionVector

use of org.apache.jackrabbit.oak.plugins.document.RevisionVector in project jackrabbit-oak by apache.

the class Utils method getMinTimestampForDiff.

/**
     * Returns the minimum timestamp to use for a query for child documents that
     * have been modified between {@code fromRev} and {@code toRev}.
     *
     * @param fromRev the from revision.
     * @param toRev the to revision.
     * @param minRevisions the minimum revisions of foreign cluster nodes. These
     *                     are derived from the startTime of a cluster node.
     * @return the minimum timestamp.
     */
public static long getMinTimestampForDiff(@Nonnull RevisionVector fromRev, @Nonnull RevisionVector toRev, @Nonnull RevisionVector minRevisions) {
    // make sure we have minimum revisions for all known cluster nodes
    fromRev = fromRev.pmax(minRevisions);
    toRev = toRev.pmax(minRevisions);
    // keep only revision entries that changed
    RevisionVector from = fromRev.difference(toRev);
    RevisionVector to = toRev.difference(fromRev);
    // now calculate minimum timestamp
    long min = Long.MAX_VALUE;
    for (Revision r : from) {
        min = Math.min(r.getTimestamp(), min);
    }
    for (Revision r : to) {
        min = Math.min(r.getTimestamp(), min);
    }
    return min;
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector)

Example 10 with RevisionVector

use of org.apache.jackrabbit.oak.plugins.document.RevisionVector in project jackrabbit-oak by apache.

the class ReplicaSetInfo method getSecondariesSafeTimestamp.

/**
     * Find the oldest revision which hasn't been replicated from primary to
     * secondary yet and return its timestamp. If all revisions has been already
     * replicated, return the date of the measurement.
     *
     * @return the point in time to which the secondary instances has been synchronized
     */
private long getSecondariesSafeTimestamp(Timestamped<RevisionVector> primary, Iterable<Timestamped<RevisionVector>> secondaries) {
    final RevisionVector priRev = primary.getValue();
    Long oldestNotReplicated = null;
    for (Timestamped<RevisionVector> v : secondaries) {
        RevisionVector secRev = v.getValue();
        if (secRev.equals(priRev)) {
            continue;
        }
        for (Revision pr : priRev) {
            Revision sr = secRev.getRevision(pr.getClusterId());
            if (pr.equals(sr)) {
                continue;
            }
            if (oldestNotReplicated == null || oldestNotReplicated > pr.getTimestamp()) {
                oldestNotReplicated = pr.getTimestamp();
            }
        }
    }
    if (oldestNotReplicated == null) {
        long minOpTimestamp = primary.getOperationTimestamp();
        for (Timestamped<RevisionVector> v : secondaries) {
            if (v.getOperationTimestamp() < minOpTimestamp) {
                minOpTimestamp = v.getOperationTimestamp();
            }
        }
        return minOpTimestamp;
    } else {
        return oldestNotReplicated;
    }
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector)

Aggregations

RevisionVector (org.apache.jackrabbit.oak.plugins.document.RevisionVector)16 Revision (org.apache.jackrabbit.oak.plugins.document.Revision)13 Test (org.junit.Test)8 File (java.io.File)3 AbstractDocumentNodeState (org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState)3 PathRev (org.apache.jackrabbit.oak.plugins.document.PathRev)3 StringValue (org.apache.jackrabbit.oak.plugins.document.util.StringValue)3 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)3 ArrayList (java.util.ArrayList)2 PathFilter (org.apache.jackrabbit.oak.plugins.index.PathFilter)2 BasicDBObject (com.mongodb.BasicDBObject)1 DBCollection (com.mongodb.DBCollection)1 DBObject (com.mongodb.DBObject)1 ReadPreference (com.mongodb.ReadPreference)1 FileOutputStream (java.io.FileOutputStream)1 HashSet (java.util.HashSet)1 AbstractMongoConnectionTest (org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest)1 DocumentNodeState (org.apache.jackrabbit.oak.plugins.document.DocumentNodeState)1 DocumentReadPreference (org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore.DocumentReadPreference)1 LocalChanges (org.apache.jackrabbit.oak.plugins.document.mongo.replica.LocalChanges)1