codelipenghui commented on code in PR #21406:
URL: https://github.com/apache/pulsar/pull/21406#discussion_r1381806801
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/buffer/impl/TopicTransactionBuffer.java:
##########
@@ -231,7 +232,7 @@ public long getCommittedTxnCount() {
@Override
public CompletableFuture<Position> appendBufferToTxn(TxnID txnId, long
sequenceId, ByteBuf buffer) {
buffer.retain();
- return transactionBufferFuture.thenCompose(ignore -> {
+ CompletableFuture<Position> future = publishFuture.thenCompose(ignore
-> {
Review Comment:
https://github.com/apache/pulsar/blob/99e6aebb88c8ea82c8b8d65261ce71f0ab8d36d8/pulsar-common/src/main/java/org/apache/pulsar/common/util/FutureUtil.java#L174
The Sequencer can be used to handle this case. So that you don't need to
create a meaningless `publishFuture` which is not easy to understand.
For example:
```java
public void testSequencer2() {
final FutureUtil.Sequencer<Void> sequencer =
FutureUtil.Sequencer.create();
CompletableFuture<Void> first = new CompletableFuture<>();
sequencer.sequential(() -> first);
sequencer.sequential(() -> CompletableFuture.runAsync(() ->
System.out.println("1")));
sequencer.sequential(() -> CompletableFuture.runAsync(() ->
System.out.println("2")));
sequencer.sequential(() -> CompletableFuture.runAsync(() ->
System.out.println("3")));
first.complete(null);
}
```
It will consistently execute as:
```
1
2
3
```
--
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]