mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-02-20 01:28:45 +01:00
chore: enable exposedSyncMutex rule from go-critic (#24026)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
@@ -37,8 +37,7 @@ type Consistent struct {
|
||||
loadMap map[string]*Host
|
||||
totalLoad int64
|
||||
replicationFactor int
|
||||
|
||||
sync.RWMutex
|
||||
lock sync.RWMutex
|
||||
}
|
||||
|
||||
type item struct {
|
||||
@@ -68,8 +67,8 @@ func NewWithReplicationFactor(replicationFactor int) *Consistent {
|
||||
}
|
||||
|
||||
func (c *Consistent) Add(server string) {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if _, ok := c.loadMap[server]; ok {
|
||||
return
|
||||
@@ -87,8 +86,8 @@ func (c *Consistent) Add(server string) {
|
||||
// As described in https://en.wikipedia.org/wiki/Consistent_hashing
|
||||
// It returns ErrNoHosts if the ring has no servers in it.
|
||||
func (c *Consistent) Get(client string) (string, error) {
|
||||
c.RLock()
|
||||
defer c.RUnlock()
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
|
||||
if c.clients.Len() == 0 {
|
||||
return "", ErrNoHosts
|
||||
@@ -116,8 +115,8 @@ func (c *Consistent) Get(client string) (string, error) {
|
||||
// https://research.googleblog.com/2017/04/consistent-hashing-with-bounded-loads.html
|
||||
// It returns ErrNoHosts if the ring has no hosts in it.
|
||||
func (c *Consistent) GetLeast(client string) (string, error) {
|
||||
c.RLock()
|
||||
defer c.RUnlock()
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
|
||||
if c.clients.Len() == 0 {
|
||||
return "", ErrNoHosts
|
||||
@@ -151,8 +150,8 @@ func (c *Consistent) GetLeast(client string) (string, error) {
|
||||
|
||||
// Sets the load of `server` to the given `load`
|
||||
func (c *Consistent) UpdateLoad(server string, load int64) {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if _, ok := c.loadMap[server]; !ok {
|
||||
return
|
||||
@@ -166,8 +165,8 @@ func (c *Consistent) UpdateLoad(server string, load int64) {
|
||||
//
|
||||
// should only be used with if you obtained a host with GetLeast
|
||||
func (c *Consistent) Inc(server string) {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if _, ok := c.loadMap[server]; !ok {
|
||||
return
|
||||
@@ -180,8 +179,8 @@ func (c *Consistent) Inc(server string) {
|
||||
//
|
||||
// should only be used with if you obtained a host with GetLeast
|
||||
func (c *Consistent) Done(server string) {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if _, ok := c.loadMap[server]; !ok {
|
||||
return
|
||||
@@ -192,8 +191,8 @@ func (c *Consistent) Done(server string) {
|
||||
|
||||
// Deletes host from the ring
|
||||
func (c *Consistent) Remove(server string) bool {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
for i := 0; i < c.replicationFactor; i++ {
|
||||
h := c.hash(fmt.Sprintf("%s%d", server, i))
|
||||
@@ -206,8 +205,8 @@ func (c *Consistent) Remove(server string) bool {
|
||||
|
||||
// Return the list of servers in the ring
|
||||
func (c *Consistent) Servers() (servers []string) {
|
||||
c.RLock()
|
||||
defer c.RUnlock()
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
for k := range c.loadMap {
|
||||
servers = append(servers, k)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user