Repository navigation
Subscription: fix retained snapshot completion across DataNodes and DataRegions #19364
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
Changes from 5 commits
674c40a
9384659
df8194d
70ade80
be26858
4d3bee9
6c3920d
c243982
1ff5426
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 |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ | |
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashSet; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
@@ -51,6 +52,7 @@ final class AbstractSubscriptionProviders { | |
|
|
||
| private final SortedMap<Integer, AbstractSubscriptionProvider> subscriptionProviders = | ||
| new ConcurrentSkipListMap<>(); | ||
| private final Set<Integer> knownClusterDataNodeIds = ConcurrentHashMap.newKeySet(); | ||
| private final AtomicBoolean isClosing = new AtomicBoolean(false); | ||
| private final AtomicBoolean unavailableSyncInFlight = new AtomicBoolean(false); | ||
| private final Set<AbstractSubscriptionProvider> providersWithHeartbeatInFlight = | ||
|
|
@@ -90,6 +92,7 @@ void releaseWriteLock() { | |
| /** Caller should ensure that the method is called in the lock {@link #acquireWriteLock()}. */ | ||
| void openProviders(final AbstractSubscriptionConsumer consumer) throws SubscriptionException { | ||
| // close stale providers | ||
| consumer.clearTerminatedProviderStates(); | ||
| closeProviders(false); | ||
|
|
||
| final Map<TEndPoint, String> connectionFailures = new LinkedHashMap<>(); | ||
|
|
@@ -126,6 +129,8 @@ void openProviders(final AbstractSubscriptionConsumer consumer) throws Subscript | |
| final Map<Integer, TEndPoint> allEndPoints; | ||
| try { | ||
| allEndPoints = defaultProvider.heartbeat().getEndPoints(); | ||
| knownClusterDataNodeIds.clear(); | ||
| knownClusterDataNodeIds.addAll(allEndPoints.keySet()); | ||
| } catch (final SubscriptionConsumerFencedException e) { | ||
| consumer.fence(e); | ||
| throw e; | ||
|
|
@@ -197,6 +202,7 @@ void closeProviders() { | |
| void closeProviders(final boolean closeConsumer) { | ||
| final List<AbstractSubscriptionProvider> providers = getAllProviders(); | ||
| subscriptionProviders.clear(); | ||
| knownClusterDataNodeIds.clear(); | ||
| for (final AbstractSubscriptionProvider provider : providers) { | ||
| try { | ||
| if (closeConsumer) { | ||
|
|
@@ -301,6 +307,13 @@ List<AbstractSubscriptionProvider> getAllAvailableProviders() { | |
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| /** Caller should ensure that the method is called in the lock {@link #acquireReadLock()}. */ | ||
| Set<Integer> getExpectedDataNodeIds() { | ||
| final Set<Integer> ids = new HashSet<>(knownClusterDataNodeIds); | ||
| ids.addAll(subscriptionProviders.keySet()); | ||
| return ids; | ||
|
Comment on lines
+322
to
+324
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. Addressed in 4d3bee9: |
||
| } | ||
|
|
||
| /** Caller should ensure that the method is called in the lock {@link #acquireReadLock()}. */ | ||
| void updateNextDataNodeId() { | ||
| final SortedMap<Integer, AbstractSubscriptionProvider> subProviders = | ||
|
|
@@ -367,19 +380,15 @@ private void heartbeatProvider( | |
| synchronized (heartbeatResponseLock) { | ||
| consumer.subscribedTopics = resp.getTopics(); | ||
| for (final String topicName : resp.getTopicNamesToUnsubscribe()) { | ||
| LOGGER.info( | ||
| SubscriptionMessages | ||
| .LOG_TERMINATION_OCCURRED_SUBSCRIPTIONCONSUMER_ARG_POLLING_TOPICS_UNSUBSCRIBE_TOPIC_ARG_AUTOMATICALLY_E9B695FA, | ||
| consumer.coreReportMessage(), | ||
| topicName); | ||
| consumer.unsubscribe(topicName); | ||
| consumer.handleProviderTopicTermination(provider.getDataNodeId(), topicName); | ||
| } | ||
| } | ||
| } catch (final SubscriptionConsumerFencedException e) { | ||
| if (containsProvider(provider)) { | ||
| consumer.fence(e); | ||
| } | ||
| provider.setUnavailable(); | ||
| consumer.clearTerminatedProviderStates(); | ||
| } catch (final Exception e) { | ||
| LOGGER.warn( | ||
| SubscriptionMessages | ||
|
|
@@ -389,6 +398,7 @@ private void heartbeatProvider( | |
| e, | ||
| e); | ||
| provider.setUnavailable(); | ||
| consumer.clearTerminatedProviderStates(); | ||
| } finally { | ||
| providersWithHeartbeatInFlight.remove(provider); | ||
| } | ||
|
|
@@ -472,6 +482,8 @@ private void syncInternal(final AbstractSubscriptionConsumer consumer) { | |
| final Map<Integer, TEndPoint> allEndPoints; | ||
| try { | ||
| allEndPoints = consumer.fetchAllEndPointsWithRedirection(); | ||
| knownClusterDataNodeIds.clear(); | ||
| knownClusterDataNodeIds.addAll(allEndPoints.keySet()); | ||
| } catch (final SubscriptionConsumerFencedException e) { | ||
| consumer.fence(e); | ||
| return; | ||
|
|
@@ -509,6 +521,7 @@ private void syncInternal(final AbstractSubscriptionConsumer consumer) { | |
|
|
||
| if (Objects.nonNull(provider) && !provider.isAvailable()) { | ||
| // Remove unavailable providers before creating replacements in this same sync round. | ||
| consumer.clearTerminatedProviderStates(); | ||
| try { | ||
| closeAndRemoveProvider(entry.getKey()); | ||
| } catch (final Exception e) { | ||
|
|
@@ -544,6 +557,7 @@ private void syncInternal(final AbstractSubscriptionConsumer consumer) { | |
| e); | ||
| continue; | ||
| } | ||
| consumer.clearTerminatedProviderStates(); | ||
| addProvider(entry.getKey(), newProvider); | ||
| } | ||
| } | ||
|
|
@@ -552,6 +566,7 @@ private void syncInternal(final AbstractSubscriptionConsumer consumer) { | |
| for (final AbstractSubscriptionProvider provider : getAllProviders()) { | ||
| final int dataNodeId = provider.getDataNodeId(); | ||
| if (!allEndPoints.containsKey(dataNodeId)) { | ||
| consumer.clearTerminatedProviderStates(); | ||
| try { | ||
| closeAndRemoveProvider(dataNodeId); | ||
| } catch (final Exception e) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 4d3bee9:
handleProviderTopicTerminationnow holdsproviders.acquireReadLock()across readingproviders.getExpectedDataNodeIds()/providers.getTopologyGeneration()and checkingtopicTerminationLock, and validates thattopologyGenerationis unchanged before issuingunsubscribe();syncInternalalso clears termination state and incrementstopologyGenerationwhenever cluster membership changes. Added regression testSubscriptionConsumerMultiProviderPollTest#testRetainedSnapshotTerminationDoesNotUseStaleMembershipAcrossConcurrentSync.