Search in sources :

Example 11 with RevisionVector

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

the class ReplicaSetInfo method updateRevisions.

private void updateRevisions(Iterable<BasicBSONObject> members) {
    Set<String> secondaries = new HashSet<String>();
    boolean unknownState = false;
    String primary = null;
    for (BasicBSONObject member : members) {
        MemberState state;
        try {
            state = MemberState.valueOf(member.getString("stateStr"));
        } catch (IllegalArgumentException e) {
            state = MemberState.UNKNOWN;
        }
        String name = member.getString("name");
        if (hiddenMembers.contains(name)) {
            continue;
        }
        switch(state) {
            case PRIMARY:
                primary = name;
                continue;
            case SECONDARY:
                secondaries.add(name);
                break;
            case ARBITER:
                continue;
            default:
                LOG.debug("Invalid state {} for instance {}", state, name);
                unknownState = true;
                break;
        }
    }
    Set<String> hostsToCheck = new HashSet<String>();
    if (secondaries.isEmpty()) {
        LOG.debug("No secondaries found: {}", members);
        unknownState = true;
    } else {
        hostsToCheck.addAll(secondaries);
    }
    if (primary == null) {
        LOG.debug("No primary found: {}", members);
        unknownState = true;
    } else {
        hostsToCheck.add(primary);
    }
    Map<String, Timestamped<RevisionVector>> vectors = null;
    if (!unknownState) {
        vectors = getRootRevisions(hostsToCheck);
        if (vectors.containsValue(null)) {
            unknownState = true;
        }
    }
    if (unknownState) {
        rootRevisions = null;
        secondariesSafeTimestamp = 0;
    } else {
        Timestamped<RevisionVector> primaryRevision = vectors.get(primary);
        Iterable<Timestamped<RevisionVector>> secondaryRevisions = filterKeys(vectors, in(secondaries)).values();
        rootRevisions = pmin(transform(secondaryRevisions, Timestamped.<RevisionVector>getExtractFunction()));
        if (rootRevisions == null || primaryRevision == null || isEmpty(secondaryRevisions)) {
            secondariesSafeTimestamp = 0;
        } else {
            secondariesSafeTimestamp = getSecondariesSafeTimestamp(primaryRevision, secondaryRevisions);
        }
    }
    LOG.debug("Minimum root revisions: {}. Current lag: {}", rootRevisions, getLag());
    nodeCollections.retain(hostsToCheck);
}
Also used : BasicBSONObject(org.bson.BasicBSONObject) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) HashSet(java.util.HashSet)

Example 12 with RevisionVector

use of org.apache.jackrabbit.oak.plugins.document.RevisionVector 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 13 with RevisionVector

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

the class MongoDocumentStore method updateAccessedRevision.

@Override
public synchronized void updateAccessedRevision(RevisionVector revisions, int clusterId) {
    if (localChanges == null && replicaInfo != null) {
        localChanges = new LocalChanges(clusterId);
        replicaInfo.addListener(localChanges);
    }
    RevisionVector previousValue = mostRecentAccessedRevisions;
    if (mostRecentAccessedRevisions == null) {
        mostRecentAccessedRevisions = revisions;
    } else {
        mostRecentAccessedRevisions = mostRecentAccessedRevisions.pmax(revisions);
    }
    if (LOG.isDebugEnabled() && !mostRecentAccessedRevisions.equals(previousValue)) {
        LOG.debug("Most recent accessed revisions: {}", mostRecentAccessedRevisions);
    }
}
Also used : LocalChanges(org.apache.jackrabbit.oak.plugins.document.mongo.replica.LocalChanges) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector)

Example 14 with RevisionVector

use of org.apache.jackrabbit.oak.plugins.document.RevisionVector 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)

Example 15 with RevisionVector

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

the class RevisionsKeyTest method fromAsString.

@Test
public void fromAsString() {
    RevisionsKey k1 = new RevisionsKey(new RevisionVector(new Revision(1, 0, 1)), new RevisionVector(new Revision(2, 1, 2)));
    RevisionsKey k2 = RevisionsKey.fromString(k1.asString());
    assertEquals(k1, k2);
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) Test(org.junit.Test)

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