congbobo184 commented on a change in pull request #12219:
URL: https://github.com/apache/pulsar/pull/12219#discussion_r726770905
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/buffer/impl/TopicTransactionBufferState.java
##########
@@ -49,10 +50,22 @@ protected boolean changeToReadyState() {
return (STATE_UPDATER.compareAndSet(this, State.Initializing,
State.Ready));
}
+ protected boolean changeToUnUsedState() {
+ return (STATE_UPDATER.compareAndSet(this, State.Initializing,
State.Unused));
+ }
+
+ protected boolean changeBackToUnUsedState() {
Review comment:
the same as changeToUnUsedState
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/buffer/impl/TopicTransactionBuffer.java
##########
@@ -163,6 +175,37 @@ 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()){
+ if (changeToInitializingStateFromUnused()){
+ buffer.retain();
+ takeSnapshot().thenAccept(ignore -> {
+ addTxnEntry(completableFuture, txnId, buffer);
+ buffer.release();
+ changeToReadyState();
+ }).exceptionally(exception -> {
+ changeBackToUnUsedState();
+ buffer.release();
+ log.error("Fail to takeSnapshot before adding the
first message with transaction", exception);
+ completableFuture.completeExceptionally(exception);
+ return null;
+ });
+ } else {
+ completableFuture.completeExceptionally(new
TransactionBufferInitialUseException("Fail to change "
+ + "TransactionBufferState from Unused to Ready
When the first message with transaction "
+ + "was sent"));
+ }
+ } else {
+ completableFuture.completeExceptionally(new
TransactionBufferStatusException(this.topic.getName(),
+ State.Unused, getState()));
Review comment:
except state is ready.
--
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]