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);
}
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();
}
}
}
}
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));
}
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());
}
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);
}
Aggregations