Class TopicTransactionBuffer

java.lang.Object
org.apache.pulsar.broker.transaction.buffer.impl.TopicTransactionBufferState
org.apache.pulsar.broker.transaction.buffer.impl.TopicTransactionBuffer
All Implemented Interfaces:
io.netty.util.TimerTask, TransactionBuffer

public class TopicTransactionBuffer extends TopicTransactionBufferState implements TransactionBuffer, io.netty.util.TimerTask
Transaction buffer based on normal persistent topic.
  • Field Details

    • recoverTime

      public final org.apache.pulsar.common.util.RecoverTimeRecord recoverTime
  • Constructor Details

    • TopicTransactionBuffer

      public TopicTransactionBuffer(PersistentTopic topic)
  • Method Details

    • getTransactionMeta

      public CompletableFuture<TransactionMeta> getTransactionMeta(org.apache.pulsar.client.api.transaction.TxnID txnID)
      Description copied from interface: TransactionBuffer
      Return the metadata of a transaction in the buffer.
      Specified by:
      getTransactionMeta in interface TransactionBuffer
      Parameters:
      txnID - the transaction id
      Returns:
      a future represents the result of the operation
    • checkIfTBRecoverCompletely

      public CompletableFuture<Void> checkIfTBRecoverCompletely(boolean isTxnEnabled)
      Description copied from interface: TransactionBuffer
      Wait TransactionBuffer Recovers completely. Take snapshot after TB Recovers completely.
      Specified by:
      checkIfTBRecoverCompletely in interface TransactionBuffer
      Returns:
      a future which has completely if isTxn = false. Or a future return by takeSnapshot.
    • getOngoingTxnCount

      public long getOngoingTxnCount()
      Specified by:
      getOngoingTxnCount in interface TransactionBuffer
    • getAbortedTxnCount

      public long getAbortedTxnCount()
      Specified by:
      getAbortedTxnCount in interface TransactionBuffer
    • getCommittedTxnCount

      public long getCommittedTxnCount()
      Specified by:
      getCommittedTxnCount in interface TransactionBuffer
    • appendBufferToTxn

      public CompletableFuture<org.apache.bookkeeper.mledger.Position> appendBufferToTxn(org.apache.pulsar.client.api.transaction.TxnID txnId, long sequenceId, io.netty.buffer.ByteBuf buffer)
      Description copied from interface: TransactionBuffer
      Append the buffer to the transaction buffer.

      The entry will be indexed by txnId and sequenceId.

      Specified by:
      appendBufferToTxn in interface TransactionBuffer
      Parameters:
      txnId - the transaction id
      sequenceId - the sequence id of the entry in this transaction buffer.
      buffer - the entry buffer
      Returns:
      a future represents the result of the operation.
    • openTransactionBufferReader

      public CompletableFuture<TransactionBufferReader> openTransactionBufferReader(org.apache.pulsar.client.api.transaction.TxnID txnID, long startSequenceId)
      Description copied from interface: TransactionBuffer
      Open a TransactionBufferReader to read entries of a given transaction starting from the provided sequenceId.
      Specified by:
      openTransactionBufferReader in interface TransactionBuffer
      Parameters:
      txnID - transaction id
      startSequenceId - the sequence id to start read
      Returns:
      a future represents the result of open operation.
    • commitTxn

      public CompletableFuture<Void> commitTxn(org.apache.pulsar.client.api.transaction.TxnID txnID, long lowWaterMark)
      Description copied from interface: TransactionBuffer
      Commit the transaction and seal the buffer for this transaction.

      If a transaction is sealed, no more entries can be TransactionBuffer.appendBufferToTxn(TxnID, long, ByteBuf).

      Specified by:
      commitTxn in interface TransactionBuffer
      Parameters:
      txnID - the transaction id
      lowWaterMark - the low water mark of this transaction
      Returns:
      a future represents the result of commit operation.
    • abortTxn

      public CompletableFuture<Void> abortTxn(org.apache.pulsar.client.api.transaction.TxnID txnID, long lowWaterMark)
      Description copied from interface: TransactionBuffer
      Abort the transaction and all the entries of this transaction will be discarded.
      Specified by:
      abortTxn in interface TransactionBuffer
      Parameters:
      txnID - the transaction id
      lowWaterMark - the low water mark of this transaction
      Returns:
      a future represents the result of abort operation.
    • purgeTxns

      public CompletableFuture<Void> purgeTxns(List<Long> dataLedgers)
      Description copied from interface: TransactionBuffer
      Purge all the data of the transactions who are committed and stored in the provided data ledgers.

      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.

      Specified by:
      purgeTxns in interface TransactionBuffer
      Parameters:
      dataLedgers - the list of data ledgers.
      Returns:
      a future represents the result of purge operations.
    • clearSnapshot

      public CompletableFuture<Void> clearSnapshot()
      Description copied from interface: TransactionBuffer
      Clear up the snapshot of the TransactionBuffer.
      Specified by:
      clearSnapshot in interface TransactionBuffer
      Returns:
      Clear up operation result.
    • closeAsync

      public CompletableFuture<Void> closeAsync()
      Description copied from interface: TransactionBuffer
      Close the buffer asynchronously.
      Specified by:
      closeAsync in interface TransactionBuffer
      Returns:
    • isTxnAborted

      public boolean isTxnAborted(org.apache.pulsar.client.api.transaction.TxnID txnID)
      Description copied from interface: TransactionBuffer
      Close the buffer asynchronously.
      Specified by:
      isTxnAborted in interface TransactionBuffer
      Parameters:
      txnID - TxnID txnId.
      Returns:
      the txnId is aborted.
    • syncMaxReadPositionForNormalPublish

      public void syncMaxReadPositionForNormalPublish(org.apache.bookkeeper.mledger.impl.PositionImpl position)
      Description copied from interface: TransactionBuffer
      Sync max read position for normal publish.
      Specified by:
      syncMaxReadPositionForNormalPublish in interface TransactionBuffer
      Parameters:
      position - PositionImpl the position to sync.
    • getMaxReadPosition

      public org.apache.bookkeeper.mledger.impl.PositionImpl getMaxReadPosition()
      Description copied from interface: TransactionBuffer
      Get the can read max position.
      Specified by:
      getMaxReadPosition in interface TransactionBuffer
      Returns:
      the stable position.
    • getTransactionInBufferStats

      public org.apache.pulsar.common.policies.data.TransactionInBufferStats getTransactionInBufferStats(org.apache.pulsar.client.api.transaction.TxnID txnID)
      Description copied from interface: TransactionBuffer
      Get transaction in buffer stats.
      Specified by:
      getTransactionInBufferStats in interface TransactionBuffer
      Returns:
      the transaction in buffer stats.
    • getStats

      public org.apache.pulsar.common.policies.data.TransactionBufferStats getStats(boolean lowWaterMarks)
      Description copied from interface: TransactionBuffer
      Get transaction stats in buffer.
      Specified by:
      getStats in interface TransactionBuffer
      Returns:
      the transaction stats in buffer.
    • run

      public void run(io.netty.util.Timeout timeout)
      Specified by:
      run in interface io.netty.util.TimerTask