Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] lightning: store read bytes in compressReader #54808

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions br/pkg/storage/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ func InterceptDecompressReader(
if compressType == NoCompression {
return fileReader, nil
}
fileReader = &OffsetReader{
Reader: fileReader,
Closer: fileReader,
Seeker: fileReader,
}
r, err := newCompressReader(compressType, cfg, fileReader)
if err != nil {
return nil, errors.Trace(err)
Expand Down
23 changes: 23 additions & 0 deletions br/pkg/storage/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/klauspost/compress/zstd"
"github.com/pingcap/errors"
"github.com/pingcap/log"
berrors "github.com/pingcap/tidb/br/pkg/errors"
"go.uber.org/atomic"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -54,6 +56,27 @@ type interceptBuffer interface {
Compressed() bool
}

type OffsetReader struct {
io.Reader
io.Seeker
io.Closer
offset atomic.Int64
}

func (r *OffsetReader) Read(p []byte) (int, error) {
n, err := r.Reader.Read(p)
r.offset.Add(int64(n))
return n, err
}

func (r *OffsetReader) Seek(offset int64, whence int) (int64, error) {
return r.offset.Load(), nil
}

func (r *OffsetReader) GetFileSize() (int64, error) {
return 0, errors.Annotatef(berrors.ErrUnsupportedOperation, "OffsetReader doesn't support GetFileSize now")
}

func createSuffixString(compressType CompressType) string {
txtSuffix := ".txt"
switch compressType {
Expand Down
Loading