Search in sources :

Example 6 with DocumentNodeStore

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

the class ReadOnlyDocumentStoreWrapperTest method backgroundRead.

@Test
public void backgroundRead() throws Exception {
    DocumentStore docStore = new MemoryDocumentStore();
    DocumentNodeStore store = builderProvider.newBuilder().setAsyncDelay(0).setDocumentStore(docStore).setClusterId(2).getNodeStore();
    DocumentNodeStore readOnlyStore = builderProvider.newBuilder().setAsyncDelay(0).setDocumentStore(docStore).setClusterId(1).setReadOnlyMode().getNodeStore();
    NodeBuilder builder = store.getRoot().builder();
    builder.child("node");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    store.runBackgroundOperations();
    // at this point node must not be visible
    assertFalse(readOnlyStore.getRoot().hasChildNode("node"));
    readOnlyStore.runBackgroundOperations();
    // at this point node should get visible
    assertTrue(readOnlyStore.getRoot().hasChildNode("node"));
}
Also used : DocumentStore(org.apache.jackrabbit.oak.plugins.document.DocumentStore) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 7 with DocumentNodeStore

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

the class UtilsTest method getAllDocuments.

@Test
public void getAllDocuments() throws CommitFailedException {
    DocumentNodeStore store = new DocumentMK.Builder().getNodeStore();
    try {
        NodeBuilder builder = store.getRoot().builder();
        for (int i = 0; i < 1000; i++) {
            builder.child("test-" + i);
        }
        store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
        assertEquals(1001, /* root + 1000 children */
        Iterables.size(Utils.getAllDocuments(store.getDocumentStore())));
    } finally {
        store.dispose();
    }
}
Also used : DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 8 with DocumentNodeStore

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

the class TextExtractorMain method bootStrapNodeStore.

private static NodeStore bootStrapNodeStore(String src, BlobStore blobStore, Closer closer) throws IOException {
    if (src.startsWith(MongoURI.MONGODB_PREFIX)) {
        MongoClientURI uri = new MongoClientURI(src);
        if (uri.getDatabase() == null) {
            System.err.println("Database missing in MongoDB URI: " + uri.getURI());
            System.exit(1);
        }
        MongoConnection mongo = new MongoConnection(uri.getURI());
        closer.register(asCloseable(mongo));
        DocumentNodeStore store = new DocumentMK.Builder().setBlobStore(blobStore).setMongoDB(mongo.getDB()).getNodeStore();
        closer.register(asCloseable(store));
        return store;
    }
    return SegmentTarUtils.bootstrap(src, blobStore, closer);
}
Also used : MongoClientURI(com.mongodb.MongoClientURI) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection)

Example 9 with DocumentNodeStore

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

the class DataStoreCheckCommand method execute.

