diff options
Diffstat (limited to 'weed/operation')
| -rw-r--r-- | weed/operation/lookup.go | 17 | ||||
| -rw-r--r-- | weed/operation/tail_volume.go | 2 |
2 files changed, 12 insertions, 7 deletions
diff --git a/weed/operation/lookup.go b/weed/operation/lookup.go index 0372e47b0..ea68f8763 100644 --- a/weed/operation/lookup.go +++ b/weed/operation/lookup.go @@ -79,16 +79,21 @@ func LookupFileId(masterFn GetMasterFn, fileId string) (fullUrl string, err erro return "http://" + lookup.Locations[rand.Intn(len(lookup.Locations))].Url + "/" + fileId, nil } +func LookupVolumeId(masterFn GetMasterFn, grpcDialOption grpc.DialOption, vid string) (*LookupResult, error) { + results, err := LookupVolumeIds(masterFn, grpcDialOption, []string{vid}) + return results[vid], err +} + // LookupVolumeIds find volume locations by cache and actual lookup -func LookupVolumeIds(masterFn GetMasterFn, grpcDialOption grpc.DialOption, vids []string) (map[string]LookupResult, error) { - ret := make(map[string]LookupResult) +func LookupVolumeIds(masterFn GetMasterFn, grpcDialOption grpc.DialOption, vids []string) (map[string]*LookupResult, error) { + ret := make(map[string]*LookupResult) var unknown_vids []string //check vid cache first for _, vid := range vids { - locations, cache_err := vc.Get(vid) - if cache_err == nil { - ret[vid] = LookupResult{VolumeId: vid, Locations: locations} + locations, cacheErr := vc.Get(vid) + if cacheErr == nil { + ret[vid] = &LookupResult{VolumeId: vid, Locations: locations} } else { unknown_vids = append(unknown_vids, vid) } @@ -122,7 +127,7 @@ func LookupVolumeIds(masterFn GetMasterFn, grpcDialOption grpc.DialOption, vids if vidLocations.Error != "" { vc.Set(vidLocations.VolumeId, locations, 10*time.Minute) } - ret[vidLocations.VolumeId] = LookupResult{ + ret[vidLocations.VolumeId] = &LookupResult{ VolumeId: vidLocations.VolumeId, Locations: locations, Error: vidLocations.Error, diff --git a/weed/operation/tail_volume.go b/weed/operation/tail_volume.go index 79a5b3812..e3f2c0664 100644 --- a/weed/operation/tail_volume.go +++ b/weed/operation/tail_volume.go @@ -13,7 +13,7 @@ import ( func TailVolume(masterFn GetMasterFn, grpcDialOption grpc.DialOption, vid needle.VolumeId, sinceNs uint64, timeoutSeconds int, fn func(n *needle.Needle) error) error { // find volume location, replication, ttl info - lookup, err := Lookup(masterFn, vid.String()) + lookup, err := LookupVolumeId(masterFn, grpcDialOption, vid.String()) if err != nil { return fmt.Errorf("look up volume %d: %v", vid, err) } |
