use of de.fhg.igd.mongomvcc.VHistory in project mongomvcc by igd-geo.
the class MongoDBVMaintenance method doFindDanglingCommits.
private long[] doFindDanglingCommits(long expiry, TimeUnit unit) {
long maxTime = getMaxTime(expiry, unit);
//load all commits which are older than the expiry time. mark them as dangling
DBCollection collCommits = _db.getDB().getCollection(MongoDBConstants.COLLECTION_COMMITS);
DBCursor commits = collCommits.find(new BasicDBObject(MongoDBConstants.TIMESTAMP, //also include commits without a timestamp
new BasicDBObject("$not", new BasicDBObject("$gte", maxTime))), new BasicDBObject(MongoDBConstants.ID, 1));
IdSet danglingCommits = new IdHashSet();
for (DBObject o : commits) {
long cid = (Long) o.get(MongoDBConstants.ID);
danglingCommits.add(cid);
}
//walk through all branches and eliminate commits which are not dangling
DBCollection collBranches = _db.getDB().getCollection(MongoDBConstants.COLLECTION_BRANCHES);
DBCursor branches = collBranches.find(new BasicDBObject(), new BasicDBObject(MongoDBConstants.CID, 1));
VHistory history = _db.getHistory();
IdSet alreadyCheckedCommits = new IdHashSet();
for (DBObject o : branches) {
long cid = (Long) o.get(MongoDBConstants.CID);
while (cid != 0) {
if (alreadyCheckedCommits.contains(cid)) {
break;
}
alreadyCheckedCommits.add(cid);
danglingCommits.remove(cid);
cid = history.getParent(cid);
}
}
//all remaining commits must be dangling
return danglingCommits.toArray();
}
use of de.fhg.igd.mongomvcc.VHistory in project mongomvcc by igd-geo.
the class TreeTest method history.
/**
* Tests if the history works correctly
*/
@Test
public void history() {
long root = _master.getHead();
putPerson("Max", 3);
long c1 = _master.commit();
putPerson("Peter", 26);
long c2 = _master.commit();
VHistory h = _db.getHistory();
assertEquals(c1, h.getParent(c2));
assertEquals(root, h.getParent(c1));
assertEquals(0, h.getParent(root));
assertArrayEquals(new long[] { root }, h.getChildren(0));
assertArrayEquals(new long[] { c1 }, h.getChildren(root));
assertArrayEquals(new long[] { c2 }, h.getChildren(c1));
assertArrayEquals(new long[0], h.getChildren(c2));
VBranch master2 = _db.createBranch("master2", c1);
VCollection persons = master2.getCollection("persons");
persons.insert(_factory.createDocument("name", "Elvis"));
long c3 = master2.commit();
h = _db.getHistory();
assertEquals(c1, h.getParent(c2));
assertEquals(c1, h.getParent(c3));
assertEquals(root, h.getParent(c1));
assertEquals(0, h.getParent(root));
assertArrayEquals(new long[] { root }, h.getChildren(0));
assertArrayEquals(new long[] { c1 }, h.getChildren(root));
long[] c1c = h.getChildren(c1);
assertEquals(2, c1c.length);
assertTrue((c1c[0] == c2 && c1c[1] == c3) || (c1c[0] == c3 && c1c[1] == c2));
assertArrayEquals(new long[0], h.getChildren(c2));
assertArrayEquals(new long[0], h.getChildren(c3));
}
Aggregations