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