diff options
| author | chrislusf <chris.lu@gmail.com> | 2015-05-26 10:29:49 -0700 |
|---|---|---|
| committer | chrislusf <chris.lu@gmail.com> | 2015-05-26 10:29:49 -0700 |
| commit | 32ba7fc6c015cd3f4f83af4a261b89e7262d1477 (patch) | |
| tree | eb71b7a540d3ab094697f497bb9192a1914ab680 /go/operation | |
| parent | 86cd40fba87f7e69c10d1e66e967f6e5e40605b6 (diff) | |
| download | seaweedfs-32ba7fc6c015cd3f4f83af4a261b89e7262d1477.tar.xz seaweedfs-32ba7fc6c015cd3f4f83af4a261b89e7262d1477.zip | |
Fix a possible index out of range error. Remove unnecessary caching.
Diffstat (limited to 'go/operation')
| -rw-r--r-- | go/operation/lookup_vid_cache.go | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/go/operation/lookup_vid_cache.go b/go/operation/lookup_vid_cache.go index 72e7da924..ac4240102 100644 --- a/go/operation/lookup_vid_cache.go +++ b/go/operation/lookup_vid_cache.go @@ -4,6 +4,8 @@ import ( "errors" "strconv" "time" + + "github.com/chrislusf/seaweedfs/go/glog" ) type VidInfo struct { @@ -15,7 +17,11 @@ type VidCache struct { } func (vc *VidCache) Get(vid string) ([]Location, error) { - id, _ := strconv.Atoi(vid) + id, err := strconv.Atoi(vid) + if err != nil { + glog.V(1).Infof("Unknown volume id %s", vid) + return nil, err + } if 0 < id && id <= len(vc.cache) { if vc.cache[id-1].Locations == nil { return nil, errors.New("Not Set") @@ -28,14 +34,18 @@ func (vc *VidCache) Get(vid string) ([]Location, error) { return nil, errors.New("Not Found") } func (vc *VidCache) Set(vid string, locations []Location, duration time.Duration) { - id, _ := strconv.Atoi(vid) - if id >= len(vc.cache) { + id, err := strconv.Atoi(vid) + if err != nil { + glog.V(1).Infof("Unknown volume id %s", vid) + return + } + if id > len(vc.cache) { for i := id - len(vc.cache); i > 0; i-- { vc.cache = append(vc.cache, VidInfo{}) } } - - vc.cache[id-1].Locations = locations - vc.cache[id-1].NextRefreshTime = time.Now().Add(duration) - + if id > 0 { + vc.cache[id-1].Locations = locations + vc.cache[id-1].NextRefreshTime = time.Now().Add(duration) + } } |
