Search in sources :

Example 91 with NodeStore

use of org.apache.jackrabbit.oak.spi.state.NodeStore in project jackrabbit-oak by apache.

the class CompositeNodeStore method merge.

@Override
public NodeState merge(NodeBuilder builder, CommitHook commitHook, CommitInfo info) throws CommitFailedException {
    checkArgument(builder instanceof CompositeNodeBuilder);
    CompositeNodeBuilder nodeBuilder = (CompositeNodeBuilder) builder;
    if (!PathUtils.denotesRoot(nodeBuilder.getPath())) {
        throw new IllegalArgumentException();
    }
    // run commit hooks and apply the changes to the builder instance
    NodeState processed = commitHook.processCommit(getRoot(), rebase(nodeBuilder), info);
    processed.compareAgainstBaseState(builder.getNodeState(), new ApplyDiff(nodeBuilder));
    assertNoChangesOnReadOnlyMounts(nodeBuilder);
    // apply the accumulated changes on individual NodeStore instances
    Map<MountedNodeStore, NodeState> resultStates = newHashMap();
    for (MountedNodeStore mountedNodeStore : ctx.getAllMountedNodeStores()) {
        NodeStore nodeStore = mountedNodeStore.getNodeStore();
        NodeBuilder partialBuilder = nodeBuilder.getBuilders().get(mountedNodeStore);
        NodeState result = nodeStore.merge(partialBuilder, EmptyHook.INSTANCE, info);
        resultStates.put(mountedNodeStore, result);
    }
    CompositeNodeState newRoot = createRootNodeState(resultStates);
    for (Observer observer : observers) {
        observer.contentChanged(newRoot, info);
    }
    return newRoot;
}
Also used : ApplyDiff(org.apache.jackrabbit.oak.spi.state.ApplyDiff) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) Observer(org.apache.jackrabbit.oak.spi.commit.Observer) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 92 with NodeStore

use of org.apache.jackrabbit.oak.spi.state.NodeStore in project jackrabbit-oak by apache.

the class ResetClusterIdCommand method execute.

@Override
public void execute(String... args) throws Exception {
    OptionParser parser = new OptionParser();
    OptionSet options = parser.parse(args);
    if (options.nonOptionArguments().isEmpty()) {
        System.out.println("usage: resetclusterid {<path>|<mongo-uri>}");
        System.exit(1);
    }
    String source = options.nonOptionArguments().get(0).toString();
    Closer closer = Closer.create();
    try {
        NodeStore store;
        if (args[0].startsWith(MongoURI.MONGODB_PREFIX)) {
            MongoClientURI uri = new MongoClientURI(source);
            MongoClient client = new MongoClient(uri);
            final DocumentNodeStore dns = new DocumentMK.Builder().setMongoDB(client.getDB(uri.getDatabase())).getNodeStore();
            closer.register(Utils.asCloseable(dns));
            store = dns;
        } else {
            store = SegmentTarUtils.bootstrapNodeStore(source, closer);
        }
        deleteClusterId(store);
    } catch (Throwable e) {
        throw closer.rethrow(e);
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer) MongoClient(com.mongodb.MongoClient) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MongoClientURI(com.mongodb.MongoClientURI) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 93 with NodeStore

use of org.apache.jackrabbit.oak.spi.state.NodeStore 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 94 with NodeStore

use of org.apache.jackrabbit.oak.spi.state.NodeStore in project jackrabbit-oak by apache.

the class NodeStoreFixtureProvider method configureSegment.

private static NodeStore configureSegment(Options options, BlobStore blobStore, StatisticsProvider statisticsProvider, Closer closer, boolean readOnly) throws IOException, InvalidFileStoreVersionException {
    String path = options.getOptionBean(CommonOptions.class).getStoreArg();
    FileStoreBuilder builder = fileStoreBuilder(new File(path)).withMaxFileSize(256);
    if (blobStore != null) {
        builder.withBlobStore(blobStore);
    }
    NodeStore nodeStore;
    if (readOnly) {
        ReadOnlyFileStore fileStore = builder.withStatisticsProvider(statisticsProvider).buildReadOnly();
        closer.register(fileStore);
        nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
    } else {
        FileStore fileStore = builder.withStatisticsProvider(statisticsProvider).build();
        closer.register(fileStore);
        nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
    }
    return nodeStore;
}
Also used : ReadOnlyFileStore(org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) FileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder) ReadOnlyFileStore(org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore) File(java.io.File)

Example 95 with NodeStore

use of org.apache.jackrabbit.oak.spi.state.NodeStore 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

NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)141 Test (org.junit.Test)81 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)58 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)52 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)29 Blob (org.apache.jackrabbit.oak.api.Blob)24 Before (org.junit.Before)18 FileInputStream (java.io.FileInputStream)16 Hex.encodeHexString (org.apache.commons.codec.binary.Hex.encodeHexString)16 File (java.io.File)14 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)14 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)14 ProxyNodeStore (org.apache.jackrabbit.oak.spi.state.ProxyNodeStore)13 Oak (org.apache.jackrabbit.oak.Oak)10 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)10 StandbyClientSync (org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync)10 StandbyServerSync (org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync)10 DocumentNodeStore (org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)9 MemoryStore (org.apache.jackrabbit.oak.segment.memory.MemoryStore)9 MountInfoProvider (org.apache.jackrabbit.oak.spi.mount.MountInfoProvider)9