8000 vrg: synchronize map writes by asn1809 · Pull Request #2065 · RamenDR/ramen · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

vrg: synchronize map writes #2065

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

Merged
merged 1 commit into from
Jun 5, 2025
Merged

Conversation

asn1809
Copy link
Member
@asn1809 asn1809 commented May 29, 2025

Fixes #2048. Issue was seen when concurrent writes to the map was done. To solve the same, sync.Map is being made use of, which is thread safe.

ramen "github.com/ramendr/ramen/api/v1alpha1"
"github.com/ramendr/ramen/internal/controller/util"
corev1 "k8s.io/api/core/v1"
ctrl "sigs.k8s.io/controller-runtime"
)

var vrgLastUploadVersion = map[string]string{}
var vrgLastUploadVersion sync.Map
Copy link
Member

Choose a reason for hiding this comment

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

sync.Map is recommended only for special cases:

The Map type is specialized. Most code should use a plain Go map instead, with separate locking or coordination, for better type safety and to make it easier to maintain other invariants along with the map content.

The Map type is optimized for two common use cases: (1) when the entry for a given key is only ever written once but read many times, as in caches that only grow, or (2) when multiple goroutines read, write, and overwrite entries for disjoint sets of keys. In these two cases, use of a Map may significantly reduce lock contention compared to a Go map paired with a separate Mutex or RWMutex.

See https://pkg.go.dev/sync#Map

If we don't use the special use case, we should use a lock to synchronize access to the map.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @nirs. We read on this and found that we are using special case 2 and hence, chose to proceed with sync.Map.

< 8000 a href="/RamenDR/ramen/pull/2065/commits/19efe45765f670efb4ffdcab521255d53b02a7d1" class="Link--secondary">19efe45
Signed-off-by: Annaraya Narasagond <annarayanarasagond@gmail.com>
@ShyamsundarR ShyamsundarR merged commit 7d5466c into RamenDR:main Jun 5, 2025
36 of 39 checks passed
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.

fatal error: concurrent map writes while protecting kubeobjects - ramen-operator pod crash
3 participants
0