@Test
  public void shouldPerformRecoveryIfNecessary() throws Exception {
    // Given
    StoreRecoverer recoverer = new StoreRecoverer();
    Configuration config = buildProperties();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    new GraphDatabaseFactory().newEmbeddedDatabase(STORE_DIRECTORY).shutdown();
    // Make this look incorrectly shut down
    new File(STORE_DIRECTORY, "nioneo_logical.log.active").delete();

    assertThat(
        "Store should not be recovered",
        recoverer.recoveryNeededAt(new File(STORE_DIRECTORY), new HashMap<String, String>()),
        is(true));

    // Run recovery
    PerformRecoveryIfNecessary task =
        new PerformRecoveryIfNecessary(
            config, new HashMap<String, String>(), new PrintStream(outputStream));
    assertThat("Recovery task should run successfully.", task.run(), is(true));
    assertThat("Database should exist.", new File(STORE_DIRECTORY).exists(), is(true));
    assertThat(
        "Recovery should print status message.",
        outputStream.toString(),
        is("Detected incorrectly shut down database, performing recovery.." + LINEBREAK));
    assertThat(
        "Store should be recovered",
        recoverer.recoveryNeededAt(new File(STORE_DIRECTORY), new HashMap<String, String>()),
        is(false));
  }
Ejemplo n.º 2
0
  private void attemptRecoveryOrCheckStateOfLogicalLogs(Args arguments, String storeDir) {
    if (arguments.getBoolean(RECOVERY, false, true)) {
      dbFactory.newEmbeddedDatabase(storeDir).shutdown();
    } else {
      try {
        if (recoveryChecker.recoveryNeededAt(new File(storeDir))) {
          systemError.print(
              lines(
                  "Active logical log detected, this might be a source of inconsistencies.",
                  "Consider allowing the database to recover before running the consistency check.",
                  "Consistency checking will continue, abort if you wish to perform recovery first.",
                  "To perform recovery before checking consistency, use the '--recovery' flag."));

          exitHandle.pull();
        }
      } catch (IOException e) {
        systemError.printf(
            "Failure when checking for recovery state: '%s', continuing as normal.%n", e);
      }
    }
  }