Class TransactionalBuffer
- java.lang.Object
-
- io.debezium.connector.oracle.logminer.TransactionalBuffer
-
- All Implemented Interfaces:
AutoCloseable
@NotThreadSafe public final class TransactionalBuffer extends Object implements AutoCloseable
Buffer that stores transactions and related callbacks that will be executed when a transaction commits or discarded when a transaction has been rolled back.- Author:
- Andrey Pustovetov
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceTransactionalBuffer.CommitCallbackCallback is designed to execute when transaction commits.private static classTransactionalBuffer.Transaction
-
Field Summary
Fields Modifier and Type Field Description private Set<String>abandonedTransactionIdsprivate ErrorHandlererrorHandlerprivate ScnlastCommittedScnprivate static org.slf4j.LoggerLOGGERprivate Set<String>rolledBackTransactionIdsprivate OracleStreamingChangeEventSourceMetricsstreamingMetricsprivate Map<String,TransactionalBuffer.Transaction>transactions
-
Constructor Summary
Constructors Constructor Description TransactionalBuffer(ErrorHandler errorHandler, OracleStreamingChangeEventSourceMetrics streamingMetrics)Constructor to create a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidabandonLongTransactions(Scn thresholdScn, OracleOffsetContext offsetContext)If for some reason the connector got restarted, the offset will point to the beginning of the oldest captured transaction.private ScncalculateSmallestScn()voidclose()private voidcommit(ChangeEventSource.ChangeEventSourceContext context, OracleOffsetContext offsetContext, Instant start, List<TransactionalBuffer.CommitCallback> commitCallbacks, Timestamp timestamp, Scn smallestScn, Scn scn, EventDispatcher<?> dispatcher)(package private) booleancommit(String transactionId, Scn scn, OracleOffsetContext offsetContext, Timestamp timestamp, ChangeEventSource.ChangeEventSourceContext context, String debugMessage, EventDispatcher dispatcher)Commits a transaction by looking up the transaction in the buffer and if exists, all registered callbacks will be executed in chronological order, emitting events for each followed by a transaction commit event.(package private) Set<String>getRolledBackTransactionIds()(package private) booleanisEmpty()Returnstrueif buffer is empty, otherwisefalse.(package private) booleanisTransactionRegistered(String txId)(package private) voidregisterCommitCallback(String transactionId, Scn scn, Instant changeTime, TransactionalBuffer.CommitCallback callback)Registers callback to execute when transaction commits.(package private) booleanrollback(String transactionId, String debugMessage)Clears registered callbacks for given transaction identifier.(package private) voidsetDatabaseTimeDifference(long difference)Set the database time difference.StringtoString()
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
transactions
private final Map<String,TransactionalBuffer.Transaction> transactions
-
errorHandler
private final ErrorHandler errorHandler
-
streamingMetrics
private final OracleStreamingChangeEventSourceMetrics streamingMetrics
-
lastCommittedScn
private Scn lastCommittedScn
-
-
Constructor Detail
-
TransactionalBuffer
TransactionalBuffer(ErrorHandler errorHandler, OracleStreamingChangeEventSourceMetrics streamingMetrics)
Constructor to create a new instance.- Parameters:
errorHandler- the connector error handlerstreamingMetrics- the streaming metrics
-
-
Method Detail
-
getRolledBackTransactionIds
Set<String> getRolledBackTransactionIds()
- Returns:
- rolled back transactions
-
registerCommitCallback
void registerCommitCallback(String transactionId, Scn scn, Instant changeTime, TransactionalBuffer.CommitCallback callback)
Registers callback to execute when transaction commits.- Parameters:
transactionId- transaction identifierscn- SCNchangeTime- time of DML parsing completioncallback- callback to execute when transaction commits
-
commit
boolean commit(String transactionId, Scn scn, OracleOffsetContext offsetContext, Timestamp timestamp, ChangeEventSource.ChangeEventSourceContext context, String debugMessage, EventDispatcher dispatcher)
Commits a transaction by looking up the transaction in the buffer and if exists, all registered callbacks will be executed in chronological order, emitting events for each followed by a transaction commit event.- Parameters:
transactionId- transaction identifierscn- SCN of the commit.offsetContext- Oracle offsettimestamp- commit timestampcontext- context to check that source is runningdebugMessage- messagedispatcher- event dispatcher- Returns:
- true if committed transaction is in the buffer, was not processed yet and processed now
-
commit
private void commit(ChangeEventSource.ChangeEventSourceContext context, OracleOffsetContext offsetContext, Instant start, List<TransactionalBuffer.CommitCallback> commitCallbacks, Timestamp timestamp, Scn smallestScn, Scn scn, EventDispatcher<?> dispatcher)
-
rollback
boolean rollback(String transactionId, String debugMessage)
Clears registered callbacks for given transaction identifier.- Parameters:
transactionId- transaction iddebugMessage- message- Returns:
- true if the rollback is for a transaction in the buffer
-
abandonLongTransactions
void abandonLongTransactions(Scn thresholdScn, OracleOffsetContext offsetContext)
If for some reason the connector got restarted, the offset will point to the beginning of the oldest captured transaction. If that transaction was lasted for a long time, let say > 4 hours, the offset might be not accessible after restart, Hence we have to address these cases manually.In case of an abandonment, all DMLs/Commits/Rollbacks for this transaction will be ignored
- Parameters:
thresholdScn- the smallest SVN of any transaction to keep in the buffer. All others will be removed.offsetContext- the offset context
-
isTransactionRegistered
boolean isTransactionRegistered(String txId)
-
calculateSmallestScn
private Scn calculateSmallestScn()
-
isEmpty
boolean isEmpty()
Returnstrueif buffer is empty, otherwisefalse.- Returns:
trueif buffer is empty, otherwisefalse
-
setDatabaseTimeDifference
void setDatabaseTimeDifference(long difference)
Set the database time difference.- Parameters:
difference- the time difference in milliseconds
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable
-
-