congbobo184 commented on a change in pull request #8719:
URL: https://github.com/apache/pulsar/pull/8719#discussion_r532006440
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/buffer/impl/TopicTransactionBuffer.java
##########
@@ -69,47 +188,71 @@ public TopicTransactionBuffer(PersistentTopic topic) {
public CompletableFuture<TransactionBufferReader>
openTransactionBufferReader(TxnID txnID, long startSequenceId) {
return null;
}
+
@Override
public CompletableFuture<Void> commitTxn(TxnID txnID, List<MessageIdData>
sendMessageIdList) {
+ if (!checkIfReady()) {
+ return FutureUtil.failedFuture(
+ new ServiceUnitNotReadyException("Topic : " +
topic.getName()
+ + " transaction buffer haven't finish replay!"));
+ }
if (log.isDebugEnabled()) {
log.debug("Transaction {} commit on topic {}.", txnID.toString(),
topic.getName());
}
CompletableFuture<Void> completableFuture = new CompletableFuture<>();
-
- ByteBuf commitMarker = Markers.newTxnCommitMarker(-1L,
txnID.getMostSigBits(),
- txnID.getLeastSigBits(),
getMessageIdDataList(sendMessageIdList));
- topic.publishMessage(commitMarker, (e, ledgerId, entryId) -> {
- if (e != null) {
- log.error("Failed to commit for txn {}", txnID, e);
- completableFuture.completeExceptionally(e);
- return;
- }
+ ConcurrentOpenHashSet<PositionImpl> positions =
txnBufferCache.get(txnID);
+ if (positions != null) {
+ ByteBuf commitMarker = Markers.newTxnCommitMarker(-1L,
txnID.getMostSigBits(),
+ txnID.getLeastSigBits(),
convertPositionToMessageIdData(positions.values()));
+ topic.publishMessage(commitMarker, (e, ledgerId, entryId) -> {
+ if (e != null) {
+ log.error("Failed to commit for txn {}", txnID, e);
+ completableFuture.completeExceptionally(e);
+ return;
+ }
+ txnBufferCache.remove(txnID);
+ completableFuture.complete(null);
+ positionsSort.removeAll(positions.values());
+ });
+ } else {
Review comment:
yes, when we receive the commit command again, in memory we don't have
any positions need to write marker.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]