From 4d322df95ecda5fee8149bf5ede29a7666d41514 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 27 Jul 2018 02:10:10 -0700 Subject: [PATCH 1/2] avoid reparsing the multipart form --- weed/storage/needle.go | 12 +++++------- weed/storage/needle_parse_multipart.go | 7 +++++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/weed/storage/needle.go b/weed/storage/needle.go index f67556c72..e071ebbd5 100644 --- a/weed/storage/needle.go +++ b/weed/storage/needle.go @@ -29,12 +29,12 @@ type Needle struct { DataSize uint32 `comment:"Data size"` //version2 Data []byte `comment:"The actual file data"` - Flags byte `comment:"boolean flags"` //version2 - NameSize uint8 //version2 + Flags byte `comment:"boolean flags"` //version2 + NameSize uint8 //version2 Name []byte `comment:"maximum 256 characters"` //version2 - MimeSize uint8 //version2 + MimeSize uint8 //version2 Mime []byte `comment:"maximum 256 characters"` //version2 - PairsSize uint16 //version2 + PairsSize uint16 //version2 Pairs []byte `comment:"additional name value pairs, json format, maximum 64kB"` LastModified uint64 //only store LastModifiedBytesLength bytes, which is 5 bytes to disk Ttl *TTL @@ -59,10 +59,8 @@ func ParseUpload(r *http.Request) ( } } - isChunkedFile, _ = strconv.ParseBool(r.FormValue("cm")) - if r.Method == "POST" { - fileName, data, mimeType, isGzipped, e = parseMultipart(r, isChunkedFile) + fileName, data, mimeType, isGzipped, isChunkedFile, e = parseMultipart(r) } else { isGzipped = false mimeType = r.Header.Get("Content-Type") diff --git a/weed/storage/needle_parse_multipart.go b/weed/storage/needle_parse_multipart.go index af12b994d..de60f4e75 100644 --- a/weed/storage/needle_parse_multipart.go +++ b/weed/storage/needle_parse_multipart.go @@ -8,10 +8,11 @@ import ( "net/http" "path" "strings" + "strconv" ) -func parseMultipart(r *http.Request, isChunkedFile bool) ( - fileName string, data []byte, mimeType string, isGzipped bool, e error) { +func parseMultipart(r *http.Request) ( + fileName string, data []byte, mimeType string, isGzipped, isChunkedFile bool, e error) { form, fe := r.MultipartReader() if fe != nil { glog.V(0).Infoln("MultipartReader [ERROR]", fe) @@ -63,6 +64,8 @@ func parseMultipart(r *http.Request, isChunkedFile bool) ( } } + isChunkedFile, _ = strconv.ParseBool(r.FormValue("cm")) + if !isChunkedFile { dotIndex := strings.LastIndex(fileName, ".") From 10bb76fe6b7351b3131ae56d2faea34b03bf52af Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 27 Jul 2018 02:10:42 -0700 Subject: [PATCH 2/2] go fmt --- weed/storage/needle.go | 8 ++++---- weed/storage/needle_map_metric.go | 2 +- weed/storage/needle_parse_multipart.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/weed/storage/needle.go b/weed/storage/needle.go index e071ebbd5..ce6130711 100644 --- a/weed/storage/needle.go +++ b/weed/storage/needle.go @@ -29,12 +29,12 @@ type Needle struct { DataSize uint32 `comment:"Data size"` //version2 Data []byte `comment:"The actual file data"` - Flags byte `comment:"boolean flags"` //version2 - NameSize uint8 //version2 + Flags byte `comment:"boolean flags"` //version2 + NameSize uint8 //version2 Name []byte `comment:"maximum 256 characters"` //version2 - MimeSize uint8 //version2 + MimeSize uint8 //version2 Mime []byte `comment:"maximum 256 characters"` //version2 - PairsSize uint16 //version2 + PairsSize uint16 //version2 Pairs []byte `comment:"additional name value pairs, json format, maximum 64kB"` LastModified uint64 //only store LastModifiedBytesLength bytes, which is 5 bytes to disk Ttl *TTL diff --git a/weed/storage/needle_map_metric.go b/weed/storage/needle_map_metric.go index 67b41f5a7..cc3d9e028 100644 --- a/weed/storage/needle_map_metric.go +++ b/weed/storage/needle_map_metric.go @@ -109,7 +109,7 @@ func reverseWalkIndexFile(r *os.File, initFn func(entryCount int64), fn func(key return e } for i := int(nextBatchSize) - 1; i >= 0; i-- { - key, offset, size := IdxFileEntry(bytes[i*NeedleEntrySize:i*NeedleEntrySize+NeedleEntrySize]) + key, offset, size := IdxFileEntry(bytes[i*NeedleEntrySize : i*NeedleEntrySize+NeedleEntrySize]) if e = fn(key, offset, size); e != nil { return e } diff --git a/weed/storage/needle_parse_multipart.go b/weed/storage/needle_parse_multipart.go index de60f4e75..d42bc4629 100644 --- a/weed/storage/needle_parse_multipart.go +++ b/weed/storage/needle_parse_multipart.go @@ -7,8 +7,8 @@ import ( "mime" "net/http" "path" - "strings" "strconv" + "strings" ) func parseMultipart(r *http.Request) (