-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Fix race on measurementFields #6190
Conversation
|
||
return nil | ||
} | ||
|
||
func (m *MeasurementFields) Field(name string) *Field { | ||
m.mu.RLock() | ||
defer m.mu.RUnlock() |
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.
How often is this called? If it's a heavily-used function, maybe read, unlock, then return?
Both Shard and Engine had the same reference to the measurementField map, but they each protected it with their own locks. This causes a race when write and queries are occurring because writes can add new fields to the map while queries are reading from it. The fix moves the ownership to the Engine and provides protected accessors to that Shard now users. For the most parts, the access on shard were old dead code. Fixing the measurementFields map race created a new race on the internal fields map. This is now unexported and protected via MeasurementFields exported funcs. Fixes #6188
Also remove some dead code that is no longer relevant with tsm.
+1 |
LGTM |
|
@e-dard Thanks! |
Required for all non-trivial PRs
Both Shard and Engine had the same reference to the measurementField map,
but they each protected it with their own locks. This causes a race when
write and queries are occurring because writes can add new fields to the
map while queries are reading from it.
The fix moves the ownership to the Engine and provides protected accessors
to that Shard now users. For the most parts, the access on shard were old
dead code.
Fixing the measurementFields map race created a new race on the internal
fields map. This is now unexported and protected via MeasurementFields
exported funcs.
Fixes #6188