Browse Source

Merge pull request #141 from agin719/cos-v4-dev

update ctx
master
agin719 4 years ago
committed by GitHub
parent
commit
f56d1a2c25
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      object.go
  2. 6
      object_part.go

12
object.go

@ -667,7 +667,7 @@ func (drc *DiscardReadCloser) Close() error {
return nil return nil
} }
func worker(s *ObjectService, jobs <-chan *Jobs, results chan<- *Results) {
func worker(ctx context.Context, s *ObjectService, jobs <-chan *Jobs, results chan<- *Results) {
for j := range jobs { for j := range jobs {
j.Opt.ContentLength = j.Chunk.Size j.Opt.ContentLength = j.Chunk.Size
@ -684,7 +684,7 @@ func worker(s *ObjectService, jobs <-chan *Jobs, results chan<- *Results) {
break break
} }
fd.Seek(j.Chunk.OffSet, os.SEEK_SET) fd.Seek(j.Chunk.OffSet, os.SEEK_SET)
resp, err := s.UploadPart(context.Background(), j.Name, j.UploadId, j.Chunk.Number,
resp, err := s.UploadPart(ctx, j.Name, j.UploadId, j.Chunk.Number,
LimitReadCloser(fd, j.Chunk.Size), j.Opt) LimitReadCloser(fd, j.Chunk.Size), j.Opt)
res.PartNumber = j.Chunk.Number res.PartNumber = j.Chunk.Number
res.Resp = resp res.Resp = resp
@ -703,7 +703,7 @@ func worker(s *ObjectService, jobs <-chan *Jobs, results chan<- *Results) {
} }
} }
func downloadWorker(s *ObjectService, jobs <-chan *Jobs, results chan<- *Results) {
func downloadWorker(ctx context.Context, s *ObjectService, jobs <-chan *Jobs, results chan<- *Results) {
for j := range jobs { for j := range jobs {
opt := &RangeOptions{ opt := &RangeOptions{
HasStart: true, HasStart: true,
@ -716,7 +716,7 @@ func downloadWorker(s *ObjectService, jobs <-chan *Jobs, results chan<- *Results
for { for {
var res Results var res Results
res.PartNumber = j.Chunk.Number res.PartNumber = j.Chunk.Number
resp, err := s.Get(context.Background(), j.Name, j.DownOpt, j.VersionId...)
resp, err := s.Get(ctx, j.Name, j.DownOpt, j.VersionId...)
res.err = err res.err = err
res.Resp = resp res.Resp = resp
if err != nil { if err != nil {
@ -972,7 +972,7 @@ func (s *ObjectService) Upload(ctx context.Context, name string, filepath string
// 3.Start worker // 3.Start worker
for w := 1; w <= poolSize; w++ { for w := 1; w <= poolSize; w++ {
go worker(s, chjobs, chresults)
go worker(ctx, s, chjobs, chresults)
} }
// progress started event // progress started event
@ -1241,7 +1241,7 @@ func (s *ObjectService) Download(ctx context.Context, name string, filepath stri
chjobs := make(chan *Jobs, 100) chjobs := make(chan *Jobs, 100)
chresults := make(chan *Results, 10000) chresults := make(chan *Results, 10000)
for w := 1; w <= poolSize; w++ { for w := 1; w <= poolSize; w++ {
go downloadWorker(s, chjobs, chresults)
go downloadWorker(ctx, s, chjobs, chresults)
} }
go func() { go func() {

6
object_part.go

@ -353,13 +353,13 @@ type CopyResults struct {
res *CopyPartResult res *CopyPartResult
} }
func copyworker(s *ObjectService, jobs <-chan *CopyJobs, results chan<- *CopyResults) {
func copyworker(ctx context.Context, s *ObjectService, jobs <-chan *CopyJobs, results chan<- *CopyResults) {
for j := range jobs { for j := range jobs {
var copyres CopyResults var copyres CopyResults
j.Opt.XCosCopySourceRange = fmt.Sprintf("bytes=%d-%d", j.Chunk.OffSet, j.Chunk.OffSet+j.Chunk.Size-1) j.Opt.XCosCopySourceRange = fmt.Sprintf("bytes=%d-%d", j.Chunk.OffSet, j.Chunk.OffSet+j.Chunk.Size-1)
rt := j.RetryTimes rt := j.RetryTimes
for { for {
res, resp, err := s.CopyPart(context.Background(), j.Name, j.UploadId, j.Chunk.Number, j.Opt.XCosCopySource, j.Opt)
res, resp, err := s.CopyPart(ctx, j.Name, j.UploadId, j.Chunk.Number, j.Opt.XCosCopySource, j.Opt)
copyres.PartNumber = j.Chunk.Number copyres.PartNumber = j.Chunk.Number
copyres.Resp = resp copyres.Resp = resp
copyres.err = err copyres.err = err
@ -456,7 +456,7 @@ func (s *ObjectService) MultiCopy(ctx context.Context, name string, sourceURL st
optcom := &CompleteMultipartUploadOptions{} optcom := &CompleteMultipartUploadOptions{}
for w := 1; w <= poolSize; w++ { for w := 1; w <= poolSize; w++ {
go copyworker(s, chjobs, chresults)
go copyworker(ctx, s, chjobs, chresults)
} }
go func() { go func() {

Loading…
Cancel
Save