Search in sources :

Example 21 with Revision

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

the class GetRootRevisionsCallable method call.

@Override
public Timestamped<RevisionVector> call() throws Exception {
    List<Revision> revisions = new ArrayList<Revision>();
    DBCollection collection = nodeCollections.get(hostName);
    long start = clock.getTime();
    DBObject root = collection.findOne(new BasicDBObject(Document.ID, "0:/"));
    long end = clock.getTime();
    long mid = (start + end) / 2;
    if (root == null) {
        LOG.warn("Can't get the root document on {}", hostName);
        return null;
    }
    DBObject lastRev = (DBObject) root.get("_lastRev");
    for (String clusterId : lastRev.keySet()) {
        String rev = (String) lastRev.get(clusterId);
        revisions.add(Revision.fromString(rev));
    }
    LOG.debug("Got /_lastRev from {}: {}", hostName, lastRev);
    return new Timestamped<RevisionVector>(new RevisionVector(revisions), mid);
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObject(com.mongodb.BasicDBObject) Revision(org.apache.jackrabbit.oak.plugins.document.Revision) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) ArrayList(java.util.ArrayList) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 22 with Revision

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

the class LocalChanges method gotRootRevisions.

@Override
public void gotRootRevisions(RevisionVector rootRevision) {
    if (rootRevision == null) {
        return;
    }
    Revision rootRevForLocalInstance = rootRevision.getRevision(clusterId);
    if (rootRevForLocalInstance == null) {
        return;
    }
    this.rootTS = rootRevForLocalInstance.getTimestamp();
    if (!replicaActive) {
        replicaActive = true;
        LOG.info("Replica set became active");
    }
    synchronized (this) {
        if (latestChange != 0 && latestChange <= rootTS) {
            latestChange = 0;
        }
        Iterator<Long> it = localChanges.values().iterator();
        while (it.hasNext()) {
            if (it.next() <= rootTS) {
                it.remove();
            }
        }
    }
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision)

Example 23 with Revision

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

the class CollisionMarkerTest method conditionalCollisionUpdate.

@Test
public void conditionalCollisionUpdate() throws Exception {
    NodeBuilder b1 = ns1.getRoot().builder();
    b1.child("test");
    b1.child("node");
    merge(ns1, b1);
    ns1.runBackgroundOperations();
    // initialize second node store after background ops
    // on ns1. this makes sure ns2 sees all changes done so far
    ns2 = newDocumentMK(connectionFactory.getConnection().getDB(), 3).getNodeStore();
    b1 = ns1.getRoot().builder();
    b1.child("node").child("foo");
    b1.child("test").setProperty("p", 1);
    merge(ns1, b1);
    Revision head = ns1.getHeadRevision().getRevision(ns1.getClusterId());
    NodeBuilder b2 = ns2.getRoot().builder();
    b2.child("node").child("bar");
    b2.child("test").setProperty("p", 2);
    try {
        merge(ns2, b2);
        fail("must fail with CommitFailedException");
    } catch (CommitFailedException e) {
    // expected
    }
    String rootId = Utils.getIdFromPath("/");
    NodeDocument root = ns2.getDocumentStore().find(NODES, rootId);
    assertFalse("root document must not have a collision marker for a" + " committed revision", root.getValueMap(COLLISIONS).containsKey(head));
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test) AbstractMongoConnectionTest(org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest)

Example 24 with Revision

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

the class MongoMissingLastRevSeekerTest method completeResult.

