use of com.mongodb.BasicDBObject in project mongomvcc by igd-geo.
the class Tree method getChildren.
@Override
public long[] getChildren(long cid) {
if (cid != 0 && !existsCommit(cid)) {
throw new VException("Unknown commit: " + cid);
}
DBCursor c = _commits.find(new BasicDBObject(PARENT_CID, cid), new BasicDBObject(MongoDBConstants.ID, 1));
long[] r = new long[c.count()];
int i = 0;
for (DBObject o : c) {
r[i++] = (Long) o.get(MongoDBConstants.ID);
}
return r;
}
use of com.mongodb.BasicDBObject in project mongomvcc by igd-geo.
the class DefaultConvertStrategy method convert.
@Override
public Object convert(long oid) throws IOException {
GridFSDBFile file = _gridFS.findOne(new BasicDBObject(MongoDBVLargeCollection.OID, oid));
if (file == null) {
return null;
}
int type = (Integer) file.get(BINARY_TYPE);
Object r;
if (type == BYTEARRAY) {
r = toByteArray(file);
} else if (type == INPUTSTREAM) {
r = file.getInputStream();
} else if (type == BYTEBUFFER) {
r = ByteBuffer.wrap(toByteArray(file));
} else if (type == FLOATARRAY) {
r = toFloatArray(file);
} else if (type == FLOATBUFFER) {
r = FloatBuffer.wrap(toFloatArray(file));
} else {
//no information. simply forward the input stream
r = file.getInputStream();
}
return r;
}
use of com.mongodb.BasicDBObject in project mongomvcc by igd-geo.
the class MongoDBVDatabaseBenchmark method plainOldInsertDelete.
/**
* Inserts a lot of documents using plain old MongoDB and then deletes them
*/
@Test
@BenchmarkOptions(benchmarkRounds = 2, warmupRounds = 1)
public void plainOldInsertDelete() {
plainOldInsert();
DBCollection coll = _db.getCollection("persons");
for (long i = 0; i < DOCUMENTS; ++i) {
coll.remove(new BasicDBObject("_id", 1 + i));
}
}
use of com.mongodb.BasicDBObject 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.BasicDBObject 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;
}
Aggregations