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

Make the datapoint storage cache safe for concurrent use #417

Merged
merged 2 commits into from Jun 15, 2022

Conversation

dashpole
Copy link
Contributor

@dashpole dashpole commented Jun 9, 2022

Fixes #405

This adds one RW lock for each cache. For GetFoo() functions, it takes a RLock, and for SetFoo() functions, it takes a write Lock. However, since the "used" bool is set in GetFoo() functions (it indicates if the item has been touched since the last GC), this still produced a data race. I could have switched to a full write-lock for Get functions, but thought it would be more performant to use a concurrency-safe bool. That also simplifies the implementation of GC using Compare and swap.

I added tests for concurrency to verify that there are no data races.

@dashpole dashpole requested review from damemi and jsuereth June 9, 2022 15:49
@dashpole
Copy link
Contributor Author

@jsuereth you had mentioned wanting to review this at standup.

Copy link
Contributor

@jsuereth jsuereth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few concurrency nits / questions on standard Go usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Concurrent map read and map write in collector exporter
2 participants