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

[config change] Support multiple producers in redis streams #2581

Merged
merged 23 commits into from
Oct 9, 2024

Conversation

ganeshvanahalli
Copy link
Contributor

@ganeshvanahalli ganeshvanahalli commented Aug 15, 2024

This PR allows our redis stream pub-sub implementation to support multiple producers per stream.

Motivation for this change is that previously only one producer was supported per stream I.e although two producers were “technically” allowed to connect to a same redis stream, they couldn’t take any meaningful use of it i.e a producer could accidentally delete the requests from other producers etc..

Previously each consumer used to maintain a heartbeat key in redis and set it periodically to confirm being active, these keys were used by producer to determine what messages are stuck in PEL (pending entry list- messages that are claimed by a consumer but not yet acknowledged) and reinsert them into stream. This PR simplifies this whole process by using XAUTOCLAIM that automatically lets any consumer claim a message which belongs to PEL and is idle for a minimum amount of time.

Config Changes

  • request-timeout has been added to ProducerConfig - indicating TTL for each message added to the redis stream
  • idletime-to-autoclaim has been added to ConsumerConfig - indicating amount of time after which a message from PEL is allowed to be autoclaimed by other consumers
  • enable-reproduce, check-pending-interval, keepalive-timeout and check-pending-items have been removed from ProducerConfig - as they are no longer needed due to changes in the working logic of producer & consumer
  • keepalive-timeout has been removed from ConsumerConfig

Testing Done

Various test cases covering different scenarios have been added to test the working of this design

Resolves NIT-2685

@cla-bot cla-bot bot added the s Automatically added by the CLA bot if the creator of a PR is registered as having signed the CLA. label Aug 15, 2024
@ganeshvanahalli ganeshvanahalli marked this pull request as ready for review August 15, 2024 12:49
eljobe
eljobe previously approved these changes Aug 20, 2024
pubsub/consumer.go Outdated Show resolved Hide resolved
Copy link
Contributor

@magicxyyz magicxyyz left a comment

Choose a reason for hiding this comment

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

Great PR! Added few comments for improvements, some error handling and to the stream trimming (it might need some more complex solution)

pubsub/consumer.go Outdated Show resolved Hide resolved
pubsub/consumer.go Outdated Show resolved Hide resolved
pubsub/producer.go Outdated Show resolved Hide resolved
validator/validation_entry.go Outdated Show resolved Hide resolved
pubsub/consumer.go Outdated Show resolved Hide resolved
pubsub/consumer.go Outdated Show resolved Hide resolved
eljobe
eljobe previously approved these changes Aug 29, 2024
Copy link
Member

@eljobe eljobe left a comment

Choose a reason for hiding this comment

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

LGTM

pubsub/consumer.go Show resolved Hide resolved
pubsub/consumer.go Show resolved Hide resolved
pubsub/consumer.go Show resolved Hide resolved
pubsub/producer.go Show resolved Hide resolved
pubsub/consumer.go Show resolved Hide resolved
Copy link
Contributor

@tsahee tsahee left a comment

Choose a reason for hiding this comment

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

not final.

pubsub/consumer.go Outdated Show resolved Hide resolved
pubsub/consumer.go Outdated Show resolved Hide resolved
pubsub/consumer.go Show resolved Hide resolved
validator/validation_entry.go Outdated Show resolved Hide resolved
pubsub/pubsub_test.go Outdated Show resolved Hide resolved
pubsub/consumer.go Outdated Show resolved Hide resolved
Copy link
Contributor

@tsahee tsahee left a comment

Choose a reason for hiding this comment

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

Awsome work. Didn't review pubsub_test yet.

pubsub/common.go Outdated Show resolved Hide resolved
pubsub/common.go Outdated Show resolved Hide resolved
pubsub/consumer.go Show resolved Hide resolved
pubsub/consumer.go Outdated Show resolved Hide resolved
pubsub/consumer.go Show resolved Hide resolved
pubsub/producer.go Outdated Show resolved Hide resolved
pubsub/producer.go Outdated Show resolved Hide resolved
pubsub/producer.go Outdated Show resolved Hide resolved
pubsub/producer.go Outdated Show resolved Hide resolved
pubsub/consumer.go Outdated Show resolved Hide resolved
@ganeshvanahalli ganeshvanahalli changed the title Support multiple producers in redis streams [config change]Support multiple producers in redis streams Sep 27, 2024
@ganeshvanahalli ganeshvanahalli changed the title [config change]Support multiple producers in redis streams [config change] Support multiple producers in redis streams Sep 27, 2024
tsahee
tsahee previously approved these changes Oct 7, 2024
Copy link
Contributor

@tsahee tsahee left a comment

Choose a reason for hiding this comment

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

very good. Tiny comment that can be done later

}
if _, err := p.client.XDel(ctx, p.redisStream, pelData.Lower).Result(); err != nil {
log.Error("error deleting PEL's lower message thats past its TTL", "msgID", pelData.Lower, "err", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

return 0 here, so we'll immediately keep clearing old results as long as these exit

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant return 0 after the delete succeeded, if err != nil, so we'd immediately be called again because there's a good chance there are more messages that need to be deleted.
In case of errors above it makes sense to return non-zero for backoff.

pubsub/producer.go Show resolved Hide resolved
}
if _, err := p.client.XDel(ctx, p.redisStream, pelData.Lower).Result(); err != nil {
log.Error("error deleting PEL's lower message thats past its TTL", "msgID", pelData.Lower, "err", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I meant return 0 after the delete succeeded, if err != nil, so we'd immediately be called again because there's a good chance there are more messages that need to be deleted.
In case of errors above it makes sense to return non-zero for backoff.

@tsahee tsahee dismissed magicxyyz’s stale review October 9, 2024 22:28

all comments addressed

@tsahee tsahee enabled auto-merge October 9, 2024 22:29
@tsahee tsahee merged commit 6eee30d into master Oct 9, 2024
15 checks passed
@tsahee tsahee deleted the multiple-producers-redisstream branch October 9, 2024 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design-approved s Automatically added by the CLA bot if the creator of a PR is registered as having signed the CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants