use of com.torodb.mongodb.commands.signatures.diagnostic.CollStatsCommand.CollStatsReply in project torodb by torodb.
the class CollStatsImplementation method apply.
@Override
public Status<CollStatsReply> apply(Request req, Command<? super CollStatsArgument, ? super CollStatsReply> command, CollStatsArgument arg, MongodTransaction context) {
String collection = arg.getCollection();
CollStatsReply.Builder replyBuilder = new CollStatsReply.Builder(req.getDatabase(), collection);
if (NamespaceUtil.isSystem(collection)) {
//TODO (matteom): support stats on system collections
LOGGER.warn("Requested stats on the system collection " + collection + ". ToroDB does not support stats for system " + "collections yet");
Stream<CollectionInfo> collectionsInfo = context.getTorodTransaction().getCollectionsInfo(req.getDatabase());
replyBuilder.setCount(collectionsInfo.count()).setSize(0).setStorageSize(0).setCustomStorageStats(null).setIndexDetails(DefaultBsonValues.EMPTY_DOC).setScale(arg.getScale()).setSizeByIndex(Collections.<String, Number>emptyMap()).setCapped(false);
} else {
try {
CollectionInfo collectionInfo = context.getTorodTransaction().getCollectionInfo(req.getDatabase(), arg.getCollection());
if (collectionInfo.isCapped()) {
replyBuilder.setCapped(true).setMaxIfCapped(collectionInfo.getMaxIfCapped());
} else {
replyBuilder.setCapped(false);
}
} catch (CollectionNotFoundException e) {
//Nothing to do if the collection does not exist
}
replyBuilder.setCapped(false).setScale(arg.getScale());
int scale = replyBuilder.getScale();
//TODO (matteom): add index stats
Collection<? extends NamedToroIndex> indexes = ImmutableList.of();
Map<String, Long> sizeByMap = Maps.newHashMapWithExpectedSize(indexes.size());
replyBuilder.setSizeByIndex(sizeByMap);
replyBuilder.setCount(context.getTorodTransaction().countAll(req.getDatabase(), collection));
replyBuilder.setSize(context.getTorodTransaction().getDocumentsSize(req.getDatabase(), collection) / scale);
replyBuilder.setStorageSize(context.getTorodTransaction().getCollectionSize(req.getDatabase(), collection) / scale);
}
return Status.ok(replyBuilder.build());
}
Aggregations