mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-11-24 11:09:12 +08:00
volume.tier.upload progress starts negative #2992
fix https://github.com/chrislusf/seaweedfs/issues/2992
This commit is contained in:
parent
ea8a7a5584
commit
1aae7a3f1b
@ -2,12 +2,11 @@ package s3_backend
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"sync/atomic"
|
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/service/s3/s3iface"
|
"github.com/aws/aws-sdk-go/service/s3/s3iface"
|
||||||
"github.com/aws/aws-sdk-go/service/s3/s3manager"
|
"github.com/aws/aws-sdk-go/service/s3/s3manager"
|
||||||
|
"os"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
)
|
)
|
||||||
@ -42,7 +41,7 @@ func uploadToS3(sess s3iface.S3API, filename string, destBucket string, destKey
|
|||||||
fileReader := &s3UploadProgressedReader{
|
fileReader := &s3UploadProgressedReader{
|
||||||
fp: f,
|
fp: f,
|
||||||
size: fileSize,
|
size: fileSize,
|
||||||
read: -fileSize,
|
signMap: map[int64]struct{}{},
|
||||||
fn: fn,
|
fn: fn,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,10 +64,13 @@ func uploadToS3(sess s3iface.S3API, filename string, destBucket string, destKey
|
|||||||
}
|
}
|
||||||
|
|
||||||
// adapted from https://github.com/aws/aws-sdk-go/pull/1868
|
// adapted from https://github.com/aws/aws-sdk-go/pull/1868
|
||||||
|
// https://github.com/aws/aws-sdk-go/blob/main/example/service/s3/putObjectWithProcess/putObjWithProcess.go
|
||||||
type s3UploadProgressedReader struct {
|
type s3UploadProgressedReader struct {
|
||||||
fp *os.File
|
fp *os.File
|
||||||
size int64
|
size int64
|
||||||
read int64
|
read int64
|
||||||
|
signMap map[int64]struct{}
|
||||||
|
mux sync.Mutex
|
||||||
fn func(progressed int64, percentage float32) error
|
fn func(progressed int64, percentage float32) error
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,8 +84,14 @@ func (r *s3UploadProgressedReader) ReadAt(p []byte, off int64) (int, error) {
|
|||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Got the length have read( or means has uploaded), and you can construct your message
|
r.mux.Lock()
|
||||||
atomic.AddInt64(&r.read, int64(n))
|
// Ignore the first signature call
|
||||||
|
if _, ok := r.signMap[off]; ok {
|
||||||
|
r.read += int64(n)
|
||||||
|
} else {
|
||||||
|
r.signMap[off] = struct{}{}
|
||||||
|
}
|
||||||
|
r.mux.Unlock()
|
||||||
|
|
||||||
if r.fn != nil {
|
if r.fn != nil {
|
||||||
read := r.read
|
read := r.read
|
||||||
|
Loading…
Reference in New Issue
Block a user