feat: Add WithGroupUUID logger and optimize GetGroupJobState in internal job #4270
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.
Description
This pull request refactors the logic for fetching and constructing group job states in the
Job
service, with a focus on improving concurrency safety and error handling. The main changes introduce mutex protection for shared state, replace the previous group job state constructor, and add a new logging helper. These updates help prevent data races and improve the clarity of error reporting.Concurrency and data safety improvements:
jobStates
inGetGroupJobState
to use a mutex (sync.Mutex
) andappend
, replacing the previous approach that used indexed assignment. This prevents potential data races when multiple goroutines update the shared slice.newGroupJobState
constructor withconstructGroupJobState
, ensuring a single, consistent method for buildingGroupJobState
instances. [1] [2]Error handling and logging enhancements:
WithGroupUUID
logger helper when group job state retrieval fails, improving visibility into failures. [1] [2]WithGroupUUID
helper ininternal/dflog/logger.go
for more granular log context.General codebase improvements:
sync
package import to support the new mutex-based concurrency logic.Related Issue
Motivation and Context
Screenshots (if appropriate)
Types of changes
Checklist