Search in sources :

Example 6 with DocumentStore

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

the class UnlockUpgradeCommand method execute.

@Override
public void execute(String... args) throws Exception {
    OptionParser parser = new OptionParser();
    // RDB specific options
    OptionSpec<String> rdbjdbcuser = parser.accepts("rdbjdbcuser", "RDB JDBC user").withOptionalArg().defaultsTo("");
    OptionSpec<String> rdbjdbcpasswd = parser.accepts("rdbjdbcpasswd", "RDB JDBC password").withOptionalArg().defaultsTo("");
    OptionSpec<String> nonOption = parser.nonOptions("unlockUpgrade {<jdbc-uri> | <mongodb-uri>}");
    OptionSpec help = parser.acceptsAll(asList("h", "?", "help"), "show help").forHelp();
    OptionSet options = parser.parse(args);
    List<String> nonOptions = nonOption.values(options);
    if (options.has(help)) {
        parser.printHelpOn(System.out);
        return;
    }
    if (nonOptions.isEmpty()) {
        parser.printHelpOn(System.err);
        return;
    }
    DocumentStore store = null;
    try {
        String uri = nonOptions.get(0);
        if (uri.startsWith(MONGODB_PREFIX)) {
            MongoClientURI clientURI = new MongoClientURI(uri);
            if (clientURI.getDatabase() == null) {
                System.err.println("Database missing in MongoDB URI: " + clientURI.getURI());
            } else {
                MongoConnection mongo = new MongoConnection(clientURI.getURI());
                store = new MongoDocumentStore(mongo.getDB(), new DocumentMK.Builder());
            }
        } else if (uri.startsWith("jdbc")) {
            DataSource ds = RDBDataSourceFactory.forJdbcUrl(uri, rdbjdbcuser.value(options), rdbjdbcpasswd.value(options));
            store = new RDBDocumentStore(ds, new DocumentMK.Builder());
        } else {
            System.err.println("Unrecognized URI: " + uri);
        }
        if (store != null && VERSION.writeTo(store)) {
            System.out.println("Format version set to " + VERSION);
        }
    } catch (DocumentStoreException e) {
        System.err.println(e.getMessage());
    } finally {
        if (store != null) {
            store.dispose();
        }
    }
}
Also used : OptionSpec(joptsimple.OptionSpec) DocumentStoreException(org.apache.jackrabbit.oak.plugins.document.DocumentStoreException) MongoClientURI(com.mongodb.MongoClientURI) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) OptionParser(joptsimple.OptionParser) MongoDocumentStore(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore) DataSource(javax.sql.DataSource) DocumentStore(org.apache.jackrabbit.oak.plugins.document.DocumentStore) MongoDocumentStore(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore) RDBDocumentStore(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore) RDBDocumentStore(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore) OptionSet(joptsimple.OptionSet) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection)

Example 7 with DocumentStore

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

the class UnlockUpgradeCommandTest method resetFormatVersion.

private void resetFormatVersion(FormatVersion v) {
    MongoConnection c = connectionFactory.getConnection();
    DocumentStore s = new MongoDocumentStore(c.getDB(), new DocumentMK.Builder());
    s.remove(Collection.SETTINGS, "version");
    assertTrue(v.writeTo(s));
    s.dispose();
}
Also used : DocumentStore(org.apache.jackrabbit.oak.plugins.document.DocumentStore) MongoDocumentStore(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection) MongoDocumentStore(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore)

Example 8 with DocumentStore

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

the class RevisionsCommandTest method sweep.

