Skip to content

Commit

Permalink
Fix cat message with custom offset
Browse files Browse the repository at this point in the history
  • Loading branch information
reshke committed Jun 7, 2024
1 parent 11a6d87 commit 8e6fcd5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
9 changes: 7 additions & 2 deletions pkg/proc/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions pkg/proc/yrreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/proc/yrreader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand All @@ -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}

Expand Down Expand Up @@ -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}

Expand Down

0 comments on commit 8e6fcd5

Please sign in to comment.