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