[PR #1156] [CLOSED] Use sync.Map in updatechannel #13357

Open
opened 2026-08-05 02:08:12 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/1156
Author: @surik
Created: 9/20/2023
Status: Closed

Base: mainHead: yury/use-sync-map-in-updatechannel


📝 Commits (6)

  • 025fefc Use sync.Map in PeersUpdateManager
  • 3e20f23 Rework Len() method via atomic counter
  • 206d903 Update error message
  • dece311 Merge remote-tracking branch 'upstream/main' into yury/use-sync-map-in-updatechannel
  • 9bfab10 Merge remote-tracking branch 'upstream/main' into yury/use-sync-map-in-updatechannel
  • 026958c Lock by PeerID when CreateChannel

📊 Changes

3 files changed (+74 additions, -39 deletions)

View changed files

📝 management/server/grpcserver.go (+1 -1)
📝 management/server/updatechannel.go (+53 -31)
📝 management/server/updatechannel_test.go (+20 -7)

📄 Description

Describe your changes

The sync.Map is part of Golang and looks a better fit for the case of concurrently accessing the map of the update channels.

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, the use of a Map may significantly reduce lock contention compared to a Go map paired with a separate Mutex or RWMutex.

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • Extended the README / documentation, if necessary

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/1156 **Author:** [@surik](https://github.com/surik) **Created:** 9/20/2023 **Status:** ❌ Closed **Base:** `main` ← **Head:** `yury/use-sync-map-in-updatechannel` --- ### 📝 Commits (6) - [`025fefc`](https://github.com/netbirdio/netbird/commit/025fefc6bd0ac212f743e9e9c0a73bb91271595e) Use sync.Map in PeersUpdateManager - [`3e20f23`](https://github.com/netbirdio/netbird/commit/3e20f2364643887d46bf52a64a814d52402a665f) Rework Len() method via atomic counter - [`206d903`](https://github.com/netbirdio/netbird/commit/206d903de5f67ac48aae11837b188129a0b026ba) Update error message - [`dece311`](https://github.com/netbirdio/netbird/commit/dece311076c53165e8571691d9f4629deaa5f171) Merge remote-tracking branch 'upstream/main' into yury/use-sync-map-in-updatechannel - [`9bfab10`](https://github.com/netbirdio/netbird/commit/9bfab103a08bd178b70d1f07b02aec83729cc92a) Merge remote-tracking branch 'upstream/main' into yury/use-sync-map-in-updatechannel - [`026958c`](https://github.com/netbirdio/netbird/commit/026958c22aa4ae39e54d58f18cbdb7d205f8ef9d) Lock by PeerID when CreateChannel ### 📊 Changes **3 files changed** (+74 additions, -39 deletions) <details> <summary>View changed files</summary> 📝 `management/server/grpcserver.go` (+1 -1) 📝 `management/server/updatechannel.go` (+53 -31) 📝 `management/server/updatechannel_test.go` (+20 -7) </details> ### 📄 Description ## Describe your changes The [sync.Map](https://pkg.go.dev/sync#Map) is part of Golang and looks a better fit for the case of concurrently accessing the map of the update channels. ``` 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, the use of a Map may significantly reduce lock contention compared to a Go map paired with a separate Mutex or RWMutex. ``` ## Issue ticket number and link ### Checklist - [ ] Is it a bug fix - [ ] Is a typo/documentation fix - [x] Is a feature enhancement - [x] It is a refactor - [ ] Created tests that fail without the change (if possible) - [ ] Extended the README / documentation, if necessary --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 02:08:12 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#13357