Search in sources :

Example 1 with Result

use of org.neo4j.consistency.ConsistencyCheckService.Result in project neo4j by neo4j.

the class ConsistencyCheckServiceIntegrationTest method shouldAllowGraphCheckDisabled.

@Test
public void shouldAllowGraphCheckDisabled() throws IOException, ConsistencyCheckIncompleteException {
    GraphDatabaseService gds = getGraphDatabaseService();
    try (Transaction tx = gds.beginTx()) {
        gds.createNode();
        tx.success();
    }
    gds.shutdown();
    ConsistencyCheckService service = new ConsistencyCheckService();
    Config configuration = Config.embeddedDefaults(settings(ConsistencyCheckSettings.consistency_check_graph.name(), Settings.FALSE));
    // when
    Result result = runFullConsistencyCheck(service, configuration);
    // then
    assertTrue(result.isSuccessful());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Config(org.neo4j.kernel.configuration.Config) Result(org.neo4j.consistency.ConsistencyCheckService.Result) Test(org.junit.Test)

Example 2 with Result

use of org.neo4j.consistency.ConsistencyCheckService.Result in project neo4j by neo4j.

the class ConsistencyCheckServiceIntegrationTest method reportNotUsedRelationshipReferencedInChain.

@Test
public void reportNotUsedRelationshipReferencedInChain() throws Exception {
    prepareDbWithDeletedRelationshipPartOfTheChain();
    Date timestamp = new Date();
    ConsistencyCheckService service = new ConsistencyCheckService(timestamp);
    Config configuration = Config.embeddedDefaults(settings());
    ConsistencyCheckService.Result result = runFullConsistencyCheck(service, configuration);
    assertFalse(result.isSuccessful());
    File reportFile = result.reportFile();
    assertTrue("Consistency check report file should be generated.", reportFile.exists());
    assertThat("Expected to see report about not deleted relationship record present as part of a chain", Files.readAllLines(reportFile.toPath()).toString(), containsString("The relationship record is not in use, but referenced from relationships chain."));
}
Also used : Result(org.neo4j.consistency.ConsistencyCheckService.Result) Config(org.neo4j.kernel.configuration.Config) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 3 with Result

use of org.neo4j.consistency.ConsistencyCheckService.Result 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)

Example 4 with Result

use of org.neo4j.consistency.ConsistencyCheckService.Result in project neo4j by neo4j.

the class ConsistencyCheckServiceIntegrationTest method shouldFailIfTheStoreInNotConsistent.

@Test
public void shouldFailIfTheStoreInNotConsistent() throws Exception {
    // given
    breakNodeStore();
    Date timestamp = new Date();
    ConsistencyCheckService service = new ConsistencyCheckService(timestamp);
    String logsDir = testDirectory.directory().getPath();
    Config configuration = Config.embeddedDefaults(settings(GraphDatabaseSettings.logs_directory.name(), logsDir));
    // when
    ConsistencyCheckService.Result result = runFullConsistencyCheck(service, configuration);
    // then
    assertFalse(result.isSuccessful());
    String reportFile = format("inconsistencies-%s.report", new SimpleDateFormat("yyyy-MM-dd.HH.mm.ss").format(timestamp));
    assertEquals(new File(logsDir, reportFile), result.reportFile());
    assertTrue("Inconsistency report file not generated", result.reportFile().exists());
}
Also used : Result(org.neo4j.consistency.ConsistencyCheckService.Result) Config(org.neo4j.kernel.configuration.Config) Matchers.containsString(org.hamcrest.Matchers.containsString) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 5 with Result

use of org.neo4j.consistency.ConsistencyCheckService.Result in project neo4j by neo4j.

the class ConsistencyCheckServiceIntegrationTest method shouldNotReportDuplicateForHugeLongValues.

@Test
public void shouldNotReportDuplicateForHugeLongValues() throws Exception {
    // given
    ConsistencyCheckService service = new ConsistencyCheckService();
    Config configuration = Config.embeddedDefaults(settings());
    GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(testDirectory.graphDbDir()).setConfig(GraphDatabaseSettings.record_format, getRecordFormatName()).newGraphDatabase();
    String propertyKey = "itemId";
    Label label = Label.label("Item");
    try (Transaction tx = db.beginTx()) {
        db.schema().constraintFor(label).assertPropertyIsUnique(propertyKey).create();
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        set(db.createNode(label), property(propertyKey, 973305894188596880L));
        set(db.createNode(label), property(propertyKey, 973305894188596864L));
        tx.success();
    }
    db.shutdown();
    // when
    Result result = runFullConsistencyCheck(service, configuration);
    // then
    assertTrue(result.isSuccessful());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Config(org.neo4j.kernel.configuration.Config) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Label(org.neo4j.graphdb.Label) Matchers.containsString(org.hamcrest.Matchers.containsString) Result(org.neo4j.consistency.ConsistencyCheckService.Result) Test(org.junit.Test)

Aggregations

Result (org.neo4j.consistency.ConsistencyCheckService.Result)8 Test (org.junit.Test)5 Config (org.neo4j.kernel.configuration.Config)5 File (java.io.File)4 Date (java.util.Date)3 ConsistencyCheckService (org.neo4j.consistency.ConsistencyCheckService)3 Matchers.containsString (org.hamcrest.Matchers.containsString)2 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 Transaction (org.neo4j.graphdb.Transaction)2 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 SimpleDateFormat (java.text.SimpleDateFormat)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Label (org.neo4j.graphdb.Label)1 Args (org.neo4j.helpers.Args)1 StoreAccess (org.neo4j.kernel.impl.store.StoreAccess)1 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)1 LifecycleAdapter (org.neo4j.kernel.lifecycle.LifecycleAdapter)1 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)1 ArgsCommand (org.neo4j.tools.console.input.ArgsCommand)1