lhotari commented on code in PR #23352:
URL: https://github.com/apache/pulsar/pull/23352#discussion_r1797029529
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentStickyKeyDispatcherMultipleConsumers.java:
##########
@@ -131,60 +131,74 @@ public synchronized CompletableFuture<Void>
addConsumer(Consumer consumer) {
consumer.disconnect();
return CompletableFuture.completedFuture(null);
}
- return super.addConsumer(consumer).thenCompose(__ ->
- selector.addConsumer(consumer).handle((result, ex) -> {
- if (ex != null) {
- synchronized
(PersistentStickyKeyDispatcherMultipleConsumers.this) {
- consumerSet.removeAll(consumer);
- consumerList.remove(consumer);
- }
- throw FutureUtil.wrapToCompletionException(ex);
+ return super.addConsumer(consumer).thenCompose(__ ->
selector.addConsumer(consumer))
+ .thenAccept(impactedConsumers -> {
+ // TODO: Add some way to prevent changes in between the time the
consumer is added and the
+ // time the draining hashes are applied. It might be fine for
ConsistentHashingStickyKeyConsumerSelector
+ // since it's not really asynchronous, although it returns a
CompletableFuture
+ if (drainingHashesRequired) {
+
consumer.setPendingAcksAddHandler(this::handleAddingPendingAck);
+ consumer.setPendingAcksRemoveHandler(new
PendingAcksMap.PendingAcksRemoveHandler() {
+ @Override
+ public void handleRemoving(Consumer consumer, long
ledgerId, long entryId, int stickyKeyHash,
+ boolean closing) {
+ drainingHashesTracker.reduceRefCount(consumer,
stickyKeyHash, closing);
}
- return result;
- })
- ).thenRun(() -> {
- synchronized (PersistentStickyKeyDispatcherMultipleConsumers.this)
{
- if (recentlyJoinedConsumerTrackingRequired) {
- final Position lastSentPositionWhenJoining =
updateIfNeededAndGetLastSentPosition();
- if (lastSentPositionWhenJoining != null) {
-
consumer.setLastSentPositionWhenJoining(lastSentPositionWhenJoining);
- // If this was the 1st consumer, or if all the
messages are already acked, then we
- // don't need to do anything special
- if (recentlyJoinedConsumers != null
- && consumerList.size() > 1
- &&
cursor.getNumberOfEntriesSinceFirstNotAckedMessage() > 1) {
- recentlyJoinedConsumers.put(consumer,
lastSentPositionWhenJoining);
- }
+
+ @Override
+ public void startBatch() {
+ drainingHashesTracker.startBatch();
}
- }
+
+ @Override
+ public void endBatch() {
+ drainingHashesTracker.endBatch();
+ }
+ });
+ registerDrainingHashes(consumer, impactedConsumers);
+ }
+ }).exceptionally(ex -> {
+ internalRemoveConsumer(consumer);
+ throw FutureUtil.wrapToCompletionException(ex);
+ });
+ }
+
+ private synchronized void registerDrainingHashes(Consumer skipConsumer,
+ ImpactedConsumersResult
impactedConsumers) {
+ impactedConsumers.processRemovedHashRanges((c, removedHashRanges) -> {
+ if (c != skipConsumer) {
Review Comment:
Created #23439 to track that.
--
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]