Package io.debezium.pipeline.txmetadata
Class TransactionMonitor
- java.lang.Object
-
- io.debezium.pipeline.txmetadata.TransactionMonitor
-
@NotThreadSafe public class TransactionMonitor extends Object
The class has externalized its state inTransactionContextcontext class so it can be stored in and recovered from offsets. The class receives all processed events and keeps the transaction tracking depending on transaction id. Upon transaction change the metadata events are delivered to a dedicated topic informing aboutSTART/ENDof the transaction, including transaction id and in case ofENDevent the amount of events generated by the transaction.Every event seen has its
sourceblock enriched to contain- transaction id
- the total event order in the transaction
- the order of event per table/collection source in the transaction
- Author:
- Jiri Pechanec
-
-
Field Summary
Fields Modifier and Type Field Description private CommonConnectorConfigconnectorConfigstatic StringDEBEZIUM_TRANSACTION_COLLECTION_KEYstatic StringDEBEZIUM_TRANSACTION_DATA_COLLECTION_ORDER_KEYstatic StringDEBEZIUM_TRANSACTION_DATA_COLLECTIONS_KEYstatic StringDEBEZIUM_TRANSACTION_EVENT_COUNT_KEYstatic StringDEBEZIUM_TRANSACTION_ID_KEYstatic StringDEBEZIUM_TRANSACTION_KEYstatic StringDEBEZIUM_TRANSACTION_STATUS_KEYstatic StringDEBEZIUM_TRANSACTION_TOTAL_ORDER_KEYprivate static org.apache.kafka.connect.data.SchemaEVENT_COUNT_PER_DATA_COLLECTION_SCHEMAprivate EventMetadataProvidereventMetadataProviderprivate static org.slf4j.LoggerLOGGERprivate BlockingConsumer<org.apache.kafka.connect.source.SourceRecord>senderprivate StringtopicNamestatic org.apache.kafka.connect.data.SchemaTRANSACTION_BLOCK_SCHEMAprivate org.apache.kafka.connect.data.SchematransactionKeySchemaprivate org.apache.kafka.connect.data.SchematransactionValueSchema
-
Constructor Summary
Constructors Constructor Description TransactionMonitor(CommonConnectorConfig connectorConfig, EventMetadataProvider eventMetadataProvider, SchemaNameAdjuster schemaNameAdjuster, BlockingConsumer<org.apache.kafka.connect.source.SourceRecord> sender)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidbeginTransaction(Partition partition, OffsetContext offsetContext)voiddataEvent(Partition partition, DataCollectionId source, OffsetContext offset, Object key, org.apache.kafka.connect.data.Struct value)private voidendTransaction(Partition partition, OffsetContext offsetContext)voidtransactionComittedEvent(Partition partition, OffsetContext offset)private voidtransactionEvent(OffsetContext offsetContext, DataCollectionId source, org.apache.kafka.connect.data.Struct value)voidtransactionStartedEvent(Partition partition, String transactionId, OffsetContext offset)
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
DEBEZIUM_TRANSACTION_KEY
public static final String DEBEZIUM_TRANSACTION_KEY
- See Also:
- Constant Field Values
-
DEBEZIUM_TRANSACTION_ID_KEY
public static final String DEBEZIUM_TRANSACTION_ID_KEY
- See Also:
- Constant Field Values
-
DEBEZIUM_TRANSACTION_TOTAL_ORDER_KEY
public static final String DEBEZIUM_TRANSACTION_TOTAL_ORDER_KEY
- See Also:
- Constant Field Values
-
DEBEZIUM_TRANSACTION_DATA_COLLECTION_ORDER_KEY
public static final String DEBEZIUM_TRANSACTION_DATA_COLLECTION_ORDER_KEY
- See Also:
- Constant Field Values
-
DEBEZIUM_TRANSACTION_STATUS_KEY
public static final String DEBEZIUM_TRANSACTION_STATUS_KEY
- See Also:
- Constant Field Values
-
DEBEZIUM_TRANSACTION_EVENT_COUNT_KEY
public static final String DEBEZIUM_TRANSACTION_EVENT_COUNT_KEY
- See Also:
- Constant Field Values
-
DEBEZIUM_TRANSACTION_COLLECTION_KEY
public static final String DEBEZIUM_TRANSACTION_COLLECTION_KEY
- See Also:
- Constant Field Values
-
DEBEZIUM_TRANSACTION_DATA_COLLECTIONS_KEY
public static final String DEBEZIUM_TRANSACTION_DATA_COLLECTIONS_KEY
- See Also:
- Constant Field Values
-
TRANSACTION_BLOCK_SCHEMA
public static final org.apache.kafka.connect.data.Schema TRANSACTION_BLOCK_SCHEMA
-
EVENT_COUNT_PER_DATA_COLLECTION_SCHEMA
private static final org.apache.kafka.connect.data.Schema EVENT_COUNT_PER_DATA_COLLECTION_SCHEMA
-
transactionKeySchema
private final org.apache.kafka.connect.data.Schema transactionKeySchema
-
transactionValueSchema
private final org.apache.kafka.connect.data.Schema transactionValueSchema
-
eventMetadataProvider
private final EventMetadataProvider eventMetadataProvider
-
topicName
private final String topicName
-
sender
private final BlockingConsumer<org.apache.kafka.connect.source.SourceRecord> sender
-
connectorConfig
private final CommonConnectorConfig connectorConfig
-
-
Constructor Detail
-
TransactionMonitor
public TransactionMonitor(CommonConnectorConfig connectorConfig, EventMetadataProvider eventMetadataProvider, SchemaNameAdjuster schemaNameAdjuster, BlockingConsumer<org.apache.kafka.connect.source.SourceRecord> sender)
-
-
Method Detail
-
dataEvent
public void dataEvent(Partition partition, DataCollectionId source, OffsetContext offset, Object key, org.apache.kafka.connect.data.Struct value) throws InterruptedException
- Throws:
InterruptedException
-
transactionComittedEvent
public void transactionComittedEvent(Partition partition, OffsetContext offset) throws InterruptedException
- Throws:
InterruptedException
-
transactionStartedEvent
public void transactionStartedEvent(Partition partition, String transactionId, OffsetContext offset) throws InterruptedException
- Throws:
InterruptedException
-
transactionEvent
private void transactionEvent(OffsetContext offsetContext, DataCollectionId source, org.apache.kafka.connect.data.Struct value)
-
beginTransaction
private void beginTransaction(Partition partition, OffsetContext offsetContext) throws InterruptedException
- Throws:
InterruptedException
-
endTransaction
private void endTransaction(Partition partition, OffsetContext offsetContext) throws InterruptedException
- Throws:
InterruptedException
-
-