Search in sources :

Example 1 with RDBDocumentStore

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

the class VersionGCSupportTest method fixtures.

@Parameterized.Parameters(name = "{0}")
public static java.util.Collection<Object[]> fixtures() {
    List<Object[]> fixtures = Lists.newArrayList();
    if (RDB_H2.isAvailable()) {
        RDBDocumentStore store = (RDBDocumentStore) RDB_H2.createDocumentStore();
        fixtures.add(new Object[] { RDB_H2, store, new RDBVersionGCSupport(store) });
    }
    if (MONGO.isAvailable()) {
        MongoDocumentStore store = (MongoDocumentStore) MONGO.createDocumentStore();
        fixtures.add(new Object[] { MONGO, store, new MongoVersionGCSupport(store) });
    }
    if (MEMORY.isAvailable()) {
        DocumentStore store = new MemoryDocumentStore();
        fixtures.add(new Object[] { MEMORY, store, new VersionGCSupport(store) });
    }
    return fixtures;
}
Also used : RDBDocumentStore(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore) MongoDocumentStore(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore) RDBDocumentStore(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) MongoVersionGCSupport(org.apache.jackrabbit.oak.plugins.document.mongo.MongoVersionGCSupport) RDBVersionGCSupport(org.apache.jackrabbit.oak.plugins.document.rdb.RDBVersionGCSupport) RDBVersionGCSupport(org.apache.jackrabbit.oak.plugins.document.rdb.RDBVersionGCSupport) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) MongoVersionGCSupport(org.apache.jackrabbit.oak.plugins.document.mongo.MongoVersionGCSupport) MongoDocumentStore(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore)

Example 2 with RDBDocumentStore

use of org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore 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.getMongoClient(), mongo.getDBName(), new MongoDocumentNodeStoreBuilder());
            }
        } else if (uri.startsWith("jdbc")) {
            DataSource ds = RDBDataSourceFactory.forJdbcUrl(uri, rdbjdbcuser.value(options), rdbjdbcpasswd.value(options));
            store = new RDBDocumentStore(ds, new DocumentNodeStoreBuilder());
        } 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) OptionParser(joptsimple.OptionParser) MongoDocumentStore(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore) DocumentNodeStoreBuilder(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreBuilder) MongoDocumentNodeStoreBuilder(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder) DataSource(javax.sql.DataSource) MongoDocumentNodeStoreBuilder(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder) 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 3 with RDBDocumentStore

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

the class OakFixture method getRDB.

