Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-17726

New consumer subscribe/subscribeFromPattern in background thread

    XMLWordPrintableJSON

Details

    Description

      There are still some calls to change the subscriptionState subscription in the app thread, that could lead to race-conditions given that the subscription state object is shared between the background and app thread and is mostly updated in the background. We should consider moving the subscriptionState.subscribe() and subscribeFromPattern calls to the background.

      https://github.com/apache/kafka/blob/5624bc7c7e43339eb64e18491ac5039324e50678/clients/src/main/java/org/apache/kafka/clients/consumer/internals/AsyncKafkaConsumer.java#L1465

      https://github.com/apache/kafka/blob/5624bc7c7e43339eb64e18491ac5039324e50678/clients/src/main/java/org/apache/kafka/clients/consumer/internals/AsyncKafkaConsumer.java#L1703

      https://github.com/apache/kafka/blob/5624bc7c7e43339eb64e18491ac5039324e50678/clients/src/main/java/org/apache/kafka/clients/consumer/internals/AsyncKafkaConsumer.java#L1736

      One option would be to use the existing SubscriptionChangeEvent, perform the subscription (and metadata) changes in the AppEventProcessor (where unsubscribe already takes place). 

      Note that these calls are closely related to metadata object calls, to request metadata for new topics and "maybeUpdateSubscriptionMetadata". We should maybe consider moving them together to the background (where the metadata object is also updated).  https://github.com/apache/kafka/blob/5624bc7c7e43339eb64e18491ac5039324e50678/clients/src/main/java/org/apache/kafka/clients/consumer/internals/AsyncKafkaConsumer.java#L1703-L1705 

      Attachments

        Issue Links

          Activity

            People

              yangpoan PoAn Yang
              lianetm Lianet Magrans
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated: