From e0fcab47c00bbebf2352000bc8f8a9a2e30c076f Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Mon, 2 Nov 2020 13:49:38 -0800 Subject: [PATCH] revert bytebufferpool, seems problematic --- weed/operation/upload_content.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/weed/operation/upload_content.go b/weed/operation/upload_content.go index 3e96b5909..c0d82f972 100644 --- a/weed/operation/upload_content.go +++ b/weed/operation/upload_content.go @@ -19,7 +19,6 @@ import ( "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" "github.com/chrislusf/seaweedfs/weed/security" "github.com/chrislusf/seaweedfs/weed/util" - "github.com/valyala/bytebufferpool" ) type UploadResult struct { @@ -81,14 +80,11 @@ func doUpload(uploadUrl string, filename string, cipher bool, reader io.Reader, if ok { data = bytesReader.Bytes } else { - buf := bytebufferpool.Get() - _, err = buf.ReadFrom(reader) - defer bytebufferpool.Put(buf) + data, err = ioutil.ReadAll(reader) if err != nil { err = fmt.Errorf("read input: %v", err) return } - data = buf.Bytes() } uploadResult, uploadErr := retriedUploadData(uploadUrl, filename, cipher, data, isInputCompressed, mtype, pairMap, jwt) return uploadResult, uploadErr, data @@ -188,9 +184,8 @@ func doUploadData(uploadUrl string, filename string, cipher bool, data []byte, i } func upload_content(uploadUrl string, fillBufferFunction func(w io.Writer) error, filename string, isGzipped bool, originalDataSize int, mtype string, pairMap map[string]string, jwt security.EncodedJwt) (*UploadResult, error) { - buf := bytebufferpool.Get() - defer bytebufferpool.Put(buf) - body_writer := multipart.NewWriter(buf) + body_buf := bytes.NewBufferString("") + body_writer := multipart.NewWriter(body_buf) h := make(textproto.MIMEHeader) h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, fileNameEscaper.Replace(filename))) if mtype == "" { @@ -218,7 +213,7 @@ func upload_content(uploadUrl string, fillBufferFunction func(w io.Writer) error return nil, err } - req, postErr := http.NewRequest("POST", uploadUrl, bytes.NewReader(buf.Bytes())) + req, postErr := http.NewRequest("POST", uploadUrl, body_buf) if postErr != nil { glog.V(1).Infof("create upload request %s: %v", uploadUrl, postErr) return nil, fmt.Errorf("create upload request %s: %v", uploadUrl, postErr)