public static OakFixture getRDB(final String name, final String jdbcuri, final String jdbcuser, final String jdbcpasswd, final String tablePrefix, final boolean dropDBAfterTest, final long cacheSize, final boolean useDataStore, final File base, final int dsCacheInMB, final int vgcMaxAge) {
    return new OakFixture(name) {

        private DocumentNodeStore[] nodeStores;

        private VersionGarbageCollectionJob versionGarbageCollectionJob = null;

        private BlobStoreFixture blobStoreFixture;

        private RDBOptions getOptions(boolean dropDBAFterTest, String tablePrefix) {
            return new RDBOptions().dropTablesOnClose(dropDBAfterTest).tablePrefix(tablePrefix);
        }

        private BlobStore getBlobStore(StatisticsProvider statsProvider) {
            try {
                if (useDataStore) {
                    initializeBlobStoreFixture(statsProvider);
                    return blobStoreFixture.setUp();
                } else {
                    DataSource ds = RDBDataSourceFactory.forJdbcUrl(jdbcuri, jdbcuser, jdbcpasswd);
                    return new RDBBlobStore(ds, getOptions(dropDBAfterTest, tablePrefix));
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public Oak getOak(int clusterId) throws Exception {
            DataSource ds = RDBDataSourceFactory.forJdbcUrl(jdbcuri, jdbcuser, jdbcpasswd);
            DocumentNodeStoreBuilder<?> builder = newRDBDocumentNodeStoreBuilder().setRDBConnection(ds, getOptions(dropDBAfterTest, tablePrefix)).memoryCacheSize(cacheSize).setClusterId(clusterId).setLogging(false);
            BlobStore blobStore = getBlobStore(StatisticsProvider.NOOP);
            if (blobStore != null) {
                builder.setBlobStore(blobStore);
            }
            return newOak(builder.build());
        }

        @Override
        public Oak[] setUpCluster(int n, StatisticsProvider statsProvider) throws Exception {
            Oak[] cluster = new Oak[n];
            nodeStores = new DocumentNodeStore[cluster.length];
            for (int i = 0; i < cluster.length; i++) {
                BlobStore blobStore = getBlobStore(statsProvider);
                DataSource ds = RDBDataSourceFactory.forJdbcUrl(jdbcuri, jdbcuser, jdbcpasswd);
                DocumentNodeStoreBuilder<?> builder = newRDBDocumentNodeStoreBuilder().setRDBConnection(ds, getOptions(dropDBAfterTest, tablePrefix)).memoryCacheSize(cacheSize).setStatisticsProvider(statsProvider).setLeaseCheck(false).setClusterId(i + 1).setLogging(false);
                if (blobStore != null) {
                    builder.setBlobStore(blobStore);
                }
                nodeStores[i] = builder.build();
                cluster[i] = newOak(nodeStores[i]);
            }
            if (vgcMaxAge > 0 && nodeStores.length >= 1) {
                versionGarbageCollectionJob = new VersionGarbageCollectionJob(nodeStores[0], vgcMaxAge);
                Thread t = new Thread(versionGarbageCollectionJob);
                t.setDaemon(true);
                t.start();
            }
            return cluster;
        }

        @Override
        public void tearDownCluster() {
            String dropped = "";
            if (versionGarbageCollectionJob != null) {
                versionGarbageCollectionJob.stop();
            }
            for (DocumentNodeStore ns : nodeStores) {
                ns.dispose();
                if (ns.getDocumentStore() instanceof RDBDocumentStore) {
                    dropped += ((RDBDocumentStore) ns.getDocumentStore()).getDroppedTables();
                }
            }
            if (dropDBAfterTest) {
                if (blobStoreFixture != null) {
                    blobStoreFixture.tearDown();
                }
                if (dropped.isEmpty()) {
                    throw new RuntimeException("dropdb was set, but tables have not been dropped");
                }
            }
        }

        private void initializeBlobStoreFixture(StatisticsProvider statsProvider) {
            if (useDataStore && blobStoreFixture == null) {
                blobStoreFixture = BlobStoreFixture.create(base, true, dsCacheInMB, statsProvider);
            }
        }
    };
}
Also used : DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) StatisticsProvider(org.apache.jackrabbit.oak.stats.StatisticsProvider) RDBOptions(org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions) UnknownHostException(java.net.UnknownHostException) DataSource(javax.sql.DataSource) RDBDocumentStore(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore) Oak(org.apache.jackrabbit.oak.Oak) RDBBlobStore(org.apache.jackrabbit.oak.plugins.document.rdb.RDBBlobStore) RDBBlobStore(org.apache.jackrabbit.oak.plugins.document.rdb.RDBBlobStore) BlobStore(org.apache.jackrabbit.oak.spi.blob.BlobStore)

Example 4 with RDBDocumentStore

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

the class DocumentFixtureProvider method configureDocumentMk.

static DocumentNodeStore configureDocumentMk(Options options, BlobStore blobStore, Whiteboard wb, Closer closer, boolean readOnly) throws IOException {
    CommonOptions commonOpts = options.getOptionBean(CommonOptions.class);
    DocumentNodeStoreBuilder<?> builder;
    if (commonOpts.isMongo()) {
        builder = newMongoDocumentNodeStoreBuilder();
    } else if (commonOpts.isRDB()) {
        builder = newRDBDocumentNodeStoreBuilder();
    } else {
        throw new IllegalStateException("Unknown DocumentStore");
    }
    StatisticsProvider statisticsProvider = checkNotNull(getService(wb, StatisticsProvider.class));
    DocumentBuilderCustomizer customizer = getService(wb, DocumentBuilderCustomizer.class);
    if (customizer != null) {
        customizer.customize(builder);
    }
    if (blobStore != null) {
        builder.setBlobStore(blobStore);
    }
    DocumentNodeStoreOptions docStoreOpts = options.getOptionBean(DocumentNodeStoreOptions.class);
    builder.setClusterId(docStoreOpts.getClusterId());
    builder.setStatisticsProvider(statisticsProvider);
    if (readOnly) {
        builder.setReadOnlyMode();
    }
    int cacheSize = docStoreOpts.getCacheSize();
    if (cacheSize != 0) {
        builder.memoryCacheSize(cacheSize * FileUtils.ONE_MB);
    }
    if (docStoreOpts.disableBranchesSpec()) {
        builder.disableBranches();
    }
    if (docStoreOpts.isCacheDistributionDefined()) {
        builder.memoryCacheDistribution(docStoreOpts.getNodeCachePercentage(), docStoreOpts.getPrevDocCachePercentage(), docStoreOpts.getChildrenCachePercentage(), docStoreOpts.getDiffCachePercentage());
    }
    DocumentNodeStore dns;
    if (commonOpts.isMongo()) {
        MongoClientURI uri = new MongoClientURI(commonOpts.getStoreArg());
        if (uri.getDatabase() == null) {
            System.err.println("Database missing in MongoDB URI: " + uri.getURI());
            System.exit(1);
        }
        MongoConnection mongo = new MongoConnection(uri.getURI());
        wb.register(MongoConnection.class, mongo, emptyMap());
        closer.register(mongo::close);
        ((MongoDocumentNodeStoreBuilder) builder).setMongoDB(mongo.getDB());
        dns = builder.build();
        wb.register(MongoDocumentStore.class, (MongoDocumentStore) builder.getDocumentStore(), emptyMap());
    } else if (commonOpts.isRDB()) {
        RDBStoreOptions rdbOpts = options.getOptionBean(RDBStoreOptions.class);
        DataSource ds = RDBDataSourceFactory.forJdbcUrl(commonOpts.getStoreArg(), rdbOpts.getUser(), rdbOpts.getPassword());
        wb.register(DataSource.class, ds, emptyMap());
        ((RDBDocumentNodeStoreBuilder) builder).setRDBConnection(ds);
        dns = builder.build();
        wb.register(RDBDocumentStore.class, (RDBDocumentStore) builder.getDocumentStore(), emptyMap());
    } else {
        throw new IllegalStateException("Unknown DocumentStore");
    }
    closer.register(dns::dispose);
    return dns;
}
Also used : MongoClientURI(com.mongodb.MongoClientURI) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) StatisticsProvider(org.apache.jackrabbit.oak.stats.StatisticsProvider) DataSource(javax.sql.DataSource) MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder) MongoDocumentNodeStoreBuilder(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder) RDBDocumentStore(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection)

