Skip to content

Commit

Permalink
Fix wrap reader
Browse files Browse the repository at this point in the history
  • Loading branch information
yzang2019 committed Oct 10, 2023
1 parent 352cdf1 commit e032e12
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
1 change: 0 additions & 1 deletion changeset/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ func WriteChangeSet(writer io.Writer, version int64, cs iavl.ChangeSet) error {
return nil
}

fmt.Printf("Writing Version: %d\n", version)
var size int
items := make([][]byte, 0, len(cs.Pairs))
for _, pair := range cs.Pairs {
Expand Down
4 changes: 2 additions & 2 deletions changeset/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func openChangesetFile(fileName string) (Reader, error) {
return nil, err
}
zstdReaderCloser := zstd.NewReader(fp)
return &WrapReader{zstdReaderCloser, fp}, nil
return &WrappedReader{zstdReaderCloser, fp}, nil
}

func iterateChangeSet(reader Reader, fn func(version int64, changeset *iavl.ChangeSet) (bool, error)) (int64, error) {
Expand Down Expand Up @@ -127,7 +127,7 @@ func readKVPair(reader Reader) (*iavl.KVPair, error) {
if _, err := io.ReadFull(reader, pair.Key); err != nil {
return nil, err
}

if pair.Delete {
return &pair, nil
}
Expand Down
8 changes: 4 additions & 4 deletions changeset/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import (
"io"
)

type WrapReader struct {
type WrappedReader struct {
readerCloser io.ReadCloser
closer io.Closer
}

func (r *WrapReader) Read(p []byte) (int, error) {
func (r *WrappedReader) Read(p []byte) (int, error) {
return r.readerCloser.Read(p)
}

func (r *WrapReader) ReadByte() (byte, error) {
func (r *WrappedReader) ReadByte() (byte, error) {
var singleByte [1]byte
_, err := r.readerCloser.Read(singleByte[:])
return singleByte[0], err
}

func (r *WrapReader) Close() error {
func (r *WrappedReader) Close() error {
var errs []error
if closer, ok := r.readerCloser.(io.Closer); ok {
err := closer.Close()
Expand Down
15 changes: 7 additions & 8 deletions cmd/changeset/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ func handlePrintChangeset(cmd *cobra.Command, _ []string) error {
if inputFile == "" {
return errors.New("input-file is required")
}
importer := changeset.NewImporter(inputFile).
WithProcessFn(func(version int64, cs *iavl.ChangeSet) (bool, error) {
if cs != nil {
for _, pair := range cs.Pairs {
fmt.Printf("Version: %d, delete: %t, key: %X, value: %X\n", version, pair.Delete, pair.Key, pair.Value)
}
importer := changeset.NewImporter(inputFile).WithProcessFn(func(version int64, cs *iavl.ChangeSet) (bool, error) {
if cs != nil {
for _, pair := range cs.Pairs {
fmt.Printf("Version: %d, delete: %t, key: %X, value: %X\n", version, pair.Delete, pair.Key, pair.Value)
}
return true, nil
})
}
return true, nil
})
_, err := importer.Start()
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/cosmos/iavl
go 1.18

require (
github.com/DataDog/zstd v1.4.5
github.com/alitto/pond v1.8.3
github.com/confio/ics23/go v0.7.0
github.com/gogo/protobuf v1.3.2
Expand All @@ -17,7 +18,6 @@ require (
)

require (
github.com/DataDog/zstd v1.4.5 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgraph-io/badger/v2 v2.2007.2 // indirect
Expand Down

0 comments on commit e032e12

Please sign in to comment.