From ef886ec43085469c7193abb5bc8f68c0954585fa Mon Sep 17 00:00:00 2001 From: kedixa <1204837541@qq.com> Date: Thu, 29 Jun 2023 20:54:41 +0800 Subject: [PATCH 1/2] KafkaClientTask::compare_topics use ordered topic_set --- src/client/WFKafkaClient.cc | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/client/WFKafkaClient.cc b/src/client/WFKafkaClient.cc index f7d59c6cd3..ec720c332e 100644 --- a/src/client/WFKafkaClient.cc +++ b/src/client/WFKafkaClient.cc @@ -766,25 +766,23 @@ void KafkaClientTask::set_meta_status(bool status) bool KafkaClientTask::compare_topics(KafkaClientTask *task) { - protocol::KafkaMetaList *meta_list1 = &this->meta_list; - protocol::KafkaMetaList *meta_list2 = &task->meta_list; - KafkaMeta *meta1, *meta2; + auto first1 = topic_set.cbegin(), last1 = topic_set.cend(); + auto first2 = task->topic_set.cbegin(), last2 = task->topic_set.cend(); + int cmp; - meta_list1->rewind(); - meta_list2->rewind(); - while (1) + while (first1 != last1 && first2 != last2) { - meta1 = meta_list1->get_next(); - meta2 = meta_list2->get_next(); - if (!meta1 && !meta2) + cmp = first1->compare(*first2); + if (cmp == 0) return true; - if (!meta1 || !meta2) - return false; - - if (strcmp(meta1->get_topic(), meta2->get_topic())) - return false; + if (cmp < 0) + ++first1; + else + ++first2; } + + return false; } bool KafkaClientTask::check_cgroup() From e5f778124e336f52862ff71ff41b5e48fc0768d5 Mon Sep 17 00:00:00 2001 From: kedixa <1204837541@qq.com> Date: Fri, 30 Jun 2023 17:45:42 +0800 Subject: [PATCH 2/2] check whether task->topic_set is a subset of this->topic_set --- src/client/WFKafkaClient.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/client/WFKafkaClient.cc b/src/client/WFKafkaClient.cc index ec720c332e..5a4f81eaa3 100644 --- a/src/client/WFKafkaClient.cc +++ b/src/client/WFKafkaClient.cc @@ -770,19 +770,22 @@ bool KafkaClientTask::compare_topics(KafkaClientTask *task) auto first2 = task->topic_set.cbegin(), last2 = task->topic_set.cend(); int cmp; + // check whether task->topic_set is a subset of topic_set while (first1 != last1 && first2 != last2) { cmp = first1->compare(*first2); if (cmp == 0) - return true; - - if (cmp < 0) + { ++first1; - else ++first2; + } + else if (cmp < 0) + ++first1; + else + return false; } - return false; + return first2 == last2; } bool KafkaClientTask::check_cgroup()