@Test
public void completeResult() throws Exception {
    final int NUM_DOCS = 200;
    // populate the store
    List<UpdateOp> ops = Lists.newArrayList();
    for (int i = 0; i < NUM_DOCS; i++) {
        UpdateOp op = new UpdateOp(getIdFromPath("/node-" + i), true);
        NodeDocument.setModified(op, new Revision(i * 5000, 0, 1));
        ops.add(op);
    }
    assertTrue(store.create(NODES, ops));
    Set<String> ids = Sets.newHashSet();
    boolean updated = false;
    MissingLastRevSeeker seeker = builder.createMissingLastRevSeeker();
    for (NodeDocument doc : seeker.getCandidates(0)) {
        if (!updated) {
            // as soon as we have the first document, update /node-0
            UpdateOp op = new UpdateOp(getIdFromPath("/node-0"), false);
            // and push out the _modified timestamp
            NodeDocument.setModified(op, new Revision(NUM_DOCS * 5000, 0, 1));
            // even after the update the document matches the query
            assertNotNull(store.findAndUpdate(NODES, op));
            updated = true;
        }
        if (doc.getPath().startsWith("/node-")) {
            ids.add(doc.getId());
        }
    }
    // seeker must return all documents
    assertEquals(NUM_DOCS, ids.size());
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) UpdateOp(org.apache.jackrabbit.oak.plugins.document.UpdateOp) MissingLastRevSeeker(org.apache.jackrabbit.oak.plugins.document.MissingLastRevSeeker) NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument) Test(org.junit.Test)

Example 25 with Revision

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

the class CacheTest method recoverIfCorrupt.

@Test
public void recoverIfCorrupt() throws Exception {
    FileUtils.deleteDirectory(new File("target/cacheTest"));
    new File("target/cacheTest").mkdirs();
    FileOutputStream out = new FileOutputStream("target/cacheTest/cache-0.data");
    out.write("corrupt".getBytes());
    out.close();
    PersistentCache pCache = new PersistentCache("target/cacheTest");
    CacheLIRS<PathRev, StringValue> cache = new CacheLIRS.Builder<PathRev, StringValue>().maximumSize(1).build();
    Cache<PathRev, StringValue> map = pCache.wrap(null, null, cache, CacheType.DIFF);
    String largeString = new String(new char[1024 * 1024]);
    for (int counter = 0; counter < 10; counter++) {
        long end = System.currentTimeMillis() + 100;
        while (System.currentTimeMillis() < end) {
            Thread.yield();
        }
        for (int i = 0; i < 100; i++) {
            PathRev k = new PathRev("/" + counter, new RevisionVector(new Revision(0, 0, i)));
            map.getIfPresent(k);
            map.put(k, new StringValue(largeString));
        }
    }
    assertTrue("Exceptions: " + pCache.getExceptionCount(), pCache.getExceptionCount() < 100);
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) PathRev(org.apache.jackrabbit.oak.plugins.document.PathRev) FileOutputStream(java.io.FileOutputStream) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) StringValue(org.apache.jackrabbit.oak.plugins.document.util.StringValue) File(java.io.File) Test(org.junit.Test)

Aggregations

Revision (org.apache.jackrabbit.oak.plugins.document.Revision)32 Test (org.junit.Test)17 RevisionVector (org.apache.jackrabbit.oak.plugins.document.RevisionVector)13 BasicDBObject (com.mongodb.BasicDBObject)4 DBObject (com.mongodb.DBObject)4 NodeDocument (org.apache.jackrabbit.oak.plugins.document.NodeDocument)4 PathRev (org.apache.jackrabbit.oak.plugins.document.PathRev)4 UpdateOp (org.apache.jackrabbit.oak.plugins.document.UpdateOp)4 DBCollection (com.mongodb.DBCollection)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 StringValue (org.apache.jackrabbit.oak.plugins.document.util.StringValue)3 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)3 TreeMap (java.util.TreeMap)2 AbstractDocumentNodeState (org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState)2 AbstractMongoConnectionTest (org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest)2 DocumentStoreException (org.apache.jackrabbit.oak.plugins.document.DocumentStoreException)2 Key (org.apache.jackrabbit.oak.plugins.document.UpdateOp.Key)2 Operation (org.apache.jackrabbit.oak.plugins.document.UpdateOp.Operation)2