private void checkBeforeUnsubscribeInternal(TUnsubscribeReq unsubscribeReq)
      throws SubscriptionException {
    // 1. Check if the consumer exists
    // NOTE: consumer id may be null if drop subscription by session
    if (Objects.nonNull(unsubscribeReq.getConsumerId())) {
      if (!isConsumerExisted(unsubscribeReq.getConsumerGroupId(), unsubscribeReq.getConsumerId())) {
        // There is no consumer with the same consumerId and consumerGroupId,
        // we should end the procedure
        final String exceptionMessage =
            String.format(
                "Failed to unsubscribe because the consumer %s in consumer group %s does not exist",
                unsubscribeReq.getConsumerId(), unsubscribeReq.getConsumerGroupId());
        LOGGER.warn(exceptionMessage);
        throw new SubscriptionException(exceptionMessage);
      }
    }

    // 2. Check if all topics exist. No need to check if already subscribed.
    for (String topic : unsubscribeReq.getTopicNames()) {
      if (!isTopicExisted(topic, unsubscribeReq.isTableModel)) {
        final String exceptionMessage =
            String.format("Failed to unsubscribe because the topic %s does not exist", topic);
        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