liangyepianzhou commented on a change in pull request #12219:
URL: https://github.com/apache/pulsar/pull/12219#discussion_r728025076
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/buffer/impl/TopicTransactionBuffer.java
##########
@@ -163,6 +174,34 @@ public void recoverExceptionally(Exception e) {
@Override
public CompletableFuture<Position> appendBufferToTxn(TxnID txnId, long
sequenceId, ByteBuf buffer) {
CompletableFuture<Position> completableFuture = new
CompletableFuture<>();
+ if (checkIfReady()){
+ addTxnEntry(completableFuture, txnId, buffer);
+ } else {
+ if (checkIfUnused() && changeToInitializingStateFromUnused()){
+ //`PulsarDecoder` will release this buffer in `finally` and
`takeSnapshot` is asynchronous
+ buffer.retain();
+ takeSnapshot().thenAccept(ignore -> {
+ changeToReadyState();
+ buffer.release();
+ timer.newTimeout(TopicTransactionBuffer.this,
+ takeSnapshotIntervalTime, TimeUnit.MILLISECONDS);
+ log.info("Topic {} take snapshot successfully when uses
TransactionBuffer at the first time",
+ this.topic.getName());
+ }).exceptionally(exception -> {
+ changeToUnUsedState();
+ buffer.release();
+ log.error("Topic {} fail to takeSnapshot before adding the
first message with transaction",
+ this.topic.getName(), exception);
+ return null;
+ });
+ }
+ completableFuture.completeExceptionally(new
TransactionBufferStatusException(this.topic.getName(),
Review comment:
If the state of TransactionBuffer is not Ready, we hope so
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]