@Test
public void sweep() throws Exception {
    int clusterId = ns.getClusterId();
    String output = captureSystemErr(new Sweep(clusterId));
    assertThat(output, containsString("cannot sweep revisions for active clusterId"));
    output = captureSystemErr(new Sweep(0));
    assertThat(output, containsString("clusterId option is required"));
    output = captureSystemErr(new Sweep(99));
    assertThat(output, containsString("store does not have changes with clusterId"));
    ns.dispose();
    output = captureSystemOut(new Sweep(clusterId));
    assertThat(output, containsString("Revision sweep not needed for clusterId"));
    // remove the sweep revision to force a sweep run
    MongoConnection c = connectionFactory.getConnection();
    DocumentMK.Builder builder = builderProvider.newBuilder().setMongoDB(c.getDB());
    DocumentStore store = builder.getDocumentStore();
    UpdateOp op = new UpdateOp(getIdFromPath("/"), false);
    op.removeMapEntry("_sweepRev", new Revision(0, 0, clusterId));
    assertNotNull(store.findAndUpdate(Collection.NODES, op));
    output = captureSystemOut(new Sweep(clusterId));
    assertThat(output, containsString("Updated sweep revision to"));
}
Also used : DocumentStore(org.apache.jackrabbit.oak.plugins.document.DocumentStore) Revision(org.apache.jackrabbit.oak.plugins.document.Revision) UpdateOp(org.apache.jackrabbit.oak.plugins.document.UpdateOp) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection) Test(org.junit.Test)

Example 9 with DocumentStore

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

the class RevisionsCommand method sweep.

private void sweep(RevisionsOptions options, Closer closer) throws IOException {
    int clusterId = options.getClusterId();
    if (clusterId <= 0) {
        System.err.println("clusterId option is required for " + RevisionsOptions.CMD_SWEEP + " command");
        return;
    }
    DocumentMK.Builder builder = createDocumentMKBuilder(options, closer);
    if (builder == null) {
        System.err.println("revisions mode only available for DocumentNodeStore");
        return;
    }
    DocumentStore store = builder.getDocumentStore();
    // cluster node must be inactive
    for (ClusterNodeInfoDocument doc : ClusterNodeInfoDocument.all(store)) {
        if (doc.getClusterId() == clusterId && doc.isActive()) {
            System.err.println("cannot sweep revisions for active " + "clusterId " + clusterId);
            return;
        }
    }
    // the root document must have a _lastRev entry for the clusterId
    if (!getRootDocument(store).getLastRev().containsKey(clusterId)) {
        System.err.println("store does not have changes with " + "clusterId " + clusterId);
        return;
    }
    builder.setReadOnlyMode();
    DocumentNodeStore ns = builder.getNodeStore();
    closer.register(asCloseable(ns));
    MissingLastRevSeeker seeker = builder.createMissingLastRevSeeker();
    SweepHelper.sweep(store, new RevisionContextWrapper(ns, clusterId), seeker);
}
Also used : ClusterNodeInfoDocument(org.apache.jackrabbit.oak.plugins.document.ClusterNodeInfoDocument) DocumentStore(org.apache.jackrabbit.oak.plugins.document.DocumentStore) RevisionContextWrapper(org.apache.jackrabbit.oak.plugins.document.RevisionContextWrapper) MissingLastRevSeeker(org.apache.jackrabbit.oak.plugins.document.MissingLastRevSeeker) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)

Aggregations

DocumentStore (org.apache.jackrabbit.oak.plugins.document.DocumentStore)9 DocumentMK (org.apache.jackrabbit.oak.plugins.document.DocumentMK)5 Test (org.junit.Test)5 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)4 DocumentNodeStore (org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)3 MongoConnection (org.apache.jackrabbit.oak.plugins.document.util.MongoConnection)3 UpdateOp (org.apache.jackrabbit.oak.plugins.document.UpdateOp)2 MongoDocumentStore (org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore)2 Fongo (com.github.fakemongo.Fongo)1 BulkWriteResult (com.mongodb.BulkWriteResult)1 DBObject (com.mongodb.DBObject)1 MongoClientURI (com.mongodb.MongoClientURI)1 MongoException (com.mongodb.MongoException)1 OakFongo (com.mongodb.OakFongo)1 WriteConcern (com.mongodb.WriteConcern)1 WriteResult (com.mongodb.WriteResult)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 List (java.util.List)1 DataSource (javax.sql.DataSource)1