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