Class LogFileCollector

java.lang.Object
io.debezium.connector.oracle.logminer.LogFileCollector

public class LogFileCollector extends Object
A collector that is responsible for fetching, deduplication, and supplying Debezium with a set of LogFile instances that should be mined given a specific Scn.
Author:
Chris Cranford
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • STATUS_CURRENT

      private static final String STATUS_CURRENT
      See Also:
    • ONLINE_LOG_TYPE

      private static final String ONLINE_LOG_TYPE
      See Also:
    • ARCHIVE_LOG_TYPE

      private static final String ARCHIVE_LOG_TYPE
      See Also:
    • initialDelay

      private final Duration initialDelay
    • maxRetryDelay

      private final Duration maxRetryDelay
    • maxAttempts

      private final int maxAttempts
    • archiveLogRetention

      private final Duration archiveLogRetention
    • archiveLogOnlyMode

      private final boolean archiveLogOnlyMode
    • archiveLogDestinationName

      private final String archiveLogDestinationName
    • connection

      private final OracleConnection connection
  • Constructor Details

  • Method Details

    • getLogs

      public List<LogFile> getLogs(Scn offsetScn) throws SQLException
      Get a list of all log files that should be mined given the specified system change number.
      Parameters:
      offsetScn - minimum system change number to start reading changes from, should not be null
      Returns:
      list of log file instances that should be added to the mining session, never null
      Throws:
      SQLException - if there is a database failure during the collection
      DebeziumException - if we were unable to collect logs due to a non-SQL related failure
    • getLogsForOffsetScn

      @VisibleForTesting public List<LogFile> getLogsForOffsetScn(Scn offsetScn) throws SQLException
      Throws:
      SQLException
    • deduplicateLogFiles

      @VisibleForTesting public List<LogFile> deduplicateLogFiles(Collection<LogFile> archiveLogFiles, Collection<LogFile> onlineLogFiles)
    • isLogFileListConsistent

      @VisibleForTesting public boolean isLogFileListConsistent(Scn startScn, List<LogFile> logs, RedoThreadState currentRedoThreadState)
      Checks consistency of the list of log files for redo threads in the currentRedoThreadState state.
      Parameters:
      startScn - the read position system change number, should not be null
      logs - the list of logs to inspect, should not be null
      currentRedoThreadState - the current database redo thread state, should not be null
      Returns:
      true if the logs are consistent; false otherwise
    • isOpenThreadConsistent

      private boolean isOpenThreadConsistent(RedoThreadState.RedoThread thread, Scn startScn, List<LogFile> threadLogs)
      Checks whether the specified open thread has consistent redo-logs in the specified collection.
      Parameters:
      thread - the redo thread to inspect; should not be null
      startScn - the read position system change number, should not be null
      threadLogs - the redo-thread logs to check consistency against, may be null or empty
      Returns:
      true if the open thread's logs are consistent; false otherwise
    • isClosedThreadConsistent

      private boolean isClosedThreadConsistent(RedoThreadState.RedoThread thread, Scn startScn, List<LogFile> threadLogs)
      Checks whether the specified closed thread has consistent redo-logs in the specified collection.
      Parameters:
      thread - the redo thread to inspect; should not be null
      startScn - the read position system change number, should not be null
      threadLogs - the redo-thread logs to check consistency against, may be null or empty
      Returns:
      true if the closed thread's logs are consistent; false otherwise
    • getFirstLogMissingSequence

      private Optional<Long> getFirstLogMissingSequence(List<LogFile> logFiles)
      Searches the specified redo-thread logs and returns the first missing log sequence; if any exist. This method will return an empty value if there are no sequence gaps.
      Parameters:
      logFiles - the redo-thread logs to search; should not be null or empty
      Returns:
      the first missing sequence or an empty value if no gaps are detected
    • logThreadCheckSkippedNotInDatabase

      private void logThreadCheckSkippedNotInDatabase(int threadId)
      Logs a warning that the thread check was skipped because the specified thread has no matching V$THREAD entry.
      Parameters:
      threadId - the redo thread id with no matching database record.
    • getLogsQuery

      private String getLogsQuery(Scn offsetScn)
      Get the SQL query to fetch logs that contain or come after the specified system change number.
      Parameters:
      offsetScn - the starting system change number to read from, should not be null
      Returns:
      query string
    • getScnFromString

      private Scn getScnFromString(String value)
      Converts the specified string value to an Scn.
      Parameters:
      value - the value to convert, can be null or empty
      Returns:
      the system change number for the specified value
    • hasLogFileWithSequenceNumber

      private boolean hasLogFileWithSequenceNumber(long sequenceId, List<LogFile> redoThreadLogs)
      Check whether there is a log file in the collection with the specified sequence number.
      Parameters:
      sequenceId - the sequence number to check
      redoThreadLogs - the collection of redo-thread specific logs to inspect
      Returns:
      true if a log exists with the sequence; false otherwise
    • getSequenceRangeForRedoThreadLogs

      private LogFileCollector.SequenceRange getSequenceRangeForRedoThreadLogs(List<LogFile> redoThreadLogs)
      Calculates the sequence range for a collection of logs for a given redo thread.
      Parameters:
      redoThreadLogs - the redo logs collection, should not be empty.
      Returns:
      the sequence range for the collection of logs
      Throws:
      DebeziumException - if the log collection is empty
    • logException

      private static void logException(String message)