Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(stream): make consumer decrement pending number when message is acknowledged. #2352

Merged
merged 5 commits into from
Jun 3, 2024

Conversation

LindaSummer
Copy link
Contributor

@LindaSummer LindaSummer commented Jun 2, 2024

Issue

close #2350

Proposed Changes

  • update consumer pending_number when consumer group has acknowledged entry.
  • add test case for XINFO.

@LindaSummer LindaSummer force-pushed the bugfix/consumer_xack_pending branch from 266bbff to 566e419 Compare June 2, 2024 09:47
@LindaSummer LindaSummer changed the title [Bugfix] make consumer decrement pending number when message is acknowledged. fix: make consumer decrement pending number when message is acknowledged. Jun 2, 2024
Copy link
Member

@PragmaTwice PragmaTwice left a comment

Choose a reason for hiding this comment

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

PTAL cc @Yangsx-1 @torwig

@PragmaTwice PragmaTwice requested review from torwig and Yangsx-1 June 2, 2024 10:42
Yangsx-1
Yangsx-1 previously approved these changes Jun 2, 2024
Copy link
Contributor

@Yangsx-1 Yangsx-1 left a comment

Choose a reason for hiding this comment

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

Good catch! LGTM.

src/types/redis_stream.cc Outdated Show resolved Hide resolved
@LindaSummer
Copy link
Contributor Author

Hi @torwig ,

Thanks for your suggestion. I have updated the related code.

Please take a look.

Thanks very much.

torwig
torwig previously approved these changes Jun 2, 2024
Yangsx-1
Yangsx-1 previously approved these changes Jun 2, 2024
@mapleFU
Copy link
Member

mapleFU commented Jun 2, 2024

CI failed is unrelated, rerun

@LindaSummer
Copy link
Contributor Author

Maybe I need to rebase on unstable branch rather than merge, it involved merge commit in this PR.

@mapleFU
Copy link
Member

mapleFU commented Jun 2, 2024

Maybe I need to rebase on unstable branch rather than merge, it involved merge commit in this PR.

We can squash and merge it in one patch, don't worry about that

@LindaSummer
Copy link
Contributor Author

Thanks very much for your warm help. 😊

The merge commit seems to make coverage calculated more code blocks than my commits.

Do I need to solve it with rebase in this PR to re-trigger the coverage workflow?

mapleFU
mapleFU previously approved these changes Jun 2, 2024
}
}
if (*acknowledged > 0) {
StreamConsumerGroupMetadata group_metadata = decodeStreamConsumerGroupMetadataValue(get_group_value);
group_metadata.pending_number -= *acknowledged;
std::string group_value = encodeStreamConsumerGroupMetadataValue(group_metadata);
batch->Put(stream_cf_handle_, group_key, group_value);

for (const auto &consumer : consumer_acknowledges) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for (const auto &consumer : consumer_acknowledges) {
for (const auto &[consumer_name, count] : consumer_acknowledges) {

Copy link
Member

Choose a reason for hiding this comment

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

This is reported by sonar, maybe we should fix that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it, I will update the loop with this syntax.

auto consumer_meta_key = internalKeyFromConsumerName(ns_key, metadata, group_name, consumer.first);
std::string consumer_meta_original;
s = storage_->Get(rocksdb::ReadOptions(), stream_cf_handle_, consumer_meta_key, &consumer_meta_original);
if (s.ok()) {
Copy link
Member

Choose a reason for hiding this comment

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

what if !s.ok() && !s.IsNotFound()?

Copy link
Contributor Author

@LindaSummer LindaSummer Jun 2, 2024

Choose a reason for hiding this comment

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

Thanks very for your correction.

It should be an internal error and I think that I need to return the error. This function's return type is a rocksdb::Status so I don't need to wrap it to another format.

Do I need to add golang integration test for this error handling case? This may be hard to produce a case for it.

Copy link
Member

Choose a reason for hiding this comment

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

Do I need to add golang integration test for this error handling case?

Currently it's a bit hard to modify this, especially in integration tests. We can just handle this without testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it! I have corrected my wording above.

This function returns rocksdb::Status and I think I should return the status immediately in the function when !s.ok() && !s.IsNotFound().

Copy link
Member

Choose a reason for hiding this comment

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

There're two gets here, right? if (s.ok()) in the loop should also adds this checks(Though errors merely happens)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your correction!

Sorry for missing another error handling. I have added it with a new commit.

@LindaSummer LindaSummer dismissed stale reviews from mapleFU, Yangsx-1, and torwig via 777f504 June 2, 2024 15:44
@LindaSummer LindaSummer force-pushed the bugfix/consumer_xack_pending branch from 712a717 to 777f504 Compare June 2, 2024 15:44
@git-hulk git-hulk changed the title fix: make consumer decrement pending number when message is acknowledged. fix(stream): make consumer decrement pending number when message is acknowledged. Jun 3, 2024
@git-hulk git-hulk requested review from mapleFU and torwig June 3, 2024 01:59
@git-hulk git-hulk requested a review from Yangsx-1 June 3, 2024 01:59
@mapleFU
Copy link
Member

mapleFU commented Jun 3, 2024

Would merge if ci passes

@git-hulk
Copy link
Member

git-hulk commented Jun 3, 2024

No worry about this flaky test failure, can rerun to avoid blocking the PR.

@mapleFU mapleFU merged commit eaf6b2e into apache:unstable Jun 3, 2024
32 checks passed
Copy link

sonarcloud bot commented Jun 3, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
35.2% Coverage on New Code (required ≥ 50%)

See analysis details on SonarCloud

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.

[Bug] XINFO overflow when deleting pending message and consumer
6 participants