Class AbstractLogMinerEventProcessor<T extends AbstractTransaction>
- java.lang.Object
-
- io.debezium.connector.oracle.logminer.processor.AbstractLogMinerEventProcessor<T>
-
- All Implemented Interfaces:
LogMinerEventProcessor,AutoCloseable
- Direct Known Subclasses:
AbstractInfinispanLogMinerEventProcessor,MemoryLogMinerEventProcessor
public abstract class AbstractLogMinerEventProcessor<T extends AbstractTransaction> extends Object implements LogMinerEventProcessor
An abstract implementation ofLogMinerEventProcessorthat all processors should extend.- Author:
- Chris Cranford
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classAbstractLogMinerEventProcessor.CountersWrapper for all counter variablesprivate classAbstractLogMinerEventProcessor.ParsedLobWriteSql
-
Field Summary
Fields Modifier and Type Field Description private OracleConnectorConfigconnectorConfigprivate ChangeEventSource.ChangeEventSourceContextcontextprotected AbstractLogMinerEventProcessor.Counterscountersprivate ScncurrentOffsetCommitScnprivate ScncurrentOffsetScnprivate EventDispatcher<OraclePartition,TableId>dispatcherprivate LogMinerDmlParserdmlParserprivate ScnlastCommittedScnprivate ScnlastProcessedScnprivate static PatternLOB_WRITE_SQL_PATTERNprivate static org.slf4j.LoggerLOGGERprivate ScnmaxCommittedScnprivate OracleStreamingChangeEventSourceMetricsmetricsprivate OracleOffsetContextoffsetContextprivate OraclePartitionpartitionprivate OracleDatabaseSchemaschemaprivate SelectLobParserselectLobParserprivate booleansequenceUnavailable
-
Constructor Summary
Constructors Constructor Description AbstractLogMinerEventProcessor(ChangeEventSource.ChangeEventSourceContext context, OracleConnectorConfig connectorConfig, OracleDatabaseSchema schema, OraclePartition partition, OracleOffsetContext offsetContext, EventDispatcher<OraclePartition,TableId> dispatcher, OracleStreamingChangeEventSourceMetrics metrics)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidaddToTransaction(String transactionId, LogMinerEventRow row, Supplier<LogMinerEvent> eventSupplier)Add a transaction to the transaction map if allowed.protected abstract ScncalculateNewStartScn(Scn endScn, Scn maxCommittedScn)Calculates the new starting system change number based on the current processing range.protected abstract PreparedStatementcreateQueryStatement()Create the JDBC query that will be used to fetch the mining result set.protected abstract TcreateTransaction(LogMinerEventRow row)Creates a new transaction based on the suppliedSTARTevent.private TabledispatchSchemaChangeEventAndGetTableForNewCapturedTable(TableId tableId, OracleOffsetContext offsetContext, EventDispatcher<OraclePartition,TableId> dispatcher)Dispatch a schema change event for a new table and get the newly created relational table model.protected abstract voidfinalizeTransactionCommit(String transactionId, Scn commitScn)Finalizes the commit of a transaction.protected abstract voidfinalizeTransactionRollback(String transactionId, Scn rollbackScn)Finalizes the rollback the specified transactionprotected abstract TgetAndRemoveTransactionFromCache(String transactionId)Gets a transaction instance from the transaction cache while also removing its cache entry.protected OracleConnectorConfiggetConfig()protected ScngetLastProcessedScn()Return the last processed system change number handled by the processor.protected OracleDatabaseSchemagetSchema()private TablegetTableForDataEvent(LogMinerEventRow row)private StringgetTableMetadataDdl(TableId tableId)Get the specified table's create DDL statement.protected abstract Map<String,T>getTransactionCache()Returns theTransactionCacheimplementation.protected abstract ScngetTransactionCacheMinimumScn()Gets the minimum system change number stored in the transaction cache.protected abstract intgetTransactionEventCount(T transaction)Returns the number of events associated with the specified transaction.protected abstract Iterator<LogMinerEvent>getTransactionEventIterator(T transaction)Get an iterator over the events that are part of the specified transaction.protected voidhandleCommit(OraclePartition partition, LogMinerEventRow row)Handle processing a LogMinerEventRow for aCOMMITevent.protected voidhandleDataEvent(LogMinerEventRow row)Handle processing a LogMinerEventRow for aINSERT,UPDATE, orDELETEevent.private voidhandleLobErase(LogMinerEventRow row)Handle processing a LogMinerEventRow for aLOB_ERASEevent.protected voidhandleLobWrite(LogMinerEventRow row)Handle processing a LogMinerEventRow for aLOB_WRITEevent.protected voidhandleMissingScn(LogMinerEventRow row)Handle processing a LogMinerEventRow for aMISSING_SCNevent.protected voidhandleRollback(LogMinerEventRow row)Handle processing a LogMinerEventRow for aROLLBACKevent.protected voidhandleSchemaChange(LogMinerEventRow row)Handle processing a LogMinerEventRow for aDDLevent.protected voidhandleSelectLobLocator(LogMinerEventRow row)Handle processing a LogMinerEventRow for aSEL_LOB_LOCATORevent.protected voidhandleStart(LogMinerEventRow row)Handle processing a LogMinerEventRow for aSTARTevent.private booleanhasNextWithMetricsUpdate(ResultSet resultSet)Checks whether the result-set has any more data available.protected booleanhasSchemaChangeBeenSeen(LogMinerEventRow row)Checks whether the LogMinerEvent row for a schema change can be emitted.protected booleanisRecentlyProcessed(String transactionId)Check whether a transaction has been recently processed through either a commit or rollback.protected booleanisTransactionAlreadyProcessed(Scn commitScn, Scn offsetCommitScn)Checks whether the transaction commit system change number has already been processed.protected booleanisTransactionUserExcluded(T transaction)Check whether the supplied username associated with the specified transaction is excluded.protected booleanisTrxIdRawValue()private LogMinerDmlEntryparseDmlStatement(String redoSql, Table table, String transactionId)Parse a DML redo SQL statement.private AbstractLogMinerEventProcessor.ParsedLobWriteSqlparseLobWriteSql(String sql)Parses aLOB_WRITEoperation SQL fragment.Scnprocess(OraclePartition partition, Scn startScn, Scn endScn)Process Oracle LogMiner events for a given system change number range.protected voidprocessResults(OraclePartition partition, ResultSet resultSet)Processes the LogMiner results.protected voidprocessRow(OraclePartition partition, LogMinerEventRow row)Processes a single LogMinerEventRow.private voidprocessTruncateEvent(LogMinerEventRow row)protected abstract voidremoveEventWithRowId(LogMinerEventRow row)Removes a specific transaction event by database row identifier.protected abstract voidremoveTransactionAndEventsFromCache(T transaction)Removes the transaction and all its associated event entries from the connector's caches.protected voidwarnPotentiallyStuckScn(Scn previousOffsetScn, Scn previousOffsetCommitScn)Checks to see whether the offset'sscnis remaining the same across multiple mining sessions while the offset'scommit_scnis changing between sessions.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.AutoCloseable
close
-
Methods inherited from interface io.debezium.connector.oracle.logminer.processor.LogMinerEventProcessor
abandonTransactions
-
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
context
private final ChangeEventSource.ChangeEventSourceContext context
-
connectorConfig
private final OracleConnectorConfig connectorConfig
-
schema
private final OracleDatabaseSchema schema
-
partition
private final OraclePartition partition
-
offsetContext
private final OracleOffsetContext offsetContext
-
dispatcher
private final EventDispatcher<OraclePartition,TableId> dispatcher
-
metrics
private final OracleStreamingChangeEventSourceMetrics metrics
-
dmlParser
private final LogMinerDmlParser dmlParser
-
selectLobParser
private final SelectLobParser selectLobParser
-
counters
protected final AbstractLogMinerEventProcessor.Counters counters
-
currentOffsetScn
private Scn currentOffsetScn
-
currentOffsetCommitScn
private Scn currentOffsetCommitScn
-
lastCommittedScn
private Scn lastCommittedScn
-
maxCommittedScn
private Scn maxCommittedScn
-
lastProcessedScn
private Scn lastProcessedScn
-
sequenceUnavailable
private boolean sequenceUnavailable
-
LOB_WRITE_SQL_PATTERN
private static Pattern LOB_WRITE_SQL_PATTERN
-
-
Constructor Detail
-
AbstractLogMinerEventProcessor
public AbstractLogMinerEventProcessor(ChangeEventSource.ChangeEventSourceContext context, OracleConnectorConfig connectorConfig, OracleDatabaseSchema schema, OraclePartition partition, OracleOffsetContext offsetContext, EventDispatcher<OraclePartition,TableId> dispatcher, OracleStreamingChangeEventSourceMetrics metrics)
-
-
Method Detail
-
getConfig
protected OracleConnectorConfig getConfig()
-
getSchema
protected OracleDatabaseSchema getSchema()
-
isRecentlyProcessed
protected boolean isRecentlyProcessed(String transactionId)
Check whether a transaction has been recently processed through either a commit or rollback.- Parameters:
transactionId- the unique transaction id- Returns:
- true if the transaction has been recently processed, false otherwise
-
hasSchemaChangeBeenSeen
protected boolean hasSchemaChangeBeenSeen(LogMinerEventRow row)
Checks whether the LogMinerEvent row for a schema change can be emitted.- Parameters:
row- the result set row- Returns:
- true if the schema change has been seen, false otherwise.
-
getLastProcessedScn
protected Scn getLastProcessedScn()
Return the last processed system change number handled by the processor.- Returns:
- the last processed system change number, never
null.
-
getTransactionCache
protected abstract Map<String,T> getTransactionCache()
Returns theTransactionCacheimplementation.- Returns:
- the transaction cache, never
null
-
createTransaction
protected abstract T createTransaction(LogMinerEventRow row)
Creates a new transaction based on the suppliedSTARTevent.- Parameters:
row- the event row, must not benull- Returns:
- the implementation-specific
Transactioninstance
-
removeEventWithRowId
protected abstract void removeEventWithRowId(LogMinerEventRow row)
Removes a specific transaction event by database row identifier.- Parameters:
row- the event row that contains the row identifier, must not benull
-
getTransactionEventCount
protected abstract int getTransactionEventCount(T transaction)
Returns the number of events associated with the specified transaction.- Parameters:
transaction- the transaction, must not benull- Returns:
- the number of events in the transaction
-
isTrxIdRawValue
protected boolean isTrxIdRawValue()
-
process
public Scn process(OraclePartition partition, Scn startScn, Scn endScn) throws SQLException, InterruptedException
Description copied from interface:LogMinerEventProcessorProcess Oracle LogMiner events for a given system change number range.- Specified by:
processin interfaceLogMinerEventProcessorstartScn- the starting system change number, must not benullendScn- the ending system change number, must not benull- Returns:
- the next iteration's starting system change number, never
null - Throws:
SQLExceptionInterruptedException
-
createQueryStatement
protected abstract PreparedStatement createQueryStatement() throws SQLException
Create the JDBC query that will be used to fetch the mining result set.- Returns:
- a prepared query statement, never
null - Throws:
SQLException- if a database exception occurred creating the statement
-
calculateNewStartScn
protected abstract Scn calculateNewStartScn(Scn endScn, Scn maxCommittedScn) throws InterruptedException
Calculates the new starting system change number based on the current processing range.- Parameters:
endScn- the end system change number for the previously mined range, nevernullmaxCommittedScn- the maximum committed system change number, nevernull- Returns:
- the system change number to start then next mining iteration from, never
null - Throws:
InterruptedException- if the current thread is interrupted
-
processResults
protected void processResults(OraclePartition partition, ResultSet resultSet) throws SQLException, InterruptedException
Processes the LogMiner results.- Parameters:
resultSet- the result set from a LogMiner query- Throws:
SQLException- if a database exception occurredInterruptedException- if the dispatcher was interrupted sending an event
-
processRow
protected void processRow(OraclePartition partition, LogMinerEventRow row) throws SQLException, InterruptedException
Processes a single LogMinerEventRow.- Parameters:
row- the event row, must not benull- Throws:
SQLException- if a database exception occurredInterruptedException- if the dispatcher was interrupted sending an event
-
handleMissingScn
protected void handleMissingScn(LogMinerEventRow row)
Handle processing a LogMinerEventRow for aMISSING_SCNevent.- Parameters:
row- the result set row
-
handleStart
protected void handleStart(LogMinerEventRow row)
Handle processing a LogMinerEventRow for aSTARTevent.- Parameters:
row- the result set row
-
handleCommit
protected void handleCommit(OraclePartition partition, LogMinerEventRow row) throws InterruptedException
Handle processing a LogMinerEventRow for aCOMMITevent.- Parameters:
row- the result set row- Throws:
InterruptedException- if the event dispatcher was interrupted sending events
-
isTransactionAlreadyProcessed
protected boolean isTransactionAlreadyProcessed(Scn commitScn, Scn offsetCommitScn)
Checks whether the transaction commit system change number has already been processed.- Parameters:
commitScn- the transaction's commit system change number, should not benulloffsetCommitScn- the current offsets commit system change number, should not benull- Returns:
- true if the transaction has been seen based on the offsets, false otherwise
-
getAndRemoveTransactionFromCache
protected abstract T getAndRemoveTransactionFromCache(String transactionId)
Gets a transaction instance from the transaction cache while also removing its cache entry.- Parameters:
transactionId- the transaction's unique identifier, should not benull- Returns:
- the transaction instance if found,
nullif the transaction wasn't found
-
removeTransactionAndEventsFromCache
protected abstract void removeTransactionAndEventsFromCache(T transaction)
Removes the transaction and all its associated event entries from the connector's caches.- Parameters:
transaction- the transaction instance, should never benull
-
getTransactionEventIterator
protected abstract Iterator<LogMinerEvent> getTransactionEventIterator(T transaction)
Get an iterator over the events that are part of the specified transaction.- Parameters:
transaction- the transaction instance, should never benull- Returns:
- an iterator over the transaction's events, never
null
-
finalizeTransactionCommit
protected abstract void finalizeTransactionCommit(String transactionId, Scn commitScn)
Finalizes the commit of a transaction.- Parameters:
transactionId- the transaction's unique identifier, should not benullcommitScn- the transaction's system change number, should not benull
-
isTransactionUserExcluded
protected boolean isTransactionUserExcluded(T transaction)
Check whether the supplied username associated with the specified transaction is excluded.- Parameters:
transaction- the transaction, nevernull- Returns:
- true if the transaction should be skipped; false if transaction should be emitted
-
handleRollback
protected void handleRollback(LogMinerEventRow row)
Handle processing a LogMinerEventRow for aROLLBACKevent.- Parameters:
row- the result set row
-
finalizeTransactionRollback
protected abstract void finalizeTransactionRollback(String transactionId, Scn rollbackScn)
Finalizes the rollback the specified transaction- Parameters:
transactionId- the unique transaction identifier, nevernullrollbackScn- the rollback transaction's system change number, nevernull
-
handleSchemaChange
protected void handleSchemaChange(LogMinerEventRow row) throws InterruptedException
Handle processing a LogMinerEventRow for aDDLevent.- Parameters:
row- the result set row- Throws:
InterruptedException- if the event dispatcher is interrupted sending the event
-
processTruncateEvent
private void processTruncateEvent(LogMinerEventRow row)
-
handleSelectLobLocator
protected void handleSelectLobLocator(LogMinerEventRow row)
Handle processing a LogMinerEventRow for aSEL_LOB_LOCATORevent.- Parameters:
row- the result set row
-
handleLobWrite
protected void handleLobWrite(LogMinerEventRow row)
Handle processing a LogMinerEventRow for aLOB_WRITEevent.- Parameters:
row- the result set row
-
handleLobErase
private void handleLobErase(LogMinerEventRow row)
Handle processing a LogMinerEventRow for aLOB_ERASEevent.- Parameters:
row- the result set row
-
handleDataEvent
protected void handleDataEvent(LogMinerEventRow row) throws SQLException, InterruptedException
Handle processing a LogMinerEventRow for aINSERT,UPDATE, orDELETEevent.- Parameters:
row- the result set row- Throws:
SQLException- if a database exception occursInterruptedException- if the dispatch of an event is interrupted
-
warnPotentiallyStuckScn
protected void warnPotentiallyStuckScn(Scn previousOffsetScn, Scn previousOffsetCommitScn)
Checks to see whether the offset'sscnis remaining the same across multiple mining sessions while the offset'scommit_scnis changing between sessions.- Parameters:
previousOffsetScn- the previous offset system change numberpreviousOffsetCommitScn- the previous offset commit system change number
-
getTableForDataEvent
private Table getTableForDataEvent(LogMinerEventRow row) throws SQLException, InterruptedException
- Throws:
SQLExceptionInterruptedException
-
hasNextWithMetricsUpdate
private boolean hasNextWithMetricsUpdate(ResultSet resultSet) throws SQLException
Checks whether the result-set has any more data available. When a new row is available, the streaming metrics is updated with the fetch timings.- Parameters:
resultSet- the result set to check if any more rows exist- Returns:
- true if another row exists, false otherwise
- Throws:
SQLException- if there was a database exception
-
addToTransaction
protected abstract void addToTransaction(String transactionId, LogMinerEventRow row, Supplier<LogMinerEvent> eventSupplier)
Add a transaction to the transaction map if allowed.- Parameters:
transactionId- the unqiue transaction idrow- the LogMiner event roweventSupplier- the supplier of the event to create if the event is allowed to be added
-
dispatchSchemaChangeEventAndGetTableForNewCapturedTable
private Table dispatchSchemaChangeEventAndGetTableForNewCapturedTable(TableId tableId, OracleOffsetContext offsetContext, EventDispatcher<OraclePartition,TableId> dispatcher) throws SQLException, InterruptedException
Dispatch a schema change event for a new table and get the newly created relational table model.- Parameters:
tableId- the unique table identifier, must not benulloffsetContext- the offset contextdispatcher- the event dispatcher- Returns:
- the relational table model
- Throws:
SQLException- if a database exception occurredInterruptedException- if the event dispatch was interrupted
-
getTableMetadataDdl
private String getTableMetadataDdl(TableId tableId) throws SQLException
Get the specified table's create DDL statement.- Parameters:
tableId- the table identifier, must not benull- Returns:
- the table's create DDL statement, never
null - Throws:
SQLException- if an exception occurred obtaining the DDL statement
-
parseDmlStatement
private LogMinerDmlEntry parseDmlStatement(String redoSql, Table table, String transactionId)
Parse a DML redo SQL statement.- Parameters:
redoSql- the redo SQL statementtable- the table the SQL statement is fortransactionId- the associated transaction id for the SQL statement- Returns:
- a parse object for the redo SQL statement
-
parseLobWriteSql
private AbstractLogMinerEventProcessor.ParsedLobWriteSql parseLobWriteSql(String sql)
Parses aLOB_WRITEoperation SQL fragment.- Parameters:
sql- sql statement- Returns:
- the parsed statement
- Throws:
io.debezium.DebeziumException- if an unexpected SQL fragment is provided that cannot be parsed
-
-