private void checkBeforeSubscribeInternal(TSubscribeReq subscribeReq)
      throws SubscriptionException {
    String consumerId = subscribeReq.getConsumerId();
    String consumerGroupId = subscribeReq.getConsumerGroupId();

    // 1. Check if the consumer exists
    if (!isConsumerExisted(consumerGroupId, consumerId)) {
      // There is no consumer with the same consumerId and consumerGroupId,
      // we should end the procedure
      final String exceptionMessage =
          String.format(
              "Failed to subscribe because the consumer %s in consumer group %s does not exist",
              consumerId, consumerGroupId);
      LOGGER.warn(exceptionMessage);
      throw new SubscriptionException(exceptionMessage);
    }

    ConsumerGroupMeta consumerGroupMeta = getConsumerGroupMeta(consumerGroupId);

    // 2. Check all topics will be subscribed
    for (String topicName : subscribeReq.getTopicNames()) {
      // 2.1. check if exist
      if (!isTopicExisted(topicName, subscribeReq.isTableModel)) {
        final String exceptionMessage =
            String.format("Failed to subscribe because the topic %s does not exist", topicName);
        LOGGER.warn(exceptionMessage);
        throw new SubscriptionException(exceptionMessage);
      }

      // 2.2. check username
      if (!consumerGroupMeta.allowSubscribeTopicForConsumer(topicName, consumerId)) {
        final String exceptionMessage =
            String.format(
                "Failed to subscribe topic %s for consumer %s because inconsistent username under the same consumer group",
                topicName, consumerId);
        LOGGER.warn(exceptionMessage);
        throw new SubscriptionException(exceptionMessage);
      }
    }
  }
Caller should ensure that the method is called in the lock {@link #acquireWriteLock}.
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/subscription/SubscriptionInfo.java