Search in sources :

Example 71 with BasicBSONObject

use of org.bson.BasicBSONObject 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)

Aggregations

BasicBSONObject (org.bson.BasicBSONObject)71 Test (org.junit.Test)23 BSONObject (org.bson.BSONObject)20 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)14 BSONWritable (com.mongodb.hadoop.io.BSONWritable)13 ArrayList (java.util.ArrayList)13 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)13 MapObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector)13 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)13 BasicDBObject (com.mongodb.BasicDBObject)11 ObjectId (org.bson.types.ObjectId)11 IOException (java.io.IOException)7 DataBag (org.apache.pig.data.DataBag)6 Tuple (org.apache.pig.data.Tuple)5 Mongo (com.mongodb.Mongo)4 Date (java.util.Date)4 Map (java.util.Map)4 DoubleWritable (org.apache.hadoop.io.DoubleWritable)4 Text (org.apache.hadoop.io.Text)4 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)3