Aggregations

RDBDocumentStore (org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore)4 DataSource (javax.sql.DataSource)3 MongoClientURI (com.mongodb.MongoClientURI)2 DocumentNodeStore (org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)2 MongoDocumentNodeStoreBuilder (org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder)2 MongoDocumentStore (org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore)2 MongoConnection (org.apache.jackrabbit.oak.plugins.document.util.MongoConnection)2 StatisticsProvider (org.apache.jackrabbit.oak.stats.StatisticsProvider)2 UnknownHostException (java.net.UnknownHostException)1 OptionParser (joptsimple.OptionParser)1 OptionSet (joptsimple.OptionSet)1 OptionSpec (joptsimple.OptionSpec)1 Oak (org.apache.jackrabbit.oak.Oak)1 DocumentNodeStoreBuilder (org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreBuilder)1 DocumentStore (org.apache.jackrabbit.oak.plugins.document.DocumentStore)1 DocumentStoreException (org.apache.jackrabbit.oak.plugins.document.DocumentStoreException)1 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)1 MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder (org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder)1 MongoVersionGCSupport (org.apache.jackrabbit.oak.plugins.document.mongo.MongoVersionGCSupport)1 RDBBlobStore (org.apache.jackrabbit.oak.plugins.document.rdb.RDBBlobStore)1