Class LogMinerHelper
- java.lang.Object
-
- io.debezium.connector.oracle.logminer.LogMinerHelper
-
public class LogMinerHelper extends Object
This class contains methods to configure and manage LogMiner utility
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLogMinerHelper.DATATYPE
-
Field Summary
Fields Modifier and Type Field Description private static StringALL_COLUMN_LOGGINGprivate static StringCURRENTprivate static org.slf4j.LoggerLOGGERprivate static Map<String,OracleConnection>racFlushConnectionsprivate static StringTOTALprivate static StringUNKNOWN
-
Constructor Summary
Constructors Constructor Description LogMinerHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static voidbuildDataDictionary(OracleConnection connection)This builds data dictionary objects in redo log files.(package private) static voidcheckSupplementalLogging(OracleConnection connection, String pdbName, OracleDatabaseSchema schema)This method validates the supplemental logging configuration for the source database.private static OracleConnectioncreateFlushConnection(JdbcConfiguration config, String host)(package private) static voidcreateFlushTable(OracleConnection connection)static voidendMining(OracleConnection connection)This call completes LogMiner session.private static voidexecuteCallableStatement(OracleConnection connection, String statement)(package private) static voidflushLogWriter(OracleConnection connection, JdbcConfiguration config, boolean isRac, Set<String> racHosts)It is critical to flush LogWriter(s) bufferprivate static voidflushRacLogWriters(Scn currentScn, JdbcConfiguration config, Set<String> racHosts)Oracle RAC has one LogWriter per node (instance), we have to flush them all We cannot use a query like from gv_instance view to get all the nodes, because not all nodes could be load balanced.static intgetColumnIndexByName(String columnName, Table table)Returns a 0-based index offset for the column name in the relational table.(package private) static Set<String>getCurrentRedoLogFiles(OracleConnection connection)This method query the database to get CURRENT online redo log file(s).(package private) static ScngetEndScn(OracleConnection connection, Scn startScn, Scn prevEndScn, OracleStreamingChangeEventSourceMetrics streamingMetrics, int defaultBatchSize, boolean lobEnabled, boolean archiveLogOnlyMode, String archiveLogDestinationName)This method returns next SCN for mining and also updates streaming metrics.(package private) static ScngetFirstOnlineLogScn(OracleConnection connection, Duration archiveLogRetention, String archiveDestinationName)This method fetches the oldest SCN from online redo log filesstatic Optional<Scn>getLastScnToAbandon(OracleConnection connection, Scn offsetScn, Duration transactionRetention)This method calculates SCN as a watermark to abandon long lasting transactions.static List<LogFile>getLogFilesForOffsetScn(OracleConnection connection, Scn offsetScn, Duration archiveLogRetention, boolean archiveLogOnlyMode, String archiveDestinationName)Get all log files that should be mined.static Map<String,String>getMap(OracleConnection connection, String query, String nullReplacement)private static Map<String,String>getRedoLogStatus(OracleConnection connection)This fetches online redo log statusesprivate static ScngetScnFromString(String value)static ObjectgetSingleResult(OracleConnection connection, String query, LogMinerHelper.DATATYPE type)private static intgetSwitchCount(OracleConnection connection, String archiveDestinationName)This fetches REDO LOG switch count for the last day(package private) static OffsetDateTimegetSystime(OracleConnection connection)Get the database time in the time zone of the system this database is running on(package private) static voidinstantiateFlushConnections(JdbcConfiguration config, Set<String> hosts)(package private) static booleanisTableSupplementalLogDataAll(OracleConnection connection, TableId tableId)private static voidlogDatabaseState(OracleConnection connection)Helper method that will dump the state of various critical tables used by the LogMiner implementation to derive state about which logs are to be mined and processed by the Oracle LogMiner session.(package private) static voidlogError(OracleStreamingChangeEventSourceMetrics streamingMetrics, String format, Object... args)private static voidlogQueryResults(OracleConnection connection, String query)Helper method that dumps the result set of an arbitrary SQL query to the connector's logs.(package private) static voidlogWarn(OracleStreamingChangeEventSourceMetrics streamingMetrics, String format, Object... args)static voidremoveLogFilesFromMining(OracleConnection conn)This method removes all added log files from miningstatic voidsetLogFilesForMining(OracleConnection connection, Scn lastProcessedScn, Duration archiveLogRetention, boolean archiveLogOnlyMode, String archiveDestinationName)This method substitutes CONTINUOUS_MINE functionality(package private) static voidsetNlsSessionParameters(JdbcConnection connection)Sets NLS parameters for mining session.(package private) static voidstartLogMining(OracleConnection connection, Scn startScn, Scn endScn, OracleConnectorConfig.LogMiningStrategy strategy, boolean isContinuousMining, OracleStreamingChangeEventSourceMetrics streamingMetrics)This method builds mining view to query changes from.
-
-
-
Field Detail
-
CURRENT
private static final String CURRENT
- See Also:
- Constant Field Values
-
UNKNOWN
private static final String UNKNOWN
- See Also:
- Constant Field Values
-
TOTAL
private static final String TOTAL
- See Also:
- Constant Field Values
-
ALL_COLUMN_LOGGING
private static final String ALL_COLUMN_LOGGING
- See Also:
- Constant Field Values
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
racFlushConnections
private static Map<String,OracleConnection> racFlushConnections
-
-
Method Detail
-
instantiateFlushConnections
static void instantiateFlushConnections(JdbcConfiguration config, Set<String> hosts)
-
buildDataDictionary
static void buildDataDictionary(OracleConnection connection) throws SQLException
This builds data dictionary objects in redo log files. During this build, Oracle does an additional REDO LOG switch. This call may take time, which leads to delay in delivering incremental changes. With this option the lag between source database and dispatching event fluctuates.- Parameters:
connection- connection to the database as LogMiner user (connection to the container)- Throws:
SQLException- any exception
-
createFlushTable
static void createFlushTable(OracleConnection connection) throws SQLException
- Throws:
SQLException
-
getEndScn
static Scn getEndScn(OracleConnection connection, Scn startScn, Scn prevEndScn, OracleStreamingChangeEventSourceMetrics streamingMetrics, int defaultBatchSize, boolean lobEnabled, boolean archiveLogOnlyMode, String archiveLogDestinationName) throws SQLException
This method returns next SCN for mining and also updates streaming metrics. We use a configurable limit, because the larger mining range, the slower query from LogMiner content view. In addition capturing unlimited number of changes can blow up Java heap. Gradual querying helps to catch up faster after long delays in mining.- Parameters:
connection- container level database connectionstartScn- start SCNprevEndScn- previous end SCNstreamingMetrics- the streaming metricslobEnabled- specifies whether LOB support is enabledarchiveLogOnlyMode- specifies whether archive log only mode is enabledarchiveLogDestinationName- the archive log destination name- Returns:
- next SCN to mine up to
- Throws:
SQLException- if anything unexpected happens
-
flushLogWriter
static void flushLogWriter(OracleConnection connection, JdbcConfiguration config, boolean isRac, Set<String> racHosts) throws SQLException
It is critical to flush LogWriter(s) buffer- Parameters:
connection- container level database connectionconfig- configurationisRac- true if this is the RAC systemracHosts- set of RAC host- Throws:
SQLException- exception
-
getSystime
static OffsetDateTime getSystime(OracleConnection connection) throws SQLException
Get the database time in the time zone of the system this database is running on- Parameters:
connection- connection- Returns:
- the database system time
- Throws:
SQLException
-
startLogMining
static void startLogMining(OracleConnection connection, Scn startScn, Scn endScn, OracleConnectorConfig.LogMiningStrategy strategy, boolean isContinuousMining, OracleStreamingChangeEventSourceMetrics streamingMetrics) throws SQLException
This method builds mining view to query changes from. This view is built for online redo log files. It starts log mining session. It uses data dictionary objects, incorporated in previous steps. It tracks DDL changes and mines committed data only.- Parameters:
connection- container level database connectionstartScn- the SCN to mine fromendScn- the SCN to mine tostrategy- this is about dictionary locationisContinuousMining- works < 19 version onlystreamingMetrics- the streaming metrics- Throws:
SQLException- if anything unexpected happens
-
getCurrentRedoLogFiles
static Set<String> getCurrentRedoLogFiles(OracleConnection connection) throws SQLException
This method query the database to get CURRENT online redo log file(s). Multiple is applicable for RAC systems.- Parameters:
connection- connection to reuse- Returns:
- full redo log file name(s), including path
- Throws:
SQLException- if anything unexpected happens
-
getFirstOnlineLogScn
static Scn getFirstOnlineLogScn(OracleConnection connection, Duration archiveLogRetention, String archiveDestinationName) throws SQLException
This method fetches the oldest SCN from online redo log files- Parameters:
connection- container level database connectionarchiveLogRetention- duration that archive logs are minedarchiveDestinationName- configured archive destination name to use, may benull- Returns:
- oldest SCN from online redo log
- Throws:
SQLException- if anything unexpected happens
-
setNlsSessionParameters
static void setNlsSessionParameters(JdbcConnection connection) throws SQLException
Sets NLS parameters for mining session.- Parameters:
connection- session level database connection- Throws:
SQLException- if anything unexpected happens
-
getRedoLogStatus
private static Map<String,String> getRedoLogStatus(OracleConnection connection) throws SQLException
This fetches online redo log statuses- Parameters:
connection- privileged connection- Returns:
- REDO LOG statuses Map, where key is the REDO name and value is the status
- Throws:
SQLException- if anything unexpected happens
-
getSwitchCount
private static int getSwitchCount(OracleConnection connection, String archiveDestinationName)
This fetches REDO LOG switch count for the last day- Parameters:
connection- privileged connectionarchiveDestinationName- configured archive destination name, may benull- Returns:
- counter
-
flushRacLogWriters
private static void flushRacLogWriters(Scn currentScn, JdbcConfiguration config, Set<String> racHosts)
Oracle RAC has one LogWriter per node (instance), we have to flush them all We cannot use a query like from gv_instance view to get all the nodes, because not all nodes could be load balanced. We also cannot rely on connection factory, because it may return connection to the same instance multiple times Instead we are asking node ip list from configuration
-
createFlushConnection
private static OracleConnection createFlushConnection(JdbcConfiguration config, String host) throws SQLException
- Throws:
SQLException
-
checkSupplementalLogging
static void checkSupplementalLogging(OracleConnection connection, String pdbName, OracleDatabaseSchema schema) throws SQLException
This method validates the supplemental logging configuration for the source database.- Parameters:
connection- oracle connection on LogMiner levelpdbName- pdb nameschema- oracle schema- Throws:
SQLException- if anything unexpected happens
-
isTableSupplementalLogDataAll
static boolean isTableSupplementalLogDataAll(OracleConnection connection, TableId tableId) throws SQLException
- Throws:
SQLException
-
endMining
public static void endMining(OracleConnection connection)
This call completes LogMiner session. Complete gracefully.- Parameters:
connection- container level database connection
-
setLogFilesForMining
public static void setLogFilesForMining(OracleConnection connection, Scn lastProcessedScn, Duration archiveLogRetention, boolean archiveLogOnlyMode, String archiveDestinationName) throws SQLException
This method substitutes CONTINUOUS_MINE functionality- Parameters:
connection- connectionlastProcessedScn- current offsetarchiveLogRetention- the duration that archive logs will be minedarchiveLogOnlyMode- true to mine only archive lgos, false to mine all available logsarchiveDestinationName- configured archive log destination name to use, may benull- Throws:
SQLException- if anything unexpected happens
-
getLastScnToAbandon
public static Optional<Scn> getLastScnToAbandon(OracleConnection connection, Scn offsetScn, Duration transactionRetention)
This method calculates SCN as a watermark to abandon long lasting transactions. The criteria is don't let offset scn go out of archives older given number of hours- Parameters:
connection- connectionoffsetScn- current offset scntransactionRetention- duration to tolerate long running transactions- Returns:
- optional SCN as a watermark for abandonment
-
logWarn
static void logWarn(OracleStreamingChangeEventSourceMetrics streamingMetrics, String format, Object... args)
-
logError
static void logError(OracleStreamingChangeEventSourceMetrics streamingMetrics, String format, Object... args)
-
getLogFilesForOffsetScn
public static List<LogFile> getLogFilesForOffsetScn(OracleConnection connection, Scn offsetScn, Duration archiveLogRetention, boolean archiveLogOnlyMode, String archiveDestinationName) throws SQLException
Get all log files that should be mined.- Parameters:
connection- database connectionoffsetScn- offset system change numberarchiveLogRetention- duration that archive logs should be minedarchiveLogOnlyMode- true to mine only archive logs, false to mine all available logsarchiveDestinationName- archive destination to use, may benull- Returns:
- list of log files
- Throws:
SQLException- if a database exception occurs
-
logDatabaseState
private static void logDatabaseState(OracleConnection connection)
Helper method that will dump the state of various critical tables used by the LogMiner implementation to derive state about which logs are to be mined and processed by the Oracle LogMiner session.- Parameters:
connection- the database connection
-
logQueryResults
private static void logQueryResults(OracleConnection connection, String query) throws SQLException
Helper method that dumps the result set of an arbitrary SQL query to the connector's logs.- Parameters:
connection- the database connectionquery- the query to execute- Throws:
SQLException- thrown if an exception occurs performing a SQL operation
-
removeLogFilesFromMining
public static void removeLogFilesFromMining(OracleConnection conn) throws SQLException
This method removes all added log files from mining- Parameters:
conn- connection- Throws:
SQLException- something happened
-
executeCallableStatement
private static void executeCallableStatement(OracleConnection connection, String statement) throws SQLException
- Throws:
SQLException
-
getMap
public static Map<String,String> getMap(OracleConnection connection, String query, String nullReplacement) throws SQLException
- Throws:
SQLException
-
getSingleResult
public static Object getSingleResult(OracleConnection connection, String query, LogMinerHelper.DATATYPE type) throws SQLException
- Throws:
SQLException
-
getColumnIndexByName
public static int getColumnIndexByName(String columnName, Table table)
Returns a 0-based index offset for the column name in the relational table.- Parameters:
columnName- the column name, should not benull.table- the relational table, should not benull.- Returns:
- the 0-based index offset for the column name
-
-