[TT-1180] use RWMutex to protect LogStream's consumer map #959
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.
Tried and tested here
Below is a summarization created by an LLM (gpt-4-0125-preview). Be mindful of hallucinations and verify accuracy.
Why
The changes enhance thread safety and error handling in the log streaming system. By introducing mutex locking, the code ensures that consumer access is synchronized, preventing data races. The addition of a no-op function for post-disconnect scenarios and the restructuring of shutdown procedures allow for more flexible and error-resilient shutdown logic. These modifications aim to improve the reliability and maintainability of the log streaming system.
What
RLock()
andRUnlock()
around consumer access to ensure thread safety during log processing.consumerMutex
of typesync.RWMutex
to manage concurrent access to the consumer map.Lock()
andUnlock()
) around modifications to the consumers map to prevent data races.RLock()
andRUnlock()
around read operations on consumers to ensure thread safety.Shutdown
and replaced it with a more structured approach usingshutdownWithFunction
, allowing for additional operations post-disconnection but before Loki shutdown.noOpPostDisconnectFn
, a no-operation function used as a default argument forshutdownWithFunction
for cases where no additional operations are needed post-disconnection.FlushAndShutdown
to useshutdownWithFunction
, incorporating log flushing as the post-disconnect operation.