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 inTransactionContext
context 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/END
of the transaction, including transaction id and in case ofEND
event the amount of events generated by the transaction.Every event seen has its
source
block 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 CommonConnectorConfig
connectorConfig
static String
DEBEZIUM_TRANSACTION_COLLECTION_KEY
static String
DEBEZIUM_TRANSACTION_DATA_COLLECTION_ORDER_KEY
static String
DEBEZIUM_TRANSACTION_DATA_COLLECTIONS_KEY
static String
DEBEZIUM_TRANSACTION_EVENT_COUNT_KEY
static String
DEBEZIUM_TRANSACTION_ID_KEY
static String
DEBEZIUM_TRANSACTION_KEY
static String
DEBEZIUM_TRANSACTION_STATUS_KEY
static String
DEBEZIUM_TRANSACTION_TOTAL_ORDER_KEY
private static org.apache.kafka.connect.data.Schema
EVENT_COUNT_PER_DATA_COLLECTION_SCHEMA
private EventMetadataProvider
eventMetadataProvider
private static org.slf4j.Logger
LOGGER
private BlockingConsumer<org.apache.kafka.connect.source.SourceRecord>
sender
private String
topicName
static org.apache.kafka.connect.data.Schema
TRANSACTION_BLOCK_SCHEMA
private org.apache.kafka.connect.data.Schema
transactionKeySchema
private org.apache.kafka.connect.data.Schema
transactionValueSchema
-
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 void
beginTransaction(Partition partition, OffsetContext offsetContext)
void
dataEvent(Partition partition, DataCollectionId source, OffsetContext offset, Object key, org.apache.kafka.connect.data.Struct value)
private void
endTransaction(Partition partition, OffsetContext offsetContext)
void
transactionComittedEvent(Partition partition, OffsetContext offset)
private void
transactionEvent(OffsetContext offsetContext, DataCollectionId source, org.apache.kafka.connect.data.Struct value)
void
transactionStartedEvent(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
-
-