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

Problem: can't read timestamp in versiondb iterator #1688

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Improvements

* [#1684](https://github.com/crypto-org-chain/cronos/pull/1684) versiondb NewKVStore accept string as store name.
* [#]() Add Timestamp api to versiondb iterator.
yihuang marked this conversation as resolved.
Show resolved Hide resolved

*Nov 6, 2024*

Expand Down
10 changes: 8 additions & 2 deletions versiondb/tsrocksdb/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tsrocksdb
import (
"bytes"

"cosmossdk.io/store/types"
"github.com/crypto-org-chain/cronos/versiondb"
"github.com/linxGnu/grocksdb"
)

Expand All @@ -14,7 +14,7 @@ type rocksDBIterator struct {
isInvalid bool
}

var _ types.Iterator = (*rocksDBIterator)(nil)
var _ versiondb.Iterator = (*rocksDBIterator)(nil)

func newRocksDBIterator(source *grocksdb.Iterator, prefix, start, end []byte, isReverse bool) *rocksDBIterator {
if isReverse {
Expand Down Expand Up @@ -94,6 +94,12 @@ func (itr *rocksDBIterator) Valid() bool {
return true
}

// Timestamp implements Iterator.
func (itr *rocksDBIterator) Timestamp() []byte {
itr.assertIsValid()
return moveSliceToBytes(itr.source.Timestamp())
}

// Key implements Iterator.
func (itr *rocksDBIterator) Key() []byte {
itr.assertIsValid()
Expand Down
4 changes: 2 additions & 2 deletions versiondb/tsrocksdb/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (s Store) GetLatestVersion() (int64, error) {
}

// IteratorAtVersion implements VersionStore interface
func (s Store) IteratorAtVersion(storeKey string, start, end []byte, version *int64) (types.Iterator, error) {
func (s Store) IteratorAtVersion(storeKey string, start, end []byte, version *int64) (versiondb.Iterator, error) {
if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) {
return nil, errKeyEmpty
}
Expand All @@ -140,7 +140,7 @@ func (s Store) IteratorAtVersion(storeKey string, start, end []byte, version *in
}

// ReverseIteratorAtVersion implements VersionStore interface
func (s Store) ReverseIteratorAtVersion(storeKey string, start, end []byte, version *int64) (types.Iterator, error) {
func (s Store) ReverseIteratorAtVersion(storeKey string, start, end []byte, version *int64) (versiondb.Iterator, error) {
if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) {
return nil, errKeyEmpty
}
Expand Down
10 changes: 8 additions & 2 deletions versiondb/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ import (
"cosmossdk.io/store/types"
)

type Iterator interface {
types.Iterator

Timestamp() []byte
}

// VersionStore is a versioned storage of a flat key-value pairs.
// it don't need to support merkle proof, so could be implemented in a much more efficient way.
// `nil` version means the latest version.
type VersionStore interface {
GetAtVersion(storeKey string, key []byte, version *int64) ([]byte, error)
HasAtVersion(storeKey string, key []byte, version *int64) (bool, error)
IteratorAtVersion(storeKey string, start, end []byte, version *int64) (types.Iterator, error)
ReverseIteratorAtVersion(storeKey string, start, end []byte, version *int64) (types.Iterator, error)
IteratorAtVersion(storeKey string, start, end []byte, version *int64) (Iterator, error)
ReverseIteratorAtVersion(storeKey string, start, end []byte, version *int64) (Iterator, error)
GetLatestVersion() (int64, error)

// Persist the change set of a block,
Expand Down
Loading