congbobo184 commented on a change in pull request #8996:
URL: https://github.com/apache/pulsar/pull/8996#discussion_r557844360
##########
File path:
pulsar-client/src/main/java/org/apache/pulsar/client/impl/PersistentAcknowledgmentsGroupingTracker.java
##########
@@ -330,16 +462,41 @@ public void flush() {
return;
}
+ if (ackResponseEnabled) {
+ this.lock.writeLock().lock();
+ try {
+ flushAsync(cnx);
+ } finally {
+ this.lock.writeLock().unlock();
+ }
+ } else {
+ flushAsync(cnx);
+ }
+ }
+
+ private void flushAsync(ClientCnx cnx) {
boolean shouldFlush = false;
if (cumulativeAckFlushRequired) {
- newAckCommand(consumer.consumerId, lastCumulativeAck,
lastCumulativeAckSet, AckType.Cumulative, null, Collections.emptyMap(), cnx,
false /* flush */, -1, -1);
+ if (ackResponseEnabled) {
+ long requestId = consumer.getClient().newRequestId();
+ ByteBuf cmd = Commands.newAck(consumer.consumerId,
lastCumulativeAck.messageId.ledgerId,
+ lastCumulativeAck.messageId.getEntryId(),
lastCumulativeAck.bitSetRecyclable,
+ AckType.Cumulative, null, Collections.emptyMap(),
requestId);
+ cnx.newAckForResponseWithFuture(cmd, requestId,
currentCumulativeAckFuture);
+ this.currentCumulativeAckFuture = new
TimedCompletableFuture<>();
+ } else {
+ ByteBuf cmd = Commands.newAck(consumer.consumerId,
lastCumulativeAck.messageId.ledgerId,
+ lastCumulativeAck.messageId.getEntryId(),
lastCumulativeAck.bitSetRecyclable,
+ AckType.Cumulative, null, Collections.emptyMap(), -1);
+ cnx.ctx().write(cmd, cnx.ctx().voidPromise());
Review comment:
if we optimize the code, we will judge the ackResponseEnabled twice,
because get requestId then new cmd and then write. get requestId and write are
different from normal ack and ack response. the middle operation newAckComand
can't be optimized.
----------------------------------------------------------------
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]