congbobo184 commented on a change in pull request #8719:
URL: https://github.com/apache/pulsar/pull/8719#discussion_r532006236
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/buffer/impl/TopicTransactionBuffer.java
##########
@@ -53,14 +150,36 @@ public TopicTransactionBuffer(PersistentTopic topic) {
@Override
public CompletableFuture<Position> appendBufferToTxn(TxnID txnId, long
sequenceId, ByteBuf buffer) {
+ if (!checkIfReady()) {
+ return FutureUtil.failedFuture(
+ new ServiceUnitNotReadyException("Topic : " +
topic.getName()
+ + " transaction buffer haven't finish replay!"));
+ }
CompletableFuture<Position> completableFuture = new
CompletableFuture<>();
topic.publishMessage(buffer, (e, ledgerId, entryId) -> {
if (e != null) {
log.error("Failed to append buffer to txn {}", txnId, e);
completableFuture.completeExceptionally(e);
return;
}
- completableFuture.complete(PositionImpl.get(ledgerId, entryId));
+ ConcurrentOpenHashSet<PositionImpl> positions =
+ txnBufferCache.computeIfAbsent(txnId, (v) -> new
ConcurrentOpenHashSet<>());
+ PositionImpl position = PositionImpl.get(ledgerId, entryId);
+ positions.add(position);
+ positionsSort.add(position);
+ completableFuture.complete(position);
+ if (countToSyncPosition.incrementAndGet() ==
defaultCountToSyncPosition) {
+ try {
+ PositionImpl syncPosition = positionsSort.pollFirst();
+ if (syncPosition != null) {
+
topic.getManagedLedger().setProperty(txnOnGoingPositionName,
syncPosition.toString());
+ }
+ } catch (ManagedLedgerException | InterruptedException
exception) {
+ log.error("Topic : [{}] Position : [{}], transaction
buffer " +
+ "sync replay position fail!", topic.getName(),
position);
+ }
+ countToSyncPosition.addAndGet(defaultCountToSyncPosition);
Review comment:
it is a bug in my code, i will fix it
----------------------------------------------------------------
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]