aboutsummaryrefslogtreecommitdiff
path: root/weed-fs/src/cmd
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2012-09-27 12:17:27 -0700
committerChris Lu <chris.lu@gmail.com>2012-09-27 12:17:27 -0700
commit5cb38f9ea744d32ce4157ef6bf9fe16f342a455f (patch)
tree11793193122491e4a39b0845940442d51e515344 /weed-fs/src/cmd
parent2fd6b65a9e7db98eed8ea60d3ecc7f6ac7407695 (diff)
downloadseaweedfs-5cb38f9ea744d32ce4157ef6bf9fe16f342a455f.tar.xz
seaweedfs-5cb38f9ea744d32ce4157ef6bf9fe16f342a455f.zip
use one-liner debug(messages)
Diffstat (limited to 'weed-fs/src/cmd')
-rw-r--r--weed-fs/src/cmd/weed/fix.go8
-rw-r--r--weed-fs/src/cmd/weed/master.go4
-rw-r--r--weed-fs/src/cmd/weed/upload.go12
-rw-r--r--weed-fs/src/cmd/weed/volume.go47
-rw-r--r--weed-fs/src/cmd/weed/weed.go6
5 files changed, 25 insertions, 52 deletions
diff --git a/weed-fs/src/cmd/weed/fix.go b/weed-fs/src/cmd/weed/fix.go
index 0b9088f32..acf2d6643 100644
--- a/weed-fs/src/cmd/weed/fix.go
+++ b/weed-fs/src/cmd/weed/fix.go
@@ -51,14 +51,10 @@ func runFix(cmd *Command, args []string) bool {
nm := storage.NewNeedleMap(indexFile)
offset := uint32(storage.SuperBlockSize)
for n != nil {
- if *IsDebug {
- log.Println("key", n.Id, "volume offset", offset, "data_size", n.Size, "length", length)
- }
+ debug("key", n.Id, "volume offset", offset, "data_size", n.Size, "length", length)
if n.Size > 0 {
count, pe := nm.Put(n.Id, offset/8, n.Size)
- if *IsDebug {
- log.Println("saved", count, "with error", pe)
- }
+ debug("saved", count, "with error", pe)
}
offset += length
n, length = storage.ReadNeedle(dataFile)
diff --git a/weed-fs/src/cmd/weed/master.go b/weed-fs/src/cmd/weed/master.go
index 8379642d9..bdeb2e78d 100644
--- a/weed-fs/src/cmd/weed/master.go
+++ b/weed-fs/src/cmd/weed/master.go
@@ -100,9 +100,7 @@ func dirJoinHandler(w http.ResponseWriter, r *http.Request) {
publicUrl := r.FormValue("publicUrl")
volumes := new([]storage.VolumeInfo)
json.Unmarshal([]byte(r.FormValue("volumes")), volumes)
- if *IsDebug {
- log.Println(s, "volumes", r.FormValue("volumes"))
- }
+ debug(s, "volumes", r.FormValue("volumes"))
topo.RegisterVolumes(*volumes, ip, port, publicUrl, maxVolumeCount)
}
diff --git a/weed-fs/src/cmd/weed/upload.go b/weed-fs/src/cmd/weed/upload.go
index 78b2452ff..882459c05 100644
--- a/weed-fs/src/cmd/weed/upload.go
+++ b/weed-fs/src/cmd/weed/upload.go
@@ -43,9 +43,7 @@ func assign(count int) (*AssignResult, error) {
values.Add("count", strconv.Itoa(count))
values.Add("replication", *uploadReplication)
jsonBlob, err := util.Post("http://"+*server+"/dir/assign", values)
- if *IsDebug {
- fmt.Println("assign result :", string(jsonBlob))
- }
+ debug("assign result :", string(jsonBlob))
if err != nil {
return nil, err
}
@@ -61,14 +59,10 @@ func assign(count int) (*AssignResult, error) {
}
func upload(filename string, server string, fid string) (int, error) {
- if *IsDebug {
- fmt.Println("Start uploading file:", filename)
- }
+ debug("Start uploading file:", filename)
fh, err := os.Open(filename)
if err != nil {
- if *IsDebug {
- fmt.Println("Failed to open file:", filename)
- }
+ debug("Failed to open file:", filename)
return 0, err
}
ret, e := operation.Upload("http://"+server+"/"+fid, filename, fh)
diff --git a/weed-fs/src/cmd/weed/volume.go b/weed-fs/src/cmd/weed/volume.go
index 5a09548a5..cb052a4be 100644
--- a/weed-fs/src/cmd/weed/volume.go
+++ b/weed-fs/src/cmd/weed/volume.go
@@ -49,9 +49,7 @@ func assignVolumeHandler(w http.ResponseWriter, r *http.Request) {
} else {
writeJson(w, r, map[string]string{"error": err.Error()})
}
- if *IsDebug {
- log.Println("volume =", r.FormValue("volume"), ", replicationType =", r.FormValue("replicationType"), ", error =", err)
- }
+ debug("volume =", r.FormValue("volume"), ", replicationType =", r.FormValue("replicationType"), ", error =", err)
}
func storeHandler(w http.ResponseWriter, r *http.Request) {
switch r.Method {
@@ -68,40 +66,28 @@ func GetHandler(w http.ResponseWriter, r *http.Request) {
vid, fid, ext := parseURLPath(r.URL.Path)
volumeId, err := storage.NewVolumeId(vid)
if err != nil {
- if *IsDebug {
- log.Println("parsing error:", err, r.URL.Path)
- }
+ debug("parsing error:", err, r.URL.Path)
return
}
n.ParsePath(fid)
- if *IsDebug {
- log.Println("volume", volumeId, "reading", n)
- }
+ debug("volume", volumeId, "reading", n)
if !store.HasVolume(volumeId) {
lookupResult, err := operation.Lookup(*masterNode, volumeId)
- if *IsDebug {
- log.Println("volume", volumeId, "found on", lookupResult, "error", err)
- }
+ debug("volume", volumeId, "found on", lookupResult, "error", err)
if err == nil {
http.Redirect(w, r, "http://"+lookupResult.Locations[0].PublicUrl+r.URL.Path, http.StatusMovedPermanently)
} else {
- if *IsDebug {
- log.Println("lookup error:", err, r.URL.Path)
- }
+ debug("lookup error:", err, r.URL.Path)
w.WriteHeader(http.StatusNotFound)
}
return
}
cookie := n.Cookie
count, e := store.Read(volumeId, n)
- if *IsDebug {
- log.Println("read bytes", count, "error", e)
- }
+ debug("read bytes", count, "error", e)
if e != nil || count <= 0 {
- if *IsDebug {
- log.Println("read error:", e, r.URL.Path)
- }
+ debug("read error:", e, r.URL.Path)
w.WriteHeader(http.StatusNotFound)
return
}
@@ -171,9 +157,7 @@ func DeleteHandler(w http.ResponseWriter, r *http.Request) {
volumeId, _ := storage.NewVolumeId(vid)
n.ParsePath(fid)
- if *IsDebug {
- log.Println("deleting", n)
- }
+ debug("deleting", n)
cookie := n.Cookie
count, ok := store.Read(volumeId, n)
@@ -213,6 +197,7 @@ func DeleteHandler(w http.ResponseWriter, r *http.Request) {
m["size"] = uint32(count)
writeJson(w, r, m)
}
+
func parseURLPath(path string) (vid, fid, ext string) {
sepIndex := strings.LastIndex(path, "/")
@@ -234,23 +219,17 @@ func parseURLPath(path string) (vid, fid, ext string) {
return
}
-type distributedFunction func(location operation.Location) bool
-
-func distributedOperation(volumeId storage.VolumeId, op distributedFunction) bool {
+func distributedOperation(volumeId storage.VolumeId, op func(location operation.Location) bool) bool {
if lookupResult, lookupErr := operation.Lookup(*masterNode, volumeId); lookupErr == nil {
length := 0
- sem := make(chan int, len(lookupResult.Locations))
selfUrl := (*ip + ":" + strconv.Itoa(*vport))
results := make(chan bool)
for _, location := range lookupResult.Locations {
if location.Url != selfUrl {
- sem <- 1
length++
- go func(op distributedFunction, location operation.Location, sem chan int, results chan bool) {
- ret := op(location)
- <-sem
- results <- ret
- }(op, location, sem, results)
+ go func(location operation.Location, results chan bool) {
+ results <- op(location)
+ }(location, results)
}
}
ret := true
diff --git a/weed-fs/src/cmd/weed/weed.go b/weed-fs/src/cmd/weed/weed.go
index 0cff9bfeb..d3f76a10a 100644
--- a/weed-fs/src/cmd/weed/weed.go
+++ b/weed-fs/src/cmd/weed/weed.go
@@ -184,3 +184,9 @@ func writeJson(w http.ResponseWriter, r *http.Request, obj interface{}) {
w.Write([]uint8(")"))
}
}
+
+func debug(params ...interface{}){
+ if *IsDebug {
+ fmt.Println(params)
+ }
+}