Skip to content
Snippets Groups Projects
Commit 14100c29 authored by Dean's avatar Dean
Browse files

fix race condition in weed/volume-cache.go, bump patch

parent 57e3eec0
No related branches found
No related tags found
No related merge requests found
......@@ -132,7 +132,7 @@ func main() {
log.Info("Attempting to listen on " + listenAddr)
server := &fasthttp.Server{
Handler: h,
Name: "whats-this/cdn-origin/0.1.0",
Name: "whats-this/cdn-origin/0.1.1",
ReadBufferSize: 1024 * 6, // 6 KB
ReadTimeout: time.Minute * 30,
WriteTimeout: time.Minute * 30,
......
package weed
import "sync"
// VolumeCache stores a volume ID => volume URL map used for caching volume lookup responses from the master of a
// SeaweedFS cluster.
type VolumeCache struct {
sync.RWMutex
volumeCache map[uint32][]string
next map[uint32]int
}
// Add adds a volume ID => location URL slice mapping to the volume cache.
func (v *VolumeCache) Add(id uint32, urls []string) {
v.Lock()
defer v.Unlock()
v.volumeCache[id] = urls
v.next[id] = 0
}
// Get returns all volume server URLs for a given volume ID.
func (v *VolumeCache) Get(id uint32) []string {
v.RLock()
defer v.RUnlock()
vol, _ := v.volumeCache[id]
return vol
}
// GetNext returns the n+1th location URL for the given volume ID, n is tracked internally.
func (v *VolumeCache) GetNext(id uint32) string {
v.RLock()
defer v.RUnlock()
vol, ok := v.volumeCache[id]
volLen := len(vol)
if !ok || volLen == 0 {
......@@ -36,11 +45,15 @@ func (v *VolumeCache) GetNext(id uint32) string {
// Remove removes a volume from the volume cache.
func (v *VolumeCache) Remove(id uint32) {
v.Lock()
defer v.Unlock()
delete(v.volumeCache, id)
}
// Empty clears all data and returns the VolumeCache to it's initial state.
func (v *VolumeCache) Empty() {
v.Lock()
defer v.Unlock()
v.volumeCache = map[uint32][]string{}
v.next = map[uint32]int{}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment