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

[TT-1180] use RWMutex to protect LogStream's consumer map #959

Merged
merged 1 commit into from
May 17, 2024

Conversation

Tofel
Copy link
Contributor

@Tofel Tofel commented May 17, 2024

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

  • logstream/logprocessor.go
    • Added RLock() and RUnlock() around consumer access to ensure thread safety during log processing.
  • logstream/logstream.go
    • Introduced a consumerMutex of type sync.RWMutex to manage concurrent access to the consumer map.
    • Implemented mutex locking (Lock() and Unlock()) around modifications to the consumers map to prevent data races.
    • Added RLock() and RUnlock() around read operations on consumers to ensure thread safety.
    • Removed the direct error wrapping logic in Shutdown and replaced it with a more structured approach using shutdownWithFunction, allowing for additional operations post-disconnection but before Loki shutdown.
    • Added noOpPostDisconnectFn, a no-operation function used as a default argument for shutdownWithFunction for cases where no additional operations are needed post-disconnection.
    • Modified FlushAndShutdown to use shutdownWithFunction, incorporating log flushing as the post-disconnect operation.
    • Ensured read locks are applied during operations that read from the consumers map without modifying it, enhancing thread safety without unnecessary write locks.

@cl-sonarqube-production
Copy link

@Tofel Tofel marked this pull request as ready for review May 17, 2024 07:34
@Tofel Tofel requested review from sebawo and a team as code owners May 17, 2024 07:34
@Tofel Tofel merged commit fafd30e into main May 17, 2024
24 of 25 checks passed
@Tofel Tofel deleted the tt_1180_logstream_concurrent_write branch May 17, 2024 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants