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 of
LogMinerEventProcessor that all processors should extend.- Author:
- Chris Cranford
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classWrapper for all counter variablesprivate class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final OracleConnectorConfigprivate final ChangeEventSource.ChangeEventSourceContextprotected final AbstractLogMinerEventProcessor<T>.Countersprivate Scnprivate final EventDispatcher<OraclePartition,TableId> private final LogMinerDmlParserprivate Scnprivate static Patternprivate static final org.slf4j.Loggerprivate final OracleStreamingChangeEventSourceMetricsprivate static final Stringprivate final OracleOffsetContextprivate final OraclePartitionprivate final OracleDatabaseSchemaprivate final SelectLobParserprivate boolean -
Constructor Summary
ConstructorsConstructorDescriptionAbstractLogMinerEventProcessor(ChangeEventSource.ChangeEventSourceContext context, OracleConnectorConfig connectorConfig, OracleDatabaseSchema schema, OraclePartition partition, OracleOffsetContext offsetContext, EventDispatcher<OraclePartition, TableId> dispatcher, OracleStreamingChangeEventSourceMetrics metrics) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidabandonTransactionOverEventThreshold(T transaction) 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 PreparedStatementCreate the JDBC query that will be used to fetch the mining result set.protected abstract TCreates 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 OracleConnectorConfigprotected ScnReturn the last processed system change number handled by the processor.protected OracleDatabaseSchemaprivate Tableprivate StringgetTableMetadataDdl(TableId tableId) Get the specified table's create DDL statement.Returns theTransactionCacheimplementation.protected abstract ScnGets 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 StringgetTransactionIdPrefix(String transactionId) protected voidhandleCommit(OraclePartition partition, LogMinerEventRow row) Handle processing a LogMinerEventRow for aCOMMITevent.protected voidHandle processing a LogMinerEventRow for aINSERT,UPDATE, orDELETEevent.private voidHandle processing a LogMinerEventRow for aLOB_ERASEevent.protected voidHandle processing a LogMinerEventRow for aLOB_WRITEevent.protected voidHandle processing a LogMinerEventRow for aMISSING_SCNevent.protected voidHandle processing a LogMinerEventRow for aROLLBACKevent.protected voidHandle processing a LogMinerEventRow for aDDLevent.protected voidHandle processing a LogMinerEventRow for aSEL_LOB_LOCATORevent.protected voidHandle processing a LogMinerEventRow for aSTARTevent.protected voidprivate booleanhasNextWithMetricsUpdate(ResultSet resultSet) Checks whether the result-set has any more data available.protected booleanChecks 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 booleanisTransactionIdWithNoSequence(String transactionId) Returns whether the transaction id has no sequence number component.protected booleanisTransactionOverEventThreshold(T transaction) protected booleanisTransactionUserExcluded(T transaction) Check whether the supplied username associated with the specified transaction is excluded.protected booleanprivate LogMinerDmlEntryparseDmlStatement(String redoSql, Table table) Parse a DML redo SQL statement.parseLobWriteSql(String sql) Parses aLOB_WRITEoperation SQL fragment.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 voidprotected abstract voidRemoves 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, Map<Integer, Scn> previousOffsetCommitScns) 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, waitMethods inherited from interface java.lang.AutoCloseable
closeMethods inherited from interface io.debezium.connector.oracle.logminer.processor.LogMinerEventProcessor
abandonTransactions
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
NO_SEQUENCE_TRX_ID_SUFFIX
- See Also:
-
context
-
connectorConfig
-
schema
-
partition
-
offsetContext
-
dispatcher
-
metrics
-
dmlParser
-
selectLobParser
-
counters
-
currentOffsetScn
-
currentOffsetCommitScns
-
lastProcessedScn
-
LOB_WRITE_SQL_PATTERN
-
-
Constructor Details
-
AbstractLogMinerEventProcessor
public AbstractLogMinerEventProcessor(ChangeEventSource.ChangeEventSourceContext context, OracleConnectorConfig connectorConfig, OracleDatabaseSchema schema, OraclePartition partition, OracleOffsetContext offsetContext, EventDispatcher<OraclePartition, TableId> dispatcher, OracleStreamingChangeEventSourceMetrics metrics)
-
-
Method Details
-
getConfig
-
getSchema
-
isRecentlyProcessed
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
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
Return the last processed system change number handled by the processor.- Returns:
- the last processed system change number, never
null.
-
getTransactionCache
Returns theTransactionCacheimplementation.- Returns:
- the transaction cache, never
null
-
createTransaction
Creates a new transaction based on the suppliedSTARTevent.- Parameters:
row- the event row, must not benull- Returns:
- the implementation-specific
Transactioninstance
-
removeEventWithRowId
Removes a specific transaction event by database row identifier.- Parameters:
row- the event row that contains the row identifier, must not benull
-
getTransactionEventCount
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
Description copied from interface:LogMinerEventProcessorProcess Oracle LogMiner events for a given system change number range.- Specified by:
processin interfaceLogMinerEventProcessor- Parameters:
startScn- 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
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
Handle processing a LogMinerEventRow for aMISSING_SCNevent.- Parameters:
row- the result set row
-
handleStart
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
-
getAndRemoveTransactionFromCache
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
Removes the transaction and all its associated event entries from the connector's caches.- Parameters:
transaction- the transaction instance, should never benull
-
getTransactionEventIterator
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
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
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
Handle processing a LogMinerEventRow for aROLLBACKevent.- Parameters:
row- the result set row
-
finalizeTransactionRollback
Finalizes the rollback the specified transaction- Parameters:
transactionId- the unique transaction identifier, nevernullrollbackScn- the rollback transaction's system change number, nevernull
-
handleSchemaChange
Handle processing a LogMinerEventRow for aDDLevent.- Parameters:
row- the result set row- Throws:
InterruptedException- if the event dispatcher is interrupted sending the event
-
processTruncateEvent
-
handleSelectLobLocator
Handle processing a LogMinerEventRow for aSEL_LOB_LOCATORevent.- Parameters:
row- the result set row
-
handleLobWrite
Handle processing a LogMinerEventRow for aLOB_WRITEevent.- Parameters:
row- the result set row
-
handleLobErase
Handle processing a LogMinerEventRow for aLOB_ERASEevent.- Parameters:
row- the result set row
-
handleDataEvent
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
-
handleUnsupportedEvent
-
warnPotentiallyStuckScn
protected void warnPotentiallyStuckScn(Scn previousOffsetScn, Map<Integer, Scn> previousOffsetCommitScns) 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 numberpreviousOffsetCommitScns- the previous offset commit system change number
-
getTableForDataEvent
- Throws:
SQLExceptionInterruptedException
-
hasNextWithMetricsUpdate
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, InterruptedExceptionDispatch 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
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
Parse a DML redo SQL statement.- Parameters:
redoSql- the redo SQL statementtable- the table the SQL statement is for- Returns:
- a parse object for the redo SQL statement
-
parseLobWriteSql
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
-
getTransactionCacheMinimumScn
Gets the minimum system change number stored in the transaction cache.- Returns:
- the minimum system change number, never
nullbut could beScn.NULL.
-
isTransactionIdWithNoSequence
Returns whether the transaction id has no sequence number component. Oracle transaction identifiers are a composite of:- Undo segment number
- Slot numbber of the transaction that generated the change
- Sequence number of the transaction that generated the change
true; otherwise returnsfalse.- Parameters:
transactionId- the transaction identifier to check, should not benull- Returns:
- true if the transaction has no sequence reference, false if it does
-
getTransactionIdPrefix
-
isTransactionOverEventThreshold
-
abandonTransactionOverEventThreshold
-