aboutsummaryrefslogtreecommitdiff
path: root/go/operation/lookup.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2014-05-25 14:01:54 -0700
committerChris Lu <chris.lu@gmail.com>2014-05-25 14:01:54 -0700
commitb5f99b26ebd8b7a2b86816a9a372a49af7bb260b (patch)
treea90821c9f30b037a81d1188364e6b1f3dd0f4e10 /go/operation/lookup.go
parent38260fcfb1437fc9d37b027aa289bd7b585743ec (diff)
downloadseaweedfs-b5f99b26ebd8b7a2b86816a9a372a49af7bb260b.tar.xz
seaweedfs-b5f99b26ebd8b7a2b86816a9a372a49af7bb260b.zip
Add volume id lookup caching
Diffstat (limited to 'go/operation/lookup.go')
-rw-r--r--go/operation/lookup.go18
1 files changed, 17 insertions, 1 deletions
diff --git a/go/operation/lookup.go b/go/operation/lookup.go
index e9d1586a3..2eea1ab34 100644
--- a/go/operation/lookup.go
+++ b/go/operation/lookup.go
@@ -8,6 +8,7 @@ import (
"math/rand"
"net/url"
"strings"
+ "time"
)
type Location struct {
@@ -20,7 +21,22 @@ type LookupResult struct {
Error string `json:"error,omitempty"`
}
-func Lookup(server string, vid string) (*LookupResult, error) {
+var (
+ vc VidCache
+)
+
+func Lookup(server string, vid string) (ret *LookupResult, err error) {
+ locations, cache_err := vc.Get(vid)
+ if cache_err != nil {
+ ret, err = do_lookup(server, vid)
+ vc.Set(vid, ret.Locations, 1*time.Minute)
+ } else {
+ ret = &LookupResult{VolumeId: vid, Locations: locations}
+ }
+ return
+}
+
+func do_lookup(server string, vid string) (*LookupResult, error) {
values := make(url.Values)
values.Add("volumeId", vid)
jsonBlob, err := util.Post("http://"+server+"/dir/lookup", values)