Skip to content

Commit

Permalink
Use RWMutex in copy-on-write tablet list instead of atomic.Value and …
Browse files Browse the repository at this point in the history
…Mutex
  • Loading branch information
sylwiaszunejko committed Nov 28, 2024
1 parent 1cf82d9 commit 7550d6e
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions tablets.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package gocql

import (
"sync"
"sync/atomic"
)

type ReplicaInfo struct {
Expand Down Expand Up @@ -181,27 +180,19 @@ func (t TabletInfoList) findTabletForToken(token Token, l int, r int) *TabletInf

// cowTabletList implements a copy on write tablet list, its equivalent type is TabletInfoList
type cowTabletList struct {
list atomic.Value
mu sync.Mutex
list TabletInfoList
mu sync.RWMutex
}

func (c *cowTabletList) get() TabletInfoList {
l, ok := c.list.Load().(TabletInfoList)
if !ok {
return nil
}
return l
c.mu.RLock()
defer c.mu.RUnlock()
return c.list
}

func (c *cowTabletList) set(tablets TabletInfoList) {
c.mu.Lock()
defer c.mu.Unlock()

n := len(tablets)
t := make(TabletInfoList, n)
for i := 0; i < n; i++ {
t[i] = tablets[i]
}

c.list.Store(t)
c.list = tablets
}

0 comments on commit 7550d6e

Please sign in to comment.