-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[improve][broker] PIP-307: Implement broker and client consumer changes when topic is unloading #21682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[improve][broker] PIP-307: Implement broker and client consumer changes when topic is unloading #21682
Changes from all commits
117df78
d2ba22f
3ea12a2
eb069f4
7f3ab3b
04da2b8
68731c1
58cb41d
4b480ec
94fdee4
c205665
bd94002
3c82142
c2cb6ba
6203e3d
ae14bd5
52b7db3
9483304
2449f94
2993154
b376538
10e51ee
4c18e9e
f313140
903c494
7098d51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ | |
| import static org.apache.pulsar.broker.service.persistent.PersistentTopic.getMigratedClusterUrl; | ||
| import static org.apache.pulsar.common.api.proto.ProtocolVersion.v5; | ||
| import static org.apache.pulsar.common.protocol.Commands.DEFAULT_CONSUMER_EPOCH; | ||
| import static org.apache.pulsar.common.protocol.Commands.newCloseConsumer; | ||
| import static org.apache.pulsar.common.protocol.Commands.newLookupErrorResponse; | ||
| import com.google.common.annotations.VisibleForTesting; | ||
| import com.google.common.base.Strings; | ||
|
|
@@ -1321,7 +1322,7 @@ protected void handleSubscribe(final CommandSubscribe subscribe) { | |
| topicName, remoteAddress, consumerId); | ||
| } | ||
| consumers.remove(consumerId, consumerFuture); | ||
| closeConsumer(consumerId); | ||
| closeConsumer(consumerId, Optional.empty()); | ||
| return null; | ||
| } | ||
| } else if (exception.getCause() instanceof BrokerServiceException) { | ||
|
|
@@ -1766,7 +1767,7 @@ protected void handleSend(CommandSend send, ByteBuf headersAndPayload) { | |
| // if the topic is transferring, we ignore send msg. | ||
| if (producer.getTopic().isTransferring()) { | ||
| long ignoredMsgCount = ExtensibleLoadManagerImpl.get(pulsar) | ||
| .getIgnoredSendMsgCounter().incrementAndGet(); | ||
| .getIgnoredSendMsgCounter().addAndGet(send.getNumMessages()); | ||
| if (log.isDebugEnabled()) { | ||
| log.debug("Ignored send msg from:{}:{} to fenced topic:{} while transferring." | ||
| + " Ignored message count:{}.", | ||
|
|
@@ -1842,6 +1843,15 @@ protected void handleAck(CommandAck ack) { | |
|
|
||
| if (consumerFuture != null && consumerFuture.isDone() && !consumerFuture.isCompletedExceptionally()) { | ||
| Consumer consumer = consumerFuture.getNow(null); | ||
| Subscription subscription = consumer.getSubscription(); | ||
| if (subscription.getTopic().isTransferring()) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have a test to cover in transferring acks?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not specifically, but the modified test covers ack behavior: https://github.com/apache/pulsar/pull/21682/files#diff-744119c61c9f6a1b786c3966acd1e0f63748985cf68a6a1a15418c8d9900a9a8R543-R547. The test does not succeed unless all messages sent during the transfer surface out on the consumers. Since there are 200 messages involved, at least one of them likely has the acknowledgement initially ignored. |
||
| // Message acks are silently ignored during topic transfer. | ||
| if (log.isDebugEnabled()) { | ||
| log.debug("[{}] [{}] Ignoring message acknowledgment during topic transfer, ack count: {}", | ||
| subscription, consumerId, ack.getMessageIdsCount()); | ||
| } | ||
| return; | ||
| } | ||
| consumer.messageAcked(ack).thenRun(() -> { | ||
| if (hasRequestId) { | ||
| writeAndFlush(Commands.newAckResponse( | ||
|
|
@@ -3071,15 +3081,17 @@ private void closeProducer(long producerId, long epoch, Optional<BrokerLookupDat | |
| } | ||
|
|
||
| @Override | ||
| public void closeConsumer(Consumer consumer) { | ||
| public void closeConsumer(Consumer consumer, Optional<BrokerLookupData> assignedBrokerLookupData) { | ||
| // removes consumer-connection from map and send close command to consumer | ||
| safelyRemoveConsumer(consumer); | ||
| closeConsumer(consumer.consumerId()); | ||
| closeConsumer(consumer.consumerId(), assignedBrokerLookupData); | ||
| } | ||
|
|
||
| private void closeConsumer(long consumerId) { | ||
| private void closeConsumer(long consumerId, Optional<BrokerLookupData> assignedBrokerLookupData) { | ||
| if (getRemoteEndpointProtocolVersion() >= v5.getValue()) { | ||
| writeAndFlush(Commands.newCloseConsumer(consumerId, -1L)); | ||
| writeAndFlush(newCloseConsumer(consumerId, -1L, | ||
| assignedBrokerLookupData.map(BrokerLookupData::pulsarServiceUrl).orElse(null), | ||
| assignedBrokerLookupData.map(BrokerLookupData::pulsarServiceUrlTls).orElse(null))); | ||
| } else { | ||
| close(); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.