Search in sources :

Example 6 with MongoDocumentStore

use of org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore in project jackrabbit-oak by apache.

the class DocumentNodeStoreHelper method getDocuments.

private static Iterable<NodeDocument> getDocuments(DocumentStore store) {
    if (store instanceof MongoDocumentStore) {
        // optimized implementation for MongoDocumentStore
        final MongoDocumentStore mds = (MongoDocumentStore) store;
        DBCollection dbCol = MongoDocumentStoreHelper.getDBCollection(mds, Collection.NODES);
        DBObject query = QueryBuilder.start(NodeDocument.HAS_BINARY_FLAG).is(NodeDocument.HAS_BINARY_VAL).get();
        DBCursor cursor = dbCol.find(query);
        return Iterables.transform(cursor, new Function<DBObject, NodeDocument>() {

            @Nullable
            @Override
            public NodeDocument apply(DBObject input) {
                return MongoDocumentStoreHelper.convertFromDBObject(mds, Collection.NODES, input);
            }
        });
    } else {
        return Utils.getSelectedDocuments(store, NodeDocument.HAS_BINARY_FLAG, NodeDocument.HAS_BINARY_VAL);
    }
}
Also used : DBCollection(com.mongodb.DBCollection) DBCursor(com.mongodb.DBCursor) MongoDocumentStore(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore) DBObject(com.mongodb.DBObject) Nullable(javax.annotation.Nullable)

Example 7 with MongoDocumentStore

use of org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore in project jackrabbit-oak by apache.

the class RepairCommand method execute.

@Override
public void execute(String... args) throws Exception {
    Closer closer = Closer.create();
    String h = "repair mongodb://host:port/database path";
    try {
        NodeStore store = Utils.bootstrapNodeStore(args, closer, h);
        if (!(store instanceof DocumentNodeStore)) {
            System.err.println("Repair only available for DocumentNodeStore");
            System.exit(1);
        }
        DocumentNodeStore dns = (DocumentNodeStore) store;
        if (!(dns.getDocumentStore() instanceof MongoDocumentStore)) {
            System.err.println("Repair only available for MongoDocumentStore");
            System.exit(1);
        }
        MongoDocumentStore docStore = (MongoDocumentStore) dns.getDocumentStore();
        String path = args[args.length - 1];
        MongoDocumentStoreHelper.repair(docStore, path);
    } catch (Throwable e) {
        throw closer.rethrow(e);
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) MongoDocumentStore(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore)

Example 8 with MongoDocumentStore

use of org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore in project jackrabbit-oak by apache.

the class RecoveryCommand method execute.

@Override
public void execute(String... args) throws Exception {
    MapFactory.setInstance(new MapDBMapFactory());
    Closer closer = Closer.create();
    String h = "recovery mongodb://host:port/database { dryRun }";
    try {
        NodeStore store = Utils.bootstrapNodeStore(args, closer, h);
        if (!(store instanceof DocumentNodeStore)) {
            System.err.println("Recovery only available for DocumentNodeStore");
            System.exit(1);
        }
        DocumentNodeStore dns = (DocumentNodeStore) store;
        if (!(dns.getDocumentStore() instanceof MongoDocumentStore)) {
            System.err.println("Recovery only available for MongoDocumentStore");
            System.exit(1);
        }
        MongoDocumentStore docStore = (MongoDocumentStore) dns.getDocumentStore();
        LastRevRecoveryAgent agent = new LastRevRecoveryAgent(dns);
        MongoMissingLastRevSeeker seeker = new MongoMissingLastRevSeeker(docStore, dns.getClock());
        CloseableIterable<NodeDocument> docs = seeker.getCandidates(0);
        closer.register(docs);
        boolean dryRun = Arrays.asList(args).contains("dryRun");
        agent.recover(docs, dns.getClusterId(), dryRun);
    } catch (Throwable e) {
        throw closer.rethrow(e);
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MapDBMapFactory(org.apache.jackrabbit.oak.plugins.document.util.MapDBMapFactory) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) LastRevRecoveryAgent(org.apache.jackrabbit.oak.plugins.document.LastRevRecoveryAgent) NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument) MongoDocumentStore(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore) MongoMissingLastRevSeeker(org.apache.jackrabbit.oak.plugins.document.mongo.MongoMissingLastRevSeeker)

Aggregations

MongoDocumentStore (org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore)8 Closer (com.google.common.io.Closer)2 DocumentMK (org.apache.jackrabbit.oak.plugins.document.DocumentMK)2 DocumentNodeStore (org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)2 DocumentStore (org.apache.jackrabbit.oak.plugins.document.DocumentStore)2 RDBDocumentStore (org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore)2 MongoConnection (org.apache.jackrabbit.oak.plugins.document.util.MongoConnection)2 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)2 DB (com.mongodb.DB)1 DBCollection (com.mongodb.DBCollection)1 DBCursor (com.mongodb.DBCursor)1 DBObject (com.mongodb.DBObject)1 MongoClientURI (com.mongodb.MongoClientURI)1 Field (java.lang.reflect.Field)1 Nullable (javax.annotation.Nullable)1 DataSource (javax.sql.DataSource)1 OptionParser (joptsimple.OptionParser)1 OptionSet (joptsimple.OptionSet)1 OptionSpec (joptsimple.OptionSpec)1 DocumentStoreException (org.apache.jackrabbit.oak.plugins.document.DocumentStoreException)1