Search in sources :

Example 1 with VHistory

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();
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObject(com.mongodb.BasicDBObject) DBCursor(com.mongodb.DBCursor) VHistory(de.fhg.igd.mongomvcc.VHistory) IdSet(de.fhg.igd.mongomvcc.helper.IdSet) IdHashSet(de.fhg.igd.mongomvcc.helper.IdHashSet) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject)

Example 2 with VHistory

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));
}
Also used : VHistory(de.fhg.igd.mongomvcc.VHistory) VBranch(de.fhg.igd.mongomvcc.VBranch) VCollection(de.fhg.igd.mongomvcc.VCollection) Test(org.junit.Test) AbstractMongoDBVDatabaseTest(de.fhg.igd.mongomvcc.impl.AbstractMongoDBVDatabaseTest)

Aggregations

VHistory (de.fhg.igd.mongomvcc.VHistory)2 BasicDBObject (com.mongodb.BasicDBObject)1 DBCollection (com.mongodb.DBCollection)1 DBCursor (com.mongodb.DBCursor)1 DBObject (com.mongodb.DBObject)1 VBranch (de.fhg.igd.mongomvcc.VBranch)1 VCollection (de.fhg.igd.mongomvcc.VCollection)1 IdHashSet (de.fhg.igd.mongomvcc.helper.IdHashSet)1 IdSet (de.fhg.igd.mongomvcc.helper.IdSet)1 AbstractMongoDBVDatabaseTest (de.fhg.igd.mongomvcc.impl.AbstractMongoDBVDatabaseTest)1 Test (org.junit.Test)1