diff --git a/pkg/proc/interaction.go b/pkg/proc/interaction.go index 5d2dbd4..a4583e0 100644 --- a/pkg/proc/interaction.go +++ b/pkg/proc/interaction.go @@ -39,7 +39,7 @@ func ProcConn(s storage.StorageInteractor, cr crypt.Crypter, ycl client.YproxyCl ycl.SetExternalFilePath(msg.Name) - yr := NewYRetryReader(NewRestartReader(s, msg.Name), msg.StartOffset) + yr := NewYRetryReader(NewRestartReader(s, msg.Name)) var contentReader io.Reader contentReader = yr @@ -54,6 +54,11 @@ func ProcConn(s storage.StorageInteractor, cr crypt.Crypter, ycl client.YproxyCl return err } } + + if msg.StartOffset != 0 { + io.CopyN(io.Discard, contentReader, int64(msg.StartOffset)) + } + n, err := io.Copy(ycl.GetRW(), contentReader) if err != nil { _ = ycl.ReplyError(err, "copy failed to complete") @@ -211,7 +216,7 @@ func ProcConn(s storage.StorageInteractor, cr crypt.Crypter, ycl client.YproxyCl path := strings.TrimPrefix(objectMetas[i].Path, instanceCnf.StorageCnf.StoragePrefix) //get reader - readerFromOldBucket := NewYRetryReader(NewRestartReader(oldStorage, path), 0) + readerFromOldBucket := NewYRetryReader(NewRestartReader(oldStorage, path)) var fromReader io.Reader fromReader = readerFromOldBucket defer readerFromOldBucket.Close() diff --git a/pkg/proc/yrreader.go b/pkg/proc/yrreader.go index 924d6f1..642cdb0 100644 --- a/pkg/proc/yrreader.go +++ b/pkg/proc/yrreader.go @@ -125,11 +125,11 @@ const ( defaultRetryLimit = 100 ) -func NewYRetryReader(r RestartReader, initOffset uint64) io.ReadCloser { +func NewYRetryReader(r RestartReader) io.ReadCloser { return &YproxyRetryReader{ underlying: r, retryLimit: defaultRetryLimit, - offsetReached: int64(initOffset), + offsetReached: 0, needReacquire: true, /* do initial storage request */ } } diff --git a/pkg/proc/yrreader_test.go b/pkg/proc/yrreader_test.go index b4d6914..edd0a63 100644 --- a/pkg/proc/yrreader_test.go +++ b/pkg/proc/yrreader_test.go @@ -17,7 +17,7 @@ func TestYproxyRetryReaderEmpty(t *testing.T) { rr := mock.NewMockRestartReader(ctrl) - yr := proc.NewYRetryReader(rr, 0) + yr := proc.NewYRetryReader(rr) buf := []byte{1, 233, 45} @@ -38,7 +38,7 @@ func TestYproxyRetryReaderSimpleRead(t *testing.T) { rr := mock.NewMockRestartReader(ctrl) - yr := proc.NewYRetryReader(rr, 0) + yr := proc.NewYRetryReader(rr) buf := []byte{0, 0, 0} @@ -74,7 +74,7 @@ func TestYproxyRetryReaderSimpleReadRetry(t *testing.T) { rr := mock.NewMockRestartReader(ctrl) - yr := proc.NewYRetryReader(rr, 0) + yr := proc.NewYRetryReader(rr) buf := []byte{0, 0, 0}