Exemplo n.º 1
0
 public boolean recoveryNeededAt(File dataDir) throws IOException {
   long logVersion =
       fs.fileExists(new File(dataDir, NeoStore.DEFAULT_NAME))
           ? new NeoStoreUtil(dataDir, fs).getLogVersion()
           : 0;
   return recoveryNeededAt(dataDir, logVersion);
 }
Exemplo n.º 2
0
    /**
     * Will move: messages.log.1 -> messages.log.2 messages.log -> messages.log.1
     *
     * <p>Will delete (if exists): messages.log.2
     */
    private void moveAwayFile() {
      File oldLogFile =
          new File(file.getParentFile(), file.getName() + "." + NUMBER_OF_OLD_LOGS_TO_KEEP);
      if (fileSystem.fileExists(oldLogFile)) {
        fileSystem.deleteFile(oldLogFile);
      }

      for (int i = NUMBER_OF_OLD_LOGS_TO_KEEP - 1; i >= 0; i--) {
        oldLogFile = new File(file.getParentFile(), file.getName() + (i == 0 ? "" : ("." + i)));
        if (fileSystem.fileExists(oldLogFile)) {
          try {
            fileSystem.renameFile(
                oldLogFile, new File(file.getParentFile(), file.getName() + "." + (i + 1)));
          } catch (IOException e) {
            throw new RuntimeException(e);
          }
        }
      }
    }
Exemplo n.º 3
0
  public boolean recoveryNeededAt(File dataDir, long currentLogVersion) throws IOException {
    // We need config to determine where the logical log files are
    File neoStorePath = new File(dataDir, NeoStore.DEFAULT_NAME);
    if (!fs.fileExists(neoStorePath)) {
      // No database in the specified directory.
      return false;
    }

    PhysicalLogFiles logFiles = new PhysicalLogFiles(dataDir, fs);
    File log = logFiles.getLogFileForVersion(currentLogVersion);

    if (!fs.fileExists(log)) {
      // This most likely means that the db has been cleanly shut down, i.e. force then inc log
      // version,
      // then NOT creating a new log file (will be done the next startup)
      return false;
    }
    try (StoreChannel logChannel = fs.open(log, "r")) {
      return LogRecoveryCheck.recoveryRequired(logChannel);
    }
  }
Exemplo n.º 4
0
  /**
   * Moves a file from one directory to another, by a rename op.
   *
   * @param fs
   * @param fileName The base filename of the file to move, not the complete path
   * @param fromDirectory The directory currently containing filename
   * @param toDirectory The directory to host filename - must be in the same disk partition as
   *     filename
   * @param allowOverwriteTarget
   * @throws java.io.IOException
   */
  static void moveFile(
      FileSystemAbstraction fs,
      String fileName,
      File fromDirectory,
      File toDirectory,
      boolean allowSkipNonExistentFiles,
      boolean allowOverwriteTarget)
      throws IOException {
    File sourceFile = new File(fromDirectory, fileName);
    if (allowSkipNonExistentFiles
        && !fs.fileExists(
            sourceFile)) { // The source file doesn't exist and we allow skipping, so return
      return;
    }

    File toFile = new File(toDirectory, fileName);
    if (allowOverwriteTarget && fs.fileExists(toFile)) {
      fs.deleteFile(toFile);
    }

    fs.moveToDirectory(sourceFile, toDirectory);
  }