@Override
public void execute(String... args) throws Exception {
    OptionParser parser = new OptionParser();
    parser.allowsUnrecognizedOptions();
    String helpStr = "datastorecheck [--id] [--ref] [--consistency] [--store <path>|<mongo_uri>] " + "[--s3ds <s3ds_config>|--fds <fds_config>|--azureblobds <azureblobds_config>] [--dump <path>]";
    Closer closer = Closer.create();
    try {
        // Options for operations requested
        OptionSpecBuilder idOp = parser.accepts("id", "Get ids");
        OptionSpecBuilder refOp = parser.accepts("ref", "Get references");
        OptionSpecBuilder consistencyOp = parser.accepts("consistency", "Check consistency");
        // Node Store - needed for --ref, --consistency
        ArgumentAcceptingOptionSpec<String> store = parser.accepts("store", "Node Store").requiredIf(refOp, consistencyOp).withRequiredArg().ofType(String.class);
        // Optional argument to specify the dump path
        ArgumentAcceptingOptionSpec<String> dump = parser.accepts("dump", "Dump Path").withRequiredArg().ofType(String.class);
        // Optional argument to specify tracking
        ArgumentAcceptingOptionSpec<String> track = parser.accepts("track", "Local repository home folder").withRequiredArg().ofType(String.class);
        OptionSpec<?> help = parser.acceptsAll(asList("h", "?", "help"), "show help").forHelp();
        // Required rules (any one of --id, --ref, --consistency)
        idOp.requiredUnless(refOp, consistencyOp);
        refOp.requiredUnless(idOp, consistencyOp);
        consistencyOp.requiredUnless(idOp, refOp);
        OptionSet options = null;
        try {
            options = parser.parse(args);
        } catch (Exception e) {
            System.err.println(e);
            parser.printHelpOn(System.err);
            return;
        }
        if (options.has(help)) {
            parser.printHelpOn(System.out);
            return;
        }
        String dumpPath = JAVA_IO_TMPDIR.value();
        if (options.has(dump)) {
            dumpPath = options.valueOf(dump);
        }
        GarbageCollectableBlobStore blobStore = null;
        BlobReferenceRetriever marker = null;
        if (options.has(store)) {
            String source = options.valueOf(store);
            if (source.startsWith(MongoURI.MONGODB_PREFIX)) {
                MongoClientURI uri = new MongoClientURI(source);
                MongoClient client = new MongoClient(uri);
                DocumentNodeStore nodeStore = new DocumentMK.Builder().setMongoDB(client.getDB(uri.getDatabase())).getNodeStore();
                closer.register(Utils.asCloseable(nodeStore));
                blobStore = (GarbageCollectableBlobStore) nodeStore.getBlobStore();
                marker = new DocumentBlobReferenceRetriever(nodeStore);
            } else {
                marker = SegmentTarUtils.newBlobReferenceRetriever(source, closer);
            }
        }
        // Initialize S3/FileDataStore if configured
        GarbageCollectableBlobStore dataStore = Utils.bootstrapDataStore(args, closer);
        if (dataStore != null) {
            blobStore = dataStore;
        }
        // blob store still not initialized means configuration not supported
        if (blobStore == null) {
            System.err.println("Operation not defined for SegmentNodeStore without external datastore");
            parser.printHelpOn(System.err);
            return;
        }
        FileRegister register = new FileRegister(options);
        closer.register(register);
        if (options.has(idOp) || options.has(consistencyOp)) {
            File dumpFile = register.createFile(idOp, dumpPath);
            retrieveBlobIds(blobStore, dumpFile);
            // If track path specified copy the file to the location
            if (options.has(track)) {
                String trackPath = options.valueOf(track);
                File trackingFileParent = new File(FilenameUtils.concat(trackPath, "blobids"));
                File trackingFile = new File(trackingFileParent, "blob-" + String.valueOf(System.currentTimeMillis()) + ".gen");
                FileUtils.copyFile(dumpFile, trackingFile);
            }
        }
        if (options.has(refOp) || options.has(consistencyOp)) {
            retrieveBlobReferences(blobStore, marker, register.createFile(refOp, dumpPath));
        }
        if (options.has(consistencyOp)) {
            checkConsistency(register.get(idOp), register.get(refOp), register.createFile(consistencyOp, dumpPath));
        }
    } catch (Throwable t) {
        t.printStackTrace();
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer) MongoClientURI(com.mongodb.MongoClientURI) OptionSpecBuilder(joptsimple.OptionSpecBuilder) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) OptionParser(joptsimple.OptionParser) IOException(java.io.IOException) MongoClient(com.mongodb.MongoClient) OptionSpecBuilder(joptsimple.OptionSpecBuilder) DocumentBlobReferenceRetriever(org.apache.jackrabbit.oak.plugins.document.DocumentBlobReferenceRetriever) BlobReferenceRetriever(org.apache.jackrabbit.oak.plugins.blob.BlobReferenceRetriever) GarbageCollectableBlobStore(org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore) OptionSet(joptsimple.OptionSet) DocumentBlobReferenceRetriever(org.apache.jackrabbit.oak.plugins.document.DocumentBlobReferenceRetriever) File(java.io.File)

Example 10 with DocumentNodeStore

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

the class SameNodeSiblingsTest method migrate.

private DocumentNodeStore migrate(SourceDataCreator sourceDataCreator) throws RepositoryException, IOException {
    RepositoryConfig config = RepositoryConfig.install(crx2RepoDir);
    RepositoryImpl repository = RepositoryImpl.create(config);
    try {
        Session session = repository.login(CREDENTIALS);
        sourceDataCreator.create(session);
        session.logout();
    } finally {
        repository.shutdown();
    }
    // re-create the config
    config = RepositoryConfig.install(crx2RepoDir);
    RepositoryContext context = RepositoryContext.create(config);
    DocumentNodeStore target = new DocumentMK.Builder().getNodeStore();
    try {
        RepositoryUpgrade upgrade = new RepositoryUpgrade(context, target);
        upgrade.copy(null);
    } finally {
        context.getRepository().shutdown();
    }
    return target;
}
Also used : RepositoryConfig(org.apache.jackrabbit.core.config.RepositoryConfig) RepositoryContext(org.apache.jackrabbit.core.RepositoryContext) RepositoryImpl(org.apache.jackrabbit.core.RepositoryImpl) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) Session(javax.jcr.Session)

Aggregations

DocumentNodeStore (org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)32 Test (org.junit.Test)13 DocumentMK (org.apache.jackrabbit.oak.plugins.document.DocumentMK)12 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)8 Closer (com.google.common.io.Closer)6 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)6 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)5 MongoClientURI (com.mongodb.MongoClientURI)4 RepositoryException (javax.jcr.RepositoryException)4 Session (javax.jcr.Session)4 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)4 MongoClient (com.mongodb.MongoClient)3 Node (javax.jcr.Node)3 OptionParser (joptsimple.OptionParser)3 OptionSet (joptsimple.OptionSet)3 DocumentStore (org.apache.jackrabbit.oak.plugins.document.DocumentStore)3 AssumptionViolatedException (org.junit.AssumptionViolatedException)3 DB (com.mongodb.DB)2 File (java.io.File)2 UnknownHostException (java.net.UnknownHostException)2