diff options
| author | hilimd <68371223+hilimd@users.noreply.github.com> | 2021-02-23 13:41:30 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-23 13:41:30 +0800 |
| commit | 620b91f23eaf5718088dc9ddcf91540967d0c8a6 (patch) | |
| tree | 04e92a8f92b548e26080040d009f23a51d9cc521 /weed/operation/upload_content.go | |
| parent | 690d7c10b826b53bf823faef76603cd6ad83aa1d (diff) | |
| parent | 90cdf9dcace5595b31104df3a3b7e4038a7db341 (diff) | |
| download | seaweedfs-620b91f23eaf5718088dc9ddcf91540967d0c8a6.tar.xz seaweedfs-620b91f23eaf5718088dc9ddcf91540967d0c8a6.zip | |
Merge pull request #73 from chrislusf/master
sync
Diffstat (limited to 'weed/operation/upload_content.go')
| -rw-r--r-- | weed/operation/upload_content.go | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/weed/operation/upload_content.go b/weed/operation/upload_content.go index fccc24b16..70428bb07 100644 --- a/weed/operation/upload_content.go +++ b/weed/operation/upload_content.go @@ -58,11 +58,12 @@ var ( func init() { HttpClient = &http.Client{Transport: &http.Transport{ + MaxIdleConns: 1024, MaxIdleConnsPerHost: 1024, }} } -var fileNameEscaper = strings.NewReplacer("\\", "\\\\", "\"", "\\\"") +var fileNameEscaper = strings.NewReplacer(`\`, `\\`, `"`, `\"`) // Upload sends a POST request to a volume server to upload the content with adjustable compression level func UploadData(uploadUrl string, filename string, cipher bool, data []byte, isInputCompressed bool, mtype string, pairMap map[string]string, jwt security.EncodedJwt) (uploadResult *UploadResult, err error) { @@ -99,6 +100,7 @@ func retriedUploadData(uploadUrl string, filename string, cipher bool, data []by } else { glog.Warningf("uploading to %s: %v", uploadUrl, err) } + time.Sleep(time.Millisecond * time.Duration(237*(i+1))) } return } @@ -128,7 +130,8 @@ func doUploadData(uploadUrl string, filename string, cipher bool, data []byte, i // gzip if possible // this could be double copying clearDataLen = len(data) - if shouldGzipNow { + clearData := data + if shouldGzipNow && !cipher { compressed, compressErr := util.GzipData(data) // fmt.Printf("data is compressed from %d ==> %d\n", len(data), len(compressed)) if compressErr == nil { @@ -137,7 +140,7 @@ func doUploadData(uploadUrl string, filename string, cipher bool, data []byte, i } } else if isInputCompressed { // just to get the clear data length - clearData, err := util.DecompressData(data) + clearData, err = util.DecompressData(data) if err == nil { clearDataLen = len(clearData) } @@ -148,7 +151,7 @@ func doUploadData(uploadUrl string, filename string, cipher bool, data []byte, i // encrypt cipherKey := util.GenCipherKey() - encryptedData, encryptionErr := util.Encrypt(data, cipherKey) + encryptedData, encryptionErr := util.Encrypt(clearData, cipherKey) if encryptionErr != nil { err = fmt.Errorf("encrypt input: %v", encryptionErr) return @@ -159,26 +162,26 @@ func doUploadData(uploadUrl string, filename string, cipher bool, data []byte, i _, err = w.Write(encryptedData) return }, "", false, len(encryptedData), "", nil, jwt) - if uploadResult != nil { - uploadResult.Name = filename - uploadResult.Mime = mtype - uploadResult.CipherKey = cipherKey + if uploadResult == nil { + return } + uploadResult.Name = filename + uploadResult.Mime = mtype + uploadResult.CipherKey = cipherKey + uploadResult.Size = uint32(clearDataLen) } else { // upload data uploadResult, err = upload_content(uploadUrl, func(w io.Writer) (err error) { _, err = w.Write(data) return }, filename, contentIsGzipped, len(data), mtype, pairMap, jwt) - } - - if uploadResult == nil { - return - } - - uploadResult.Size = uint32(clearDataLen) - if contentIsGzipped { - uploadResult.Gzip = 1 + if uploadResult == nil { + return + } + uploadResult.Size = uint32(clearDataLen) + if contentIsGzipped { + uploadResult.Gzip = 1 + } } return uploadResult, err |
