Skip to content

Commit

Permalink
chore(store/v2): move kv stores to kv sub-package (#18243)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored Oct 24, 2023
1 parent ff3ec25 commit 685a0a3
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 42 deletions.
6 changes: 3 additions & 3 deletions store/branchkv/README.md → store/kv/branch/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion store/branchkv/iterator.go → store/kv/branch/iterator.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package branchkv
package branch

import (
"slices"
Expand Down
6 changes: 3 additions & 3 deletions store/branchkv/store.go → store/kv/branch/store.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package branchkv
package branch

import (
"io"
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package branchkv_test
package branch_test

import (
"fmt"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions store/kv/mem/README.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion store/memkv/iterator.go → store/kv/mem/iterator.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package memkv
package mem

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion store/memkv/store.go → store/kv/mem/store.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package memkv
package mem

import (
"bytes"
Expand Down
6 changes: 3 additions & 3 deletions store/memkv/store_test.go → store/kv/mem/store_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package memkv_test
package mem_test

import (
"fmt"
Expand All @@ -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"
Expand All @@ -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() {
Expand Down
10 changes: 5 additions & 5 deletions store/tracekv/README.md → store/kv/trace/README.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions store/tracekv/doc.go → store/kv/trace/doc.go
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion store/tracekv/iterator.go → store/kv/trace/iterator.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tracekv
package trace

import (
"io"
Expand Down
2 changes: 1 addition & 1 deletion store/tracekv/store.go → store/kv/trace/store.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tracekv
package trace

import (
"encoding/base64"
Expand Down
10 changes: 5 additions & 5 deletions store/tracekv/store_test.go → store/kv/trace/store_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tracekv_test
package trace_test

import (
"bytes"
Expand All @@ -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"
Expand All @@ -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) {
Expand Down
8 changes: 0 additions & 8 deletions store/memkv/README.md

This file was deleted.

10 changes: 5 additions & 5 deletions store/root/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -184,15 +184,15 @@ 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
}

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
Expand Down

0 comments on commit 685a0a3

Please sign in to comment.