use of com.mongodb.DBCollection 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 com.mongodb.DBCollection in project mongomvcc by igd-geo.
the class MongoDBVMaintenance method pruneUnreferencedDocuments.
@Override
public long pruneUnreferencedDocuments(String collection, long expiry, TimeUnit unit) {
long[] oids = findUnreferencedDocuments(collection, expiry, unit);
DBCollection coll = _db.getDB().getCollection(collection);
//delete documents in chunks, so we avoid sending an array that is
//larger than the maximum document size
final int sliceCount = 1000;
for (int i = 0; i < oids.length; i += sliceCount) {
int maxSliceCount = Math.min(sliceCount, oids.length - i);
long[] slice = new long[maxSliceCount];
System.arraycopy(oids, i, slice, 0, maxSliceCount);
coll.remove(new BasicDBObject(MongoDBConstants.ID, new BasicDBObject("$in", slice)));
}
return oids.length;
}
use of com.mongodb.DBCollection in project mongomvcc by igd-geo.
the class MongoDBVMaintenance method pruneDanglingCommits.
@Override
public long pruneDanglingCommits(long expiry, TimeUnit unit) {
long[] cids = findDanglingCommits(expiry, unit);
DBCollection collCommits = _db.getDB().getCollection(MongoDBConstants.COLLECTION_COMMITS);
//delete commits in chunks, so we avoid sending an array that is
//larger than the maximum document size
final int sliceCount = 1000;
for (int i = 0; i < cids.length; i += sliceCount) {
int maxSliceCount = Math.min(sliceCount, cids.length - i);
long[] slice = new long[maxSliceCount];
System.arraycopy(cids, i, slice, 0, maxSliceCount);
collCommits.remove(new BasicDBObject(MongoDBConstants.ID, new BasicDBObject("$in", slice)));
}
return cids.length;
}
use of com.mongodb.DBCollection in project mongo-hadoop by mongodb.
the class GridFSInputFormat method getSplits.
@Override
public List<InputSplit> getSplits(final JobContext context) throws IOException, InterruptedException {
Configuration conf = context.getConfiguration();
DBCollection inputCollection = MongoConfigUtil.getInputCollection(conf);
MongoClientURI inputURI = MongoConfigUtil.getInputURI(conf);
GridFS gridFS = new GridFS(inputCollection.getDB(), inputCollection.getName());
DBObject query = MongoConfigUtil.getQuery(conf);
List<InputSplit> splits = new LinkedList<InputSplit>();
for (GridFSDBFile file : gridFS.find(query)) {
// One split per file.
if (MongoConfigUtil.isGridFSWholeFileSplit(conf)) {
splits.add(new GridFSSplit(inputURI, (ObjectId) file.getId(), (int) file.getChunkSize(), file.getLength()));
} else // One split per file chunk.
{
for (int chunk = 0; chunk < file.numChunks(); ++chunk) {
splits.add(new GridFSSplit(inputURI, (ObjectId) file.getId(), (int) file.getChunkSize(), file.getLength(), chunk));
}
}
}
LOG.debug("Found GridFS splits: " + splits);
return splits;
}
use of com.mongodb.DBCollection in project mongo-hadoop by mongodb.
the class GridFSSplit method getGridFS.
private GridFS getGridFS() {
if (null == gridFS) {
DBCollection rootCollection = MongoConfigUtil.getCollection(inputURI);
gridFS = new GridFS(rootCollection.getDB(), rootCollection.getName());
}
return gridFS;
}
Aggregations