Skip to content

Conversation

@emasab
Copy link
Contributor

@emasab emasab commented Apr 8, 2025

No description provided.

@emasab emasab requested a review from a team as a code owner April 8, 2025 18:21
@confluent-cla-assistant
Copy link

🎉 All Contributor License Agreements have been signed. Ready to merge.
Please push an empty commit if you would like to re-run the checks to verify CLA status for all contributors.

Base automatically changed from dev_kip848_fix_fast_subscribe_or_unsubscribe to master April 8, 2025 19:09
@airlock-confluentinc airlock-confluentinc bot force-pushed the dev_kip848_fix_fast_subscribe_or_unsubscribe_tests branch from 0999c46 to 050b06c Compare April 9, 2025 09:37
@airlock-confluentinc airlock-confluentinc bot force-pushed the dev_kip848_fix_fast_subscribe_or_unsubscribe_tests branch from 050b06c to 93df6bf Compare June 26, 2025 10:25
Copilot AI review requested due to automatic review settings September 25, 2025 16:22
@airlock-confluentinc airlock-confluentinc bot force-pushed the dev_kip848_fix_fast_subscribe_or_unsubscribe_tests branch from 93df6bf to ad14022 Compare September 25, 2025 16:22
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@airlock-confluentinc airlock-confluentinc bot force-pushed the dev_kip848_fix_fast_subscribe_or_unsubscribe_tests branch from ea0a133 to 312f6f6 Compare September 29, 2025 15:24
@emasab emasab changed the title [KIP-848] Tests for dev_kip848_fix_fast_subscribe_or_unsubscribe [KIP-848] Tests for: dev_kip848_fix_fast_subscribe_or_unsubscribe Sep 29, 2025
* for TOPICS_CNT topics */
rd_sleep(1);

RD_ARRAY_FOREACH(topic, topics, i) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for FOREACH call here. We are not using topic anywhere below. We can have a simple for loop here.

Comment on lines 915 to 917
RD_ARRAY_FOREACH(topic, topics, i) {
rd_free(topics[i]);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for FOREACH here as well. We can just use simple forloop.

Copy link
Contributor Author

@emasab emasab Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't agree, we have it for every other iterable type, the foreach in general is less typo error prone than writing the initialization and while condition every time. Of course it works only for arrays that are on stack on in structure where we can determine the full size with sizeof() but it's an improvement for these cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep the definition of RD_ARRAY_FOREACH if you feel like but here the topic is being accessed as topics[i].

If we are keeping RD_ARRAY_FOREACH then we should also have RD_ARRAY_FOREACH_INDEX(ELEM, ARRAY, INDEX) and have RD_ARRAY_FOREACH(ELEM, ARRAY) which internally uses RD_ARRAY_FOREACH_INDEX. We don't need index in FOREACH in general like other high level languages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine I add them. The index is only for when we need it so it can be a different directive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you feel like but here the topic is being accessed as topics[i].

right, I use topic here

SUB_TEST("%s", with_rebalance_cb ? "with rebalance callback"
: "without rebalance callback");

RD_ARRAY_FOREACH(topic, topics, i) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for FOREACH here as simple for loop will work.

src/rd.h Outdated
#define RD_SIZEOF(TYPE, MEMBER) sizeof(((TYPE *)NULL)->MEMBER)
#define RD_OFFSETOF(TYPE, MEMBER) ((size_t) & (((TYPE *)NULL)->MEMBER))
/** Array foreach */
#define RD_ARRAY_FOREACH(ELEM, ARRAY, INDEX) \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this foreach as not used in the PR.

Copy link
Member

@pranavrth pranavrth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few more comments.

src/rd.h Outdated
INDEX < RD_ARRAY_SIZE(ARRAY); \
(ELEM) = \
(++INDEX < RD_ARRAY_SIZE(ARRAY) ? (ARRAY)[INDEX] : (ELEM)))
#define RD_ARRAY_FOREACH_INDEX(ELEM, ARRAY, INDEX, BLOCK) \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not make it complex to understand. Remove BLOCK from here. It should be a simple FOREACH.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that way we need to provide the index variable externally instead of defining it here and we need to use always RD_ARRAY_FOREACH_INDEX

Copy link
Member

@pranavrth pranavrth Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep it simple to understand the functions. We should remove this BLOCK from the macro and make it work it without it. Something like below.

/** Array foreach */
#define RD_ARRAY_FOREACH_INDEX(ELEM, ARRAY, INDEX)                             \
        for ((INDEX = 0, (ELEM) = (ARRAY)[INDEX]);                             \
             INDEX < RD_ARRAY_SIZE(ARRAY);                                     \
             (ELEM) =                                                          \
                 (++INDEX < RD_ARRAY_SIZE(ARRAY) ? (ARRAY)[INDEX] : (ELEM)))

#define RD_ARRAY_FOREACH(ELEM, ARRAY)                                          \
        RD_ARRAY_FOREACH_INDEX(ELEM, ARRAY, __i)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are places in librdkafka where we expect a variable to be defined already. We can expect __i defined already.

Copy link
Contributor Author

@emasab emasab Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are places in librdkafka where we expect a variable to be defined already. We can expect __i defined already.

I don't like it because you've to define the variable outside it and the name is fixed, in that case it's better if we leave only the original RD_ARRAY_FOREACH passing the variable name

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using C99 standard of declaring variable inside the for loop. Like for(int i=0;i<n;i++) ?

Copy link
Contributor Author

@emasab emasab Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That way it had problem with older versions of MSVC that didn't implement the C99 standard fully until some time ago.

Copy link
Member

@pranavrth pranavrth Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. I would prefer to remove this FOREACH loop altogether. But if you want to keep it, keep only RD_ARRAY_FOREACH_INDEX. Remove RD_ARRAY_FOREACH. So the implementation of original RD_ARRAY_FOREACH but with changed name RD_ARRAY_FOREACH_INDEX.

@airlock-confluentinc airlock-confluentinc bot force-pushed the dev_kip848_fix_fast_subscribe_or_unsubscribe_tests branch from 9722f04 to 7aea93f Compare September 30, 2025 13:53
@airlock-confluentinc airlock-confluentinc bot force-pushed the dev_kip848_fix_fast_subscribe_or_unsubscribe_tests branch from 652cda5 to 7a4340a Compare September 30, 2025 19:48
Copy link
Member

@pranavrth pranavrth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!.

@emasab emasab merged commit b9a1072 into master Oct 6, 2025
2 checks passed
@emasab emasab deleted the dev_kip848_fix_fast_subscribe_or_unsubscribe_tests branch October 6, 2025 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants