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;
}
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();
}
}
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();
}
}
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;
}
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();
}
}
Aggregations