revert bytebufferpool, seems problematic

This commit is contained in:
Chris Lu 2020-11-02 13:49:38 -08:00
parent e1423a83dd
commit e0fcab47c0

View file

@ -19,7 +19,6 @@ import (
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb" "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
"github.com/chrislusf/seaweedfs/weed/security" "github.com/chrislusf/seaweedfs/weed/security"
"github.com/chrislusf/seaweedfs/weed/util" "github.com/chrislusf/seaweedfs/weed/util"
"github.com/valyala/bytebufferpool"
) )
type UploadResult struct { type UploadResult struct {
@ -81,14 +80,11 @@ func doUpload(uploadUrl string, filename string, cipher bool, reader io.Reader,
if ok { if ok {
data = bytesReader.Bytes data = bytesReader.Bytes
} else { } else {
buf := bytebufferpool.Get() data, err = ioutil.ReadAll(reader)
_, err = buf.ReadFrom(reader)
defer bytebufferpool.Put(buf)
if err != nil { if err != nil {
err = fmt.Errorf("read input: %v", err) err = fmt.Errorf("read input: %v", err)
return return
} }
data = buf.Bytes()
} }
uploadResult, uploadErr := retriedUploadData(uploadUrl, filename, cipher, data, isInputCompressed, mtype, pairMap, jwt) uploadResult, uploadErr := retriedUploadData(uploadUrl, filename, cipher, data, isInputCompressed, mtype, pairMap, jwt)
return uploadResult, uploadErr, data 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) { 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() body_buf := bytes.NewBufferString("")
defer bytebufferpool.Put(buf) body_writer := multipart.NewWriter(body_buf)
body_writer := multipart.NewWriter(buf)
h := make(textproto.MIMEHeader) h := make(textproto.MIMEHeader)
h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, fileNameEscaper.Replace(filename))) h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, fileNameEscaper.Replace(filename)))
if mtype == "" { if mtype == "" {
@ -218,7 +213,7 @@ func upload_content(uploadUrl string, fillBufferFunction func(w io.Writer) error
return nil, err return nil, err
} }
req, postErr := http.NewRequest("POST", uploadUrl, bytes.NewReader(buf.Bytes())) req, postErr := http.NewRequest("POST", uploadUrl, body_buf)
if postErr != nil { if postErr != nil {
glog.V(1).Infof("create upload request %s: %v", uploadUrl, postErr) glog.V(1).Infof("create upload request %s: %v", uploadUrl, postErr)
return nil, fmt.Errorf("create upload request %s: %v", uploadUrl, postErr) return nil, fmt.Errorf("create upload request %s: %v", uploadUrl, postErr)