private void openHeadLogFile() throws ChangelogException { final LogFile<K, V> head = LogFile.newAppendableLogFile(new File(logPath, HEAD_LOG_FILE_NAME), recordParser); final Record<K, V> newestRecord = head.getNewestRecord(); lastAppendedKey = newestRecord != null ? newestRecord.getKey() : null; logFiles.put(recordParser.getMaxKey(), head); }
/** Update the cursors that were pointing to head after a rotation of the head log file. */ private void updateOpenedCursorsOnHeadAfterRotation( List<Pair<AbortableLogCursor<K, V>, CursorState<K, V>>> cursors) throws ChangelogException { for (Pair<AbortableLogCursor<K, V>, CursorState<K, V>> pair : cursors) { final CursorState<K, V> cursorState = pair.getSecond(); // Need to update the cursor only if it is pointing to the head log file if (cursorState.isValid() && isHeadLogFile(cursorState.logFile)) { final K previousKey = logFiles.lowerKey(recordParser.getMaxKey()); final LogFile<K, V> logFile = findLogFileFor(previousKey); final AbortableLogCursor<K, V> cursor = pair.getFirst(); cursor.reinitializeTo( new CursorState<K, V>(logFile, cursorState.filePosition, cursorState.record)); } } }