Search in sources :

Example 1 with ConsoleInput

use of org.neo4j.tools.console.input.ConsoleInput in project neo4j by neo4j.

the class DatabaseRebuildTool method run.

public void run(String... arguments) throws Exception {
    if (arguments.length == 0) {
        System.err.println("Tool for rebuilding database from transaction logs onto a new store");
        System.err.println("Example: dbrebuild --from path/to/some.db --to path/to/new.db apply next");
        System.err.println("         dbrebuild --from path/to/some.db --to path/to/new.db -i");
        System.err.println("          --from : which db to use as source for reading transactions");
        System.err.println("            --to : where to build the new db");
        System.err.println("  --overwrite-to : always starts from empty 'to' db");
        System.err.println("              -i : interactive mode (enter a shell)");
        return;
    }
    Args args = Args.withFlags("i", "overwrite-to").parse(arguments);
    File fromPath = getFrom(args);
    File toPath = getTo(args);
    GraphDatabaseBuilder dbBuilder = newDbBuilder(toPath, args);
    boolean interactive = args.getBoolean("i");
    if (interactive && !args.orphans().isEmpty()) {
        throw new IllegalArgumentException("No additional commands allowed in interactive mode");
    }
    @SuppressWarnings("resource") InputStream input = interactive ? in : oneCommand(args.orphansAsArray());
    LifeSupport life = new LifeSupport();
    ConsoleInput consoleInput = console(fromPath, dbBuilder, input, interactive ? staticPrompt("# ") : NO_PROMPT, life);
    life.start();
    try {
        consoleInput.waitFor();
    } finally {
        life.shutdown();
    }
}
Also used : Args(org.neo4j.helpers.Args) InputStream(java.io.InputStream) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) ConsoleInput(org.neo4j.tools.console.input.ConsoleInput) File(java.io.File) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder)

Example 2 with ConsoleInput

use of org.neo4j.tools.console.input.ConsoleInput in project neo4j by neo4j.

the class DatabaseRebuildTool method console.

private ConsoleInput console(final File fromPath, final GraphDatabaseBuilder dbBuilder, InputStream in, Listener<PrintStream> prompt, LifeSupport life) throws Exception {
    // We must have this indirection here since in order to perform CC (one of the commands) we must shut down
    // the database and let CC instantiate its own to run on. After that completes the db
    // should be restored. The commands has references to providers of things to accommodate for this.
    final AtomicReference<Store> store = new AtomicReference<>(new Store(dbBuilder));
    final Supplier<StoreAccess> storeAccess = () -> store.get().access;
    final Supplier<GraphDatabaseAPI> dbAccess = () -> store.get().db;
    ConsoleInput consoleInput = life.add(new ConsoleInput(in, out, prompt));
    consoleInput.add("apply", new ApplyTransactionsCommand(fromPath, dbAccess));
    consoleInput.add(DumpRecordsCommand.NAME, new DumpRecordsCommand(storeAccess));
    consoleInput.add("cc", new ArgsCommand() {

        @Override
        public void run(Args action, PrintStream out) throws Exception {
            File storeDir = store.get().storeDir;
            store.get().shutdown();
            try {
                Result result = new ConsistencyCheckService().runFullConsistencyCheck(storeDir, Config.defaults(), ProgressMonitorFactory.textual(out), FormattedLogProvider.toOutputStream(System.out), false);
                out.println(result.isSuccessful() ? "consistent" : "INCONSISTENT");
            } finally {
                store.set(new Store(dbBuilder));
            }
        }

        @Override
        public String toString() {
            return "Runs consistency check on the database for data that has been applied up to this point";
        }
    });
    life.add(new LifecycleAdapter() {

        @Override
        public void shutdown() {
            store.get().shutdown();
        }
    });
    return consoleInput;
}
Also used : PrintStream(java.io.PrintStream) Args(org.neo4j.helpers.Args) StoreAccess(org.neo4j.kernel.impl.store.StoreAccess) AtomicReference(java.util.concurrent.atomic.AtomicReference) LifecycleAdapter(org.neo4j.kernel.lifecycle.LifecycleAdapter) IOException(java.io.IOException) Result(org.neo4j.consistency.ConsistencyCheckService.Result) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) ConsoleInput(org.neo4j.tools.console.input.ConsoleInput) ArgsCommand(org.neo4j.tools.console.input.ArgsCommand) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) File(java.io.File)

Aggregations

File (java.io.File)2 Args (org.neo4j.helpers.Args)2 ConsoleInput (org.neo4j.tools.console.input.ConsoleInput)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 PrintStream (java.io.PrintStream)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ConsistencyCheckService (org.neo4j.consistency.ConsistencyCheckService)1 Result (org.neo4j.consistency.ConsistencyCheckService.Result)1 GraphDatabaseBuilder (org.neo4j.graphdb.factory.GraphDatabaseBuilder)1 StoreAccess (org.neo4j.kernel.impl.store.StoreAccess)1 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)1 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)1 LifecycleAdapter (org.neo4j.kernel.lifecycle.LifecycleAdapter)1 ArgsCommand (org.neo4j.tools.console.input.ArgsCommand)1