@Beta
public interface TransactionBuffer
When committing transaction starts, the broker will append a `COMMITTED`
marker to the data partition first to mark the transaction is committed.
The broker knows the data ledger of the commit marker and calls #commitTxn(TxnID, long, long)
to commit and seal the buffer.
When the marker is appended to the data partition, all the entries are visible
to the consumers. So a transaction reader TransactionBufferReader will be
opened to read the entries when the broker sees the commit marker. There is a chance
broker crashes after writing the marker to data partition but before committing
the transaction in transaction buffer. That is fine. Because the transaction buffer
will fail opening the transaction buffer reader since the transaction is still marked
as open. The broker can keep retry until the TC (transaction coordinator) eventually
commits the buffer again.
| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<Void> |
abortTxn(org.apache.pulsar.client.api.transaction.TxnID txnID,
List<org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData> sendMessageIdList)
Abort the transaction and all the entries of this transaction will
be discarded.
|
CompletableFuture<Position> |
appendBufferToTxn(org.apache.pulsar.client.api.transaction.TxnID txnId,
long sequenceId,
io.netty.buffer.ByteBuf buffer)
Append the buffer to the transaction buffer.
|
CompletableFuture<Void> |
closeAsync()
Close the buffer asynchronously.
|
CompletableFuture<Void> |
commitTxn(org.apache.pulsar.client.api.transaction.TxnID txnID,
List<org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData> sendMessageIdList)
Commit the transaction and seal the buffer for this transaction.
|
CompletableFuture<TransactionMeta> |
getTransactionMeta(org.apache.pulsar.client.api.transaction.TxnID txnID)
Return the metadata of a transaction in the buffer.
|
CompletableFuture<TransactionBufferReader> |
openTransactionBufferReader(org.apache.pulsar.client.api.transaction.TxnID txnID,
long startSequenceId)
Open a
TransactionBufferReader to read entries of a given transaction
starting from the provided sequenceId. |
CompletableFuture<Void> |
purgeTxns(List<Long> dataLedgers)
Purge all the data of the transactions who are committed and stored
in the provided data ledgers.
|
CompletableFuture<TransactionMeta> getTransactionMeta(org.apache.pulsar.client.api.transaction.TxnID txnID)
txnID - the transaction idTransactionNotFoundException - if the transaction
is not in the buffer.CompletableFuture<Position> appendBufferToTxn(org.apache.pulsar.client.api.transaction.TxnID txnId, long sequenceId, io.netty.buffer.ByteBuf buffer)
The entry will be indexed by txnId and sequenceId.
txnId - the transaction idsequenceId - the sequence id of the entry in this transaction buffer.buffer - the entry bufferTransactionSealedException - if the transaction
has been sealed.CompletableFuture<TransactionBufferReader> openTransactionBufferReader(org.apache.pulsar.client.api.transaction.TxnID txnID, long startSequenceId)
TransactionBufferReader to read entries of a given transaction
starting from the provided sequenceId.txnID - transaction idstartSequenceId - the sequence id to start readTransactionNotFoundException - if the transaction
is not in the buffer.CompletableFuture<Void> commitTxn(org.apache.pulsar.client.api.transaction.TxnID txnID, List<org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData> sendMessageIdList)
If a transaction is sealed, no more entries can be appendBufferToTxn(TxnID, long, ByteBuf).
txnID - the transaction idTransactionNotFoundException - if the transaction
is not in the buffer.CompletableFuture<Void> abortTxn(org.apache.pulsar.client.api.transaction.TxnID txnID, List<org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData> sendMessageIdList)
txnID - the transaction idTransactionNotFoundException - if the transaction
is not in the buffer.CompletableFuture<Void> purgeTxns(List<Long> dataLedgers)
This method will be called by the broker before they delete the ledgers. It ensures that all the transactions committed in those ledgers can be purged.
dataLedgers - the list of data ledgers.CompletableFuture<Void> closeAsync()
Copyright © 2017–2021 Apache Software Foundation. All rights reserved.