Search in sources :

Example 1 with IdSet

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

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

the class Index method insert.

/**
 * Inserts a new object into the index and marks it as dirty
 * @param collection the name of the collection the object has been added to
 * @param uid the new object's UID
 * @param oid the OID
 */
public void insert(String collection, long uid, long oid) {
    IdMap objs = getObjects(collection);
    IdSet oids = getOIDs(collection);
    long prev = objs.put(uid, oid);
    if (prev != 0) {
        // an existing object is replaced by a new instance. Remove the
        // old OID, since the old object is now invalid (within this index)
        oids.remove(prev);
        if (oid == -1) {
            getDeletedOids(collection).add(prev);
        }
    }
    if (oid != -1) {
        oids.add(oid);
    }
    getDirtyObjects(collection).put(uid, oid);
}
Also used : IdMap(de.fhg.igd.mongomvcc.helper.IdMap) IdSet(de.fhg.igd.mongomvcc.helper.IdSet)

Example 3 with IdSet

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

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

the class Index method readCommit.

/**
 * Iteratively reads the information from the given commit and all its
 * ancestors and builds up the index
 * @param c the commit to read
 * @param tree the tree of commits
 */
private void readCommit(Commit c, Tree tree) {
    ArrayDeque<Commit> stack = new ArrayDeque<Commit>();
    while (true) {
        // iteratively read parent commit (if there is any)
        stack.addLast(c);
        long cid = c.getParentCID();
        if (cid == 0) {
            break;
        }
        c = tree.resolveCommit(cid);
    }
    while (!stack.isEmpty()) {
        c = stack.removeLast();
        // read objects from the given commit and put them into the index
        for (Map.Entry<String, IdMap> e : c.getObjects().entrySet()) {
            IdMap m = getObjects(e.getKey());
            IdSet o = getOIDs(e.getKey());
            IdMapIterator it = e.getValue().iterator();
            while (it.hasNext()) {
                it.advance();
                if (it.value() < 0) {
                    // deleted object
                    long prev = m.get(it.key());
                    if (prev != 0) {
                        m.remove(it.key());
                        o.remove(prev);
                    }
                } else {
                    long prev = m.put(it.key(), it.value());
                    if (prev != 0) {
                        // overwrite object with new value
                        o.remove(prev);
                    }
                    o.add(it.value());
                }
            }
        }
    }
}
Also used : IdMap(de.fhg.igd.mongomvcc.helper.IdMap) IdSet(de.fhg.igd.mongomvcc.helper.IdSet) IdMapIterator(de.fhg.igd.mongomvcc.helper.IdMapIterator) Map(java.util.Map) IdHashMap(de.fhg.igd.mongomvcc.helper.IdHashMap) HashMap(java.util.HashMap) IdMap(de.fhg.igd.mongomvcc.helper.IdMap) ArrayDeque(java.util.ArrayDeque)

Example 5 with IdSet

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

IdSet (de.fhg.igd.mongomvcc.helper.IdSet)7 IdHashSet (de.fhg.igd.mongomvcc.helper.IdHashSet)4 IdMap (de.fhg.igd.mongomvcc.helper.IdMap)4 BasicDBObject (com.mongodb.BasicDBObject)3 DBCollection (com.mongodb.DBCollection)3 IdMapIterator (de.fhg.igd.mongomvcc.helper.IdMapIterator)3 DBCursor (com.mongodb.DBCursor)2 DBObject (com.mongodb.DBObject)2 Commit (de.fhg.igd.mongomvcc.impl.internal.Commit)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DB (com.mongodb.DB)1 VException (de.fhg.igd.mongomvcc.VException)1 VHistory (de.fhg.igd.mongomvcc.VHistory)1 IdHashMap (de.fhg.igd.mongomvcc.helper.IdHashMap)1 IdSetIterator (de.fhg.igd.mongomvcc.helper.IdSetIterator)1 Index (de.fhg.igd.mongomvcc.impl.internal.Index)1 ArrayDeque (java.util.ArrayDeque)1