fix: Fix bugs in stream message handling and minor logging improvements #438
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It was observed that there are three related bugs in stream message processing:
In addition, xRange takes a significant amount of time to run depending on the size of the queue. This impacts all other operations since redis is single-threaded. xLen takes much less time to call while also accurately returning the count of messages in the stream.
To resolve the bugs, I now increment the sequence instead of the main ID. In addition, if no more stream messages are being fetched, the stream message ID is reset to '0' to ensure new messages are collected regardless of their ID. Finally, I replaced xRange with xLen. I also changed a blocking while loop to an if statement in consumer so that if the queue is empty, it continues, which triggers the finally.
I made some small additions to logging statements to include the indexer type and block number for success/failure to help diagnose problems with indexers in the future.