Search in sources :

Example 1 with IdHashSet

use of de.fhg.igd.mongomvcc.helper.IdHashSet in project mongomvcc by igd-geo.

the class Index method getDeletedOids.

/**
	 * For a given collection, this method lazily retrieves
	 * the OIDs of all deleted objects.
	 * @param collection the collection's name
	 * @return the OIDs
	 */
private IdSet getDeletedOids(String collection) {
    IdSet oids = _deletedOids.get(collection);
    if (oids == null) {
        oids = new IdHashSet();
        _deletedOids.put(collection, oids);
    }
    return oids;
}
Also used : IdSet(de.fhg.igd.mongomvcc.helper.IdSet) IdHashSet(de.fhg.igd.mongomvcc.helper.IdHashSet)

Example 2 with IdHashSet

use of de.fhg.igd.mongomvcc.helper.IdHashSet 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 3 with IdHashSet

use of de.fhg.igd.mongomvcc.helper.IdHashSet in project mongomvcc by igd-geo.

the class MongoDBVMaintenance method doFindUnreferencedDocuments.

private long[] doFindUnreferencedDocuments(String collection, long expiry, TimeUnit unit) {
    long maxTime = getMaxTime(expiry, unit);
    //fetch the OIDs of all documents older than the expiry time
    DBCollection collDocs = _db.getDB().getCollection(collection);
    DBCursor docs = collDocs.find(new BasicDBObject(MongoDBConstants.TIMESTAMP, //also include docs without a timestamp
    new BasicDBObject("$not", new BasicDBObject("$gte", maxTime))), new BasicDBObject(MongoDBConstants.ID, 1));
    IdSet oids = new IdHashSet(docs.count());
    for (DBObject o : docs) {
        oids.add((Long) o.get(MongoDBConstants.ID));
    }
    //iterate through all commits and eliminate referenced documents
    DBCollection collCommits = _db.getDB().getCollection(MongoDBConstants.COLLECTION_COMMITS);
    for (DBObject o : collCommits.find()) {
        Commit c = Tree.deserializeCommit(o);
        Map<String, IdMap> allObjs = c.getObjects();
        IdMap objs = allObjs.get(collection);
        if (objs != null) {
            //eliminate OIDs referenced by this commit
            IdMapIterator mi = objs.iterator();
            while (mi.hasNext()) {
                mi.advance();
                oids.remove(mi.value());
            }
        }
    }
    //the remaining OIDs must be the unreferenced ones
    return oids.toArray();
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObject(com.mongodb.BasicDBObject) DBCursor(com.mongodb.DBCursor) IdMap(de.fhg.igd.mongomvcc.helper.IdMap) Commit(de.fhg.igd.mongomvcc.impl.internal.Commit) IdSet(de.fhg.igd.mongomvcc.helper.IdSet) IdMapIterator(de.fhg.igd.mongomvcc.helper.IdMapIterator) IdHashSet(de.fhg.igd.mongomvcc.helper.IdHashSet) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject)

Example 4 with IdHashSet

use of de.fhg.igd.mongomvcc.helper.IdHashSet in project mongomvcc by igd-geo.

the class Index method getOIDs.

/**
	 * For a given collection, this method returns the OIDs of all objects
	 * @param collection the collection's name
	 * @return the OIDs
	 */
private IdSet getOIDs(String collection) {
    IdSet oids = _oids.get(collection);
    if (oids == null) {
        oids = new IdHashSet();
        _oids.put(collection, oids);
    }
    return oids;
}
Also used : IdSet(de.fhg.igd.mongomvcc.helper.IdSet) IdHashSet(de.fhg.igd.mongomvcc.helper.IdHashSet)

Aggregations

IdHashSet (de.fhg.igd.mongomvcc.helper.IdHashSet)4 IdSet (de.fhg.igd.mongomvcc.helper.IdSet)4 BasicDBObject (com.mongodb.BasicDBObject)2 DBCollection (com.mongodb.DBCollection)2 DBCursor (com.mongodb.DBCursor)2 DBObject (com.mongodb.DBObject)2 VHistory (de.fhg.igd.mongomvcc.VHistory)1 IdMap (de.fhg.igd.mongomvcc.helper.IdMap)1 IdMapIterator (de.fhg.igd.mongomvcc.helper.IdMapIterator)1 Commit (de.fhg.igd.mongomvcc.impl.internal.Commit)1