Search in sources :

Example 1 with SequentialAccessWriteAheadLog

use of org.apache.nifi.wali.SequentialAccessWriteAheadLog in project nifi by apache.

the class WriteAheadFlowFileRepository method migrateFromSequentialAccessLog.

private Optional<Collection<RepositoryRecord>> migrateFromSequentialAccessLog(final WriteAheadRepository<RepositoryRecord> toUpdate) throws IOException {
    final String recoveryDirName = nifiProperties.getProperty(FLOWFILE_REPOSITORY_DIRECTORY_PREFIX);
    final File recoveryDir = new File(recoveryDirName);
    if (!recoveryDir.exists()) {
        return Optional.empty();
    }
    final WriteAheadRepository<RepositoryRecord> recoveryWal = new SequentialAccessWriteAheadLog<>(recoveryDir, serdeFactory, this);
    logger.info("Encountered FlowFile Repository that was written using the Sequential Access Write Ahead Log. Will recover from this version.");
    final Collection<RepositoryRecord> recordList;
    try {
        recordList = recoveryWal.recoverRecords();
    } finally {
        recoveryWal.shutdown();
    }
    toUpdate.update(recordList, true);
    logger.info("Successfully recovered files from existing Write-Ahead Log and transitioned to new Write-Ahead Log. Will not delete old files.");
    final File journalsDir = new File(recoveryDir, "journals");
    deleteRecursively(journalsDir);
    final File checkpointFile = new File(recoveryDir, "checkpoint");
    if (!checkpointFile.delete() && checkpointFile.exists()) {
        logger.warn("Failed to delete old file {}; this file should be cleaned up manually", checkpointFile);
    }
    final File partialFile = new File(recoveryDir, "checkpoint.partial");
    if (!partialFile.delete() && partialFile.exists()) {
        logger.warn("Failed to delete old file {}; this file should be cleaned up manually", partialFile);
    }
    return Optional.of(recordList);
}
Also used : SequentialAccessWriteAheadLog(org.apache.nifi.wali.SequentialAccessWriteAheadLog) File(java.io.File)

Aggregations

File (java.io.File)1 SequentialAccessWriteAheadLog (org.apache.nifi.wali.SequentialAccessWriteAheadLog)1