chore(store/v2): move kv stores to kv sub-package (#18243)

This commit is contained in:
Aleksandr Bezobchuk
2023-10-24 21:02:53 +00:00
committed by GitHub
parent ff3ec25873
commit 685a0a363e
15 changed files with 42 additions and 42 deletions
@@ -1,7 +1,7 @@
# branchkv
# Branch KVStore
The `branchkv.Store` implementation defines a `BranchedKVStore` that contains a
reference to a `VersionedDatabase`, i.e. an SS backend. The `branchkv.Store` is
The `branch.Store` implementation defines a `BranchedKVStore` that contains a
reference to a `VersionedDatabase`, i.e. an SS backend. The `branch.Store` is
meant to be used as the primary store used in a `RootStore` implementation. It
provides the ability to get the current `ChangeSet`, branching, and writing to
a parent store (if one is defined). Note, all reads first pass through the
@@ -1,4 +1,4 @@
package branchkv
package branch
import (
"slices"
@@ -1,4 +1,4 @@
package branchkv
package branch
import (
"io"
@@ -8,7 +8,7 @@ import (
"golang.org/x/exp/maps"
"cosmossdk.io/store/v2"
"cosmossdk.io/store/v2/tracekv"
"cosmossdk.io/store/v2/kv/trace"
)
var _ store.BranchedKVStore = (*Store)(nil)
@@ -104,7 +104,7 @@ func (s *Store) Branch() store.BranchedKVStore {
}
func (s *Store) BranchWithTrace(w io.Writer, tc store.TraceContext) store.BranchedKVStore {
return NewWithParent(tracekv.New(s, w, tc))
return NewWithParent(trace.New(s, w, tc))
}
func (s *Store) Has(key []byte) bool {
@@ -1,4 +1,4 @@
package branchkv_test
package branch_test
import (
"fmt"
@@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/suite"
"cosmossdk.io/store/v2"
"cosmossdk.io/store/v2/branchkv"
"cosmossdk.io/store/v2/kv/branch"
"cosmossdk.io/store/v2/storage/sqlite"
)
@@ -38,7 +38,7 @@ func (s *StoreTestSuite) SetupTest() {
s.Require().NoError(storage.ApplyChangeset(1, cs))
kvStore, err := branchkv.New(storeKey, storage)
kvStore, err := branch.New(storeKey, storage)
s.Require().NoError(err)
s.storage = storage
+8
View File
@@ -0,0 +1,8 @@
# Memory KVStore
The `mem.Store` implementation defines an in-memory `KVStore`, which is internally
backed by a thread-safe BTree. The `mem.Store` does not provide any branching
functionality and should be used as an ephemeral store, typically reset between
blocks. A `mem.Store` contains no reference to a parent store, but can be used
as a parent store for other stores. The `mem.Store` is can be useful for testing
purposes and where state persistence is not required or should be ephemeral.
@@ -1,4 +1,4 @@
package memkv
package mem
import (
"bytes"
@@ -1,4 +1,4 @@
package memkv
package mem
import (
"bytes"
@@ -1,4 +1,4 @@
package memkv_test
package mem_test
import (
"fmt"
@@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/suite"
"cosmossdk.io/store/v2"
"cosmossdk.io/store/v2/memkv"
"cosmossdk.io/store/v2/kv/mem"
)
const storeKey = "storeKey"
@@ -23,7 +23,7 @@ func TestStorageTestSuite(t *testing.T) {
}
func (s *StoreTestSuite) SetupTest() {
s.kvStore = memkv.New(storeKey)
s.kvStore = mem.New(storeKey)
}
func (s *StoreTestSuite) TestGetStoreType() {
@@ -1,15 +1,15 @@
# tracekv
# Trace KVStore
The `tracekv.Store` implementation defines a store which wraps a parent `KVStore`
The `trace.Store` implementation defines a store which wraps a parent `KVStore`
and traces all operations performed on it. Each trace operation is written to a
provided `io.Writer` object. Specifically, a `TraceOperation` object is JSON
encoded and written to the writer. The `TraceOperation` object contains the exact
operation, e.g. a read or write, and the corresponding key and value pair.
A `tracekv.Store` can also be instantiated with a `store.TraceContext` which
A `trace.Store` can also be instantiated with a `store.TraceContext` which
can allow each traced operation to include additional metadata, e.g. a block height
or hash.
Note, `tracekv.Store` is not meant to be branched or written to. The parent `KVStore`
is responsible for all branching and writing operations, while a `tracekv.Store`
Note, `trace.Store` is not meant to be branched or written to. The parent `KVStore`
is responsible for all branching and writing operations, while a `trace.Store`
wraps such a store and traces all relevant operations on it.
@@ -1,7 +1,7 @@
/*
Package tracekv provides a KVStore implementation that wraps a parent KVStore
Package trace provides a KVStore implementation that wraps a parent KVStore
and allows all operations to be traced to an io.Writer. This can be useful to
serve use cases such as tracing and digesting all read operations for a specific
store key and key or value.
*/
package tracekv
package trace
@@ -1,4 +1,4 @@
package tracekv
package trace
import (
"io"
@@ -1,4 +1,4 @@
package tracekv
package trace
import (
"encoding/base64"
@@ -1,4 +1,4 @@
package tracekv_test
package trace_test
import (
"bytes"
@@ -9,8 +9,8 @@ import (
"github.com/stretchr/testify/require"
"cosmossdk.io/store/v2"
"cosmossdk.io/store/v2/memkv"
"cosmossdk.io/store/v2/tracekv"
"cosmossdk.io/store/v2/kv/mem"
"cosmossdk.io/store/v2/kv/trace"
)
const storeKey = "storeKey"
@@ -32,10 +32,10 @@ func newTraceKVStore(w io.Writer) store.KVStore {
}
func newEmptyTraceKVStore(w io.Writer) store.KVStore {
memKVStore := memkv.New(storeKey)
memKVStore := mem.New(storeKey)
tc := store.TraceContext(map[string]any{"blockHeight": 64})
return tracekv.New(memKVStore, w, tc)
return trace.New(memKVStore, w, tc)
}
func TestTraceKVStoreGet(t *testing.T) {
-8
View File
@@ -1,8 +0,0 @@
# memkv
The `memkv.Store` implementation defines an in-memory `KVStore`, which is internally
backed by a thread-safe BTree. The `memkv.Store` does not provide any branching
functionality and should be used as an ephemeral store, typically reset between
blocks. A `memkv.Store` contains no reference to a parent store, but can be used
as a parent store for other stores. The `memkv.Store` is can be useful for testing
purposes and where state persistence is not required or should be ephemeral.
+5 -5
View File
@@ -10,9 +10,9 @@ import (
"cosmossdk.io/log"
"cosmossdk.io/store/v2"
"cosmossdk.io/store/v2/branchkv"
"cosmossdk.io/store/v2/commitment"
"cosmossdk.io/store/v2/tracekv"
"cosmossdk.io/store/v2/kv/branch"
"cosmossdk.io/store/v2/kv/trace"
)
// defaultStoreKey defines the default store key used for the single SC backend.
@@ -62,7 +62,7 @@ func New(
ss store.VersionedDatabase,
sc *commitment.Database,
) (store.RootStore, error) {
rootKVStore, err := branchkv.New(defaultStoreKey, ss)
rootKVStore, err := branch.New(defaultStoreKey, ss)
if err != nil {
return nil, err
}
@@ -184,7 +184,7 @@ func (s *Store) LoadVersion(v uint64) (err error) {
// root KVStore using Write().
func (s *Store) GetKVStore(_ string) store.KVStore {
if s.TracingEnabled() {
return tracekv.New(s.rootKVStore, s.traceWriter, s.traceContext)
return trace.New(s.rootKVStore, s.traceWriter, s.traceContext)
}
return s.rootKVStore
@@ -192,7 +192,7 @@ func (s *Store) GetKVStore(_ string) store.KVStore {
func (s *Store) GetBranchedKVStore(_ string) store.BranchedKVStore {
if s.TracingEnabled() {
return tracekv.New(s.rootKVStore, s.traceWriter, s.traceContext)
return trace.New(s.rootKVStore, s.traceWriter, s.traceContext)
}
return s.rootKVStore