@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,
long lowWaterMark)
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> |
checkIfTBRecoverCompletely(boolean isTxn)
Wait TransactionBuffer Recovers completely.
|
CompletableFuture<Void> |
clearSnapshot()
Clear up the snapshot of the TransactionBuffer.
|
CompletableFuture<Void> |
closeAsync()
Close the buffer asynchronously.
|
CompletableFuture<Void> |
commitTxn(org.apache.pulsar.client.api.transaction.TxnID txnID,
long lowWaterMark)
Commit the transaction and seal the buffer for this transaction.
|
PositionImpl |
getMaxReadPosition()
Get the can read max position.
|
org.apache.pulsar.common.policies.data.TransactionBufferStats |
getStats()
Get transaction stats in buffer.
|
org.apache.pulsar.common.policies.data.TransactionInBufferStats |
getTransactionInBufferStats(org.apache.pulsar.client.api.transaction.TxnID txnID)
Get transaction in buffer stats.
|
CompletableFuture<TransactionMeta> |
getTransactionMeta(org.apache.pulsar.client.api.transaction.TxnID txnID)
Return the metadata of a transaction in the buffer.
|
boolean |
isTxnAborted(org.apache.pulsar.client.api.transaction.TxnID txnID)
Close the buffer asynchronously.
|
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.
|
void |
syncMaxReadPositionForNormalPublish(PositionImpl position)
Sync max read position for normal publish.
|
CompletableFuture<TransactionMeta> getTransactionMeta(org.apache.pulsar.client.api.transaction.TxnID txnID)
txnID - the transaction idorg.apache.pulsar.broker.transaction.buffer.exceptions.TransactionNotFoundException - 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 bufferorg.apache.pulsar.broker.transaction.buffer.exceptions.TransactionSealedException - 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 readorg.apache.pulsar.broker.transaction.buffer.exceptions.TransactionNotFoundException - if the transaction
is not in the buffer.CompletableFuture<Void> commitTxn(org.apache.pulsar.client.api.transaction.TxnID txnID, long lowWaterMark)
If a transaction is sealed, no more entries can be appendBufferToTxn(TxnID, long, ByteBuf).
txnID - the transaction idlowWaterMark - the low water mark of this transactionorg.apache.pulsar.broker.transaction.buffer.exceptions.TransactionNotFoundException - if the transaction
is not in the buffer.CompletableFuture<Void> abortTxn(org.apache.pulsar.client.api.transaction.TxnID txnID, long lowWaterMark)
txnID - the transaction idlowWaterMark - the low water mark of this transactionorg.apache.pulsar.broker.transaction.buffer.exceptions.TransactionNotFoundException - 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> clearSnapshot()
CompletableFuture<Void> closeAsync()
boolean isTxnAborted(org.apache.pulsar.client.api.transaction.TxnID txnID)
txnID - TxnID txnId.void syncMaxReadPositionForNormalPublish(PositionImpl position)
position - PositionImpl the position to sync.PositionImpl getMaxReadPosition()
org.apache.pulsar.common.policies.data.TransactionInBufferStats getTransactionInBufferStats(org.apache.pulsar.client.api.transaction.TxnID txnID)
org.apache.pulsar.common.policies.data.TransactionBufferStats getStats()
CompletableFuture<Void> checkIfTBRecoverCompletely(boolean isTxn)
isTxn - Copyright © 2017–2022 Apache Software Foundation. All rights reserved.