-
Notifications
You must be signed in to change notification settings - Fork 450
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
Conversation
There was a problem hiding this 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)
…rect request scenario
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not final.
There was a problem hiding this 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.
There was a problem hiding this 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) | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
} | ||
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) | ||
} |
There was a problem hiding this comment.
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.
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 toProducerConfig
- indicating TTL for each message added to the redis streamidletime-to-autoclaim
has been added toConsumerConfig
- indicating amount of time after which a message from PEL is allowed to be autoclaimed by other consumersenable-reproduce
,check-pending-interval
,keepalive-timeout
andcheck-pending-items
have been removed fromProducerConfig
- as they are no longer needed due to changes in the working logic of producer & consumerkeepalive-timeout
has been removed fromConsumerConfig
Testing Done
Various test cases covering different scenarios have been added to test the working of this design
Resolves NIT-2685