aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2016-06-13 14:34:05 -0700
committerChris Lu <chris.lu@gmail.com>2016-06-13 14:38:35 -0700
commita61453d3ece87efedfca97b2f1b5e1fde1801e4e (patch)
tree959ea78f7eb9dbaecd6d624bca99df2fb5506484
parentf6d75476b9bea404341ddabdf96d3c99e4466052 (diff)
downloadseaweedfs-a61453d3ece87efedfca97b2f1b5e1fde1801e4e.tar.xz
seaweedfs-a61453d3ece87efedfca97b2f1b5e1fde1801e4e.zip
fix nil crash
fix https://github.com/chrislusf/seaweedfs/issues/320
-rw-r--r--weed/operation/lookup_vid_cache.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/weed/operation/lookup_vid_cache.go b/weed/operation/lookup_vid_cache.go
index 1ed03613d..d4980a1f5 100644
--- a/weed/operation/lookup_vid_cache.go
+++ b/weed/operation/lookup_vid_cache.go
@@ -3,6 +3,7 @@ package operation
import (
"errors"
"strconv"
+ "sync"
"time"
"github.com/chrislusf/seaweedfs/weed/glog"
@@ -13,6 +14,7 @@ type VidInfo struct {
NextRefreshTime time.Time
}
type VidCache struct {
+ sync.RWMutex
cache []VidInfo
}
@@ -22,6 +24,8 @@ func (vc *VidCache) Get(vid string) ([]Location, error) {
glog.V(1).Infof("Unknown volume id %s", vid)
return nil, err
}
+ vc.RLock()
+ defer vc.RUnlock()
if 0 < id && id <= len(vc.cache) {
if vc.cache[id-1].Locations == nil {
return nil, errors.New("Not Set")
@@ -39,6 +43,8 @@ func (vc *VidCache) Set(vid string, locations []Location, duration time.Duration
glog.V(1).Infof("Unknown volume id %s", vid)
return
}
+ vc.Lock()
+ defer vc.Unlock()
if id > len(vc.cache) {
for i := id - len(vc.cache); i > 0; i-- {
vc.cache = append(vc.cache, VidInfo{})