RecoveryCommand implements Command { @Override public void execute(String... args) throws Exception { Closer closer = Utils.createCloserWithShutdownHook(); MapDBMapFactory mdbmf = new MapDBMapFactory(); closer.register(mdbmf); MapFactory.setInstance(mdbmf); String h = "recovery mongodb: try { DocumentNodeStoreBuilder<?> builder = Utils.createDocumentMKBuilder(args, closer, h); if (builder == null) { System.err.println("Recovery only available for DocumentNodeStore backed by MongoDB or RDB persistence"); System.exit(1); } builder.setBlobStore(new MemoryBlobStore()); boolean dryRun = Arrays.asList(args).contains("dryRun"); if (dryRun) { builder.setReadOnlyMode(); } DocumentNodeStore dns = builder.build(); closer.register(Utils.asCloseable(dns)); DocumentStore ds = builder.getDocumentStore(); LastRevRecoveryAgent agent = null; MissingLastRevSeeker seeker = null; if (ds instanceof MongoDocumentStore) { MongoDocumentStore docStore = (MongoDocumentStore) ds; agent = new LastRevRecoveryAgent(docStore, dns); seeker = new MongoMissingLastRevSeeker(docStore, dns.getClock()); } else if (ds instanceof RDBDocumentStore) { RDBDocumentStore docStore = (RDBDocumentStore) ds; agent = new LastRevRecoveryAgent(docStore, dns); seeker = new RDBMissingLastRevSeeker(docStore, dns.getClock()); } if (agent == null || seeker == null) { System.err.println("Recovery only available for MongoDocumentStore and RDBDocumentStore (this: " + ds.getClass().getName() + ")"); System.exit(1); } if (builder.getClusterId() == 0) { System.err.println("Please specify the clusterId for recovery using --clusterId"); try { List<ClusterNodeInfoDocument> all = ClusterNodeInfoDocument.all(ds); System.err.println("Existing entries in the clusternodes collection are:"); for (ClusterNodeInfoDocument c : all) { String state = c.isActive() ? "ACTIVE" : "INACTIVE"; System.err.println(c.getClusterId() + " (" + state + "): " + c.toString().replace('\n', ' ')); } } catch (Throwable e) { e.printStackTrace(System.err); } System.exit(1); } Iterable<NodeDocument> docs = seeker.getCandidates(0); if (docs instanceof Closeable) { closer.register((Closeable) docs); } agent.recover(docs, builder.getClusterId(), dryRun); } catch (Throwable e) { throw closer.rethrow(e); } finally { closer.close(); MapFactory.setInstance(oldf); } }  @Override void execute(String... args);  }
@Test public void recovery() throws Exception { RecoveryCommand cmd = new RecoveryCommand(); cmd.execute( "--clusterId", String.valueOf(ns.getClusterId()), MongoUtils.URL, "dryRun" ); }