Search in sources :

Example 1 with CollectionInfo

use of com.torodb.torod.CollectionInfo 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());
}
Also used : CollectionInfo(com.torodb.torod.CollectionInfo) CollStatsReply(com.torodb.mongodb.commands.signatures.diagnostic.CollStatsCommand.CollStatsReply) CollectionNotFoundException(com.torodb.core.exceptions.user.CollectionNotFoundException)

Example 2 with CollectionInfo

use of com.torodb.torod.CollectionInfo in project torodb by torodb.

the class SqlTorodTransaction method getCollectionInfo.

@Override
public CollectionInfo getCollectionInfo(String dbName, String colName) throws CollectionNotFoundException {
    MetaDatabase db = getInternalTransaction().getMetaSnapshot().getMetaDatabaseByName(dbName);
    if (db == null) {
        throw new CollectionNotFoundException(dbName, colName);
    }
    MetaCollection col = db.getMetaCollectionByName(colName);
    if (col == null) {
        throw new CollectionNotFoundException(dbName, colName);
    }
    return new CollectionInfo(db.getMetaCollectionByName(colName).getName(), Json.createObjectBuilder().build());
}
Also used : MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection) CollectionInfo(com.torodb.torod.CollectionInfo) CollectionNotFoundException(com.torodb.core.exceptions.user.CollectionNotFoundException)

Aggregations

CollectionNotFoundException (com.torodb.core.exceptions.user.CollectionNotFoundException)2 CollectionInfo (com.torodb.torod.CollectionInfo)2 MetaCollection (com.torodb.core.transaction.metainf.MetaCollection)1 MetaDatabase (com.torodb.core.transaction.metainf.MetaDatabase)1 CollStatsReply (com.torodb.mongodb.commands.signatures.diagnostic.CollStatsCommand.CollStatsReply)1