From 09ed882e5f34e50b1d1f4e0238e23d04e8de780b Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 24 Aug 2012 01:15:27 -0700 Subject: [PATCH] clean log --- weed-fs/src/cmd/weed/weed.go | 4 ---- weed-fs/src/pkg/directory/file_id.go | 3 +-- weed-fs/src/pkg/storage/compress.go | 7 +++---- weed-fs/src/pkg/storage/needle.go | 7 +++---- weed-fs/src/pkg/storage/storage_limit.go | 21 +++++++++++++++++++ weed-fs/src/pkg/storage/storage_limit_test.go | 11 ++++++++++ weed-fs/src/pkg/storage/store.go | 1 + 7 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 weed-fs/src/pkg/storage/storage_limit.go create mode 100644 weed-fs/src/pkg/storage/storage_limit_test.go diff --git a/weed-fs/src/cmd/weed/weed.go b/weed-fs/src/cmd/weed/weed.go index a6f857023..52361dc60 100644 --- a/weed-fs/src/cmd/weed/weed.go +++ b/weed-fs/src/cmd/weed/weed.go @@ -5,7 +5,6 @@ import ( "flag" "fmt" "io" - "log" "net/http" "os" "strings" @@ -42,7 +41,6 @@ func setExitStatus(n int) { func main() { flag.Usage = usage flag.Parse() - log.SetFlags(0) args := flag.Args() if len(args) < 1 { @@ -172,8 +170,6 @@ func exit() { os.Exit(exitStatus) } -var logf = log.Printf - func exitIfErrors() { if exitStatus != 0 { exit() diff --git a/weed-fs/src/pkg/directory/file_id.go b/weed-fs/src/pkg/directory/file_id.go index 62fc354bf..9ce556580 100644 --- a/weed-fs/src/pkg/directory/file_id.go +++ b/weed-fs/src/pkg/directory/file_id.go @@ -2,7 +2,6 @@ package directory import ( "encoding/hex" - "log" "pkg/storage" "strings" "pkg/util" @@ -20,7 +19,7 @@ func NewFileId(VolumeId storage.VolumeId, Key uint64, Hashcode uint32) *FileId { func ParseFileId(fid string) *FileId{ a := strings.Split(fid, ",") if len(a) != 2 { - log.Println("Invalid fid", fid, ", split length", len(a)) + println("Invalid fid", fid, ", split length", len(a)) return nil } vid_string, key_hash_string := a[0], a[1] diff --git a/weed-fs/src/pkg/storage/compress.go b/weed-fs/src/pkg/storage/compress.go index 74088a3c4..d441db009 100644 --- a/weed-fs/src/pkg/storage/compress.go +++ b/weed-fs/src/pkg/storage/compress.go @@ -5,7 +5,6 @@ import ( "compress/flate" "compress/gzip" "io/ioutil" - "log" "strings" ) @@ -28,10 +27,10 @@ func GzipData(input []byte) []byte { buf := new(bytes.Buffer) w, _ := gzip.NewWriterLevel(buf, flate.BestCompression) if _, err := w.Write(input); err!=nil { - log.Printf("error compressing data:%s\n", err) + println("error compressing data:", err) } if err := w.Close(); err!=nil { - log.Printf("error closing compressed data:%s\n", err) + println("error closing compressed data:", err) } return buf.Bytes() } @@ -41,7 +40,7 @@ func UnGzipData(input []byte) []byte { defer r.Close() output, err := ioutil.ReadAll(r) if err!=nil { - log.Printf("error uncompressing data:%s\n", err) + println("error uncompressing data:", err) } return output } diff --git a/weed-fs/src/pkg/storage/needle.go b/weed-fs/src/pkg/storage/needle.go index ea3cbfb1d..8d3058a1a 100644 --- a/weed-fs/src/pkg/storage/needle.go +++ b/weed-fs/src/pkg/storage/needle.go @@ -4,7 +4,6 @@ import ( "encoding/hex" "io" "io/ioutil" - "log" "mime" "net/http" "os" @@ -27,7 +26,7 @@ func NewNeedle(r *http.Request) (n *Needle, e error) { n = new(Needle) form, fe := r.MultipartReader() if fe != nil { - log.Printf("MultipartReader [ERROR] %s\n", fe) + println("MultipartReader [ERROR]", fe) e = fe return } @@ -60,7 +59,7 @@ func (n *Needle) ParsePath(fid string) { length := len(fid) if length <= 8 { if length > 0 { - log.Println("Invalid fid", fid, "length", length) + println("Invalid fid", fid, "length", length) } return } @@ -118,7 +117,7 @@ func ParseKeyHash(key_hash_string string) (uint64, uint32) { key_hash_bytes, khe := hex.DecodeString(key_hash_string) key_hash_len := len(key_hash_bytes) if khe != nil || key_hash_len <= 4 { - log.Println("Invalid key_hash", key_hash_string, "length:", key_hash_len, "error", khe) + println("Invalid key_hash", key_hash_string, "length:", key_hash_len, "error", khe) return 0, 0 } key := util.BytesToUint64(key_hash_bytes[0 : key_hash_len-4]) diff --git a/weed-fs/src/pkg/storage/storage_limit.go b/weed-fs/src/pkg/storage/storage_limit.go new file mode 100644 index 000000000..915ec48a3 --- /dev/null +++ b/weed-fs/src/pkg/storage/storage_limit.go @@ -0,0 +1,21 @@ +package storage + +import ( + "syscall" +) + +type StorageLimit struct { + sizeLimit uint64 + detectedLimit uint64 +} + +func NewStorageLimit(desiredLimit uint64) *StorageLimit { + s := syscall.Statfs_t{} + errNo := syscall.Statfs(".", &s) + detected := uint64(0) + if errNo==nil { + detected = s.Bavail*uint64(s.Bsize) + } + sl := &StorageLimit{sizeLimit: desiredLimit, detectedLimit: detected} + return sl +} diff --git a/weed-fs/src/pkg/storage/storage_limit_test.go b/weed-fs/src/pkg/storage/storage_limit_test.go new file mode 100644 index 000000000..c818356f9 --- /dev/null +++ b/weed-fs/src/pkg/storage/storage_limit_test.go @@ -0,0 +1,11 @@ +package storage + +import ( + "testing" +) + +func TestReadStorageLimit(t *testing.T) { + sl := NewStorageLimit(1000) + println("detected:",sl.detectedLimit) +} + diff --git a/weed-fs/src/pkg/storage/store.go b/weed-fs/src/pkg/storage/store.go index ef7bc82fd..1c3ba4a51 100644 --- a/weed-fs/src/pkg/storage/store.go +++ b/weed-fs/src/pkg/storage/store.go @@ -15,6 +15,7 @@ type Store struct { dir string Port int PublicUrl string + Limit StorageLimit } func NewStore(port int, publicUrl, dirname string, volumeListString string) (s *Store) {