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

feat(types): Deprecate the DBBackend variable in favor of new app-db-backend config entry #11188

Merged
merged 50 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
34615fb
[10948]: Add changelog entry.
dwedul-figure Feb 14, 2022
a51cbc2
[10948]: Deprecate the types.DBBackend variable and the NewLevelDB fu…
dwedul-figure Feb 14, 2022
533a317
[10948]: Add a DBBackend string to the simulation config and a flag f…
dwedul-figure Feb 14, 2022
53d766f
[10948]: Update the mock app creator to use the NewDB function. Not s…
dwedul-figure Feb 14, 2022
63ddc2f
[10948]: Update changelog to reflect new db-backend field name.
dwedul-figure Feb 14, 2022
d84ef9d
[10948]: Use the tendermint db-backend type for the snapshot db.
dwedul-figure Feb 14, 2022
37b3456
[10948]: Update the last use of NewLevelDB by adding a parameter to o…
dwedul-figure Feb 14, 2022
6411ab5
[10948]: Upddate the NewDB function to also have a default db backend…
dwedul-figure Feb 14, 2022
33cf13f
[10948]: Remove the new TODO in mock.NewApp. After looking through it…
dwedul-figure Feb 14, 2022
9b81772
[10948]: Enhance the NewDB defer function to also add info to any err…
dwedul-figure Feb 14, 2022
ee2736c
[10948]: Add some unit tests for NewDB.
dwedul-figure Feb 14, 2022
606c600
[10948]: Lint fixes.
dwedul-figure Feb 14, 2022
d596b60
[10948]: Add a changelog entry to the deprecated section.
dwedul-figure Feb 14, 2022
6a40720
[10948]: Update the makefile to no longer set the types.DBBackend value.
dwedul-figure Feb 14, 2022
6090bde
Merge branch 'master' into dwedul/10948-remove-dbbackend-var
dwedul-figure Feb 15, 2022
22796fe
Merge branch 'master' into dwedul/10948-remove-dbbackend-var
dwedul-figure Feb 15, 2022
36bcd0c
Merge branch 'master' into dwedul/10948-remove-dbbackend-var
dwedul-figure Feb 15, 2022
d060fc5
Merge branch 'master' into dwedul/10948-remove-dbbackend-var
tac0turtle Feb 17, 2022
7ed5bec
Merge branch 'master' into dwedul/10948-remove-dbbackend-var
dwedul-figure Feb 17, 2022
e5a97de
[10948]: Use memdb for the mock app instead of goleveldb. I know it w…
dwedul-figure Feb 17, 2022
83d2074
[10948]: Fix the store benchmark tests (had some index-out-of-range i…
dwedul-figure Feb 17, 2022
f08da2d
[10948]: Fix cachekv store bench test calling iter.Key() before check…
dwedul-figure Feb 17, 2022
ed5caf6
Merge branch 'master' into dwedul/10948-remove-dbbackend-var
dwedul-figure Feb 22, 2022
ff6d1ca
[10948]: Remove the panic recovery from types.NewDB since dbm.NewDB r…
dwedul-figure Feb 22, 2022
00e3615
[10948]: Add changlog entry indicationg an API breaking change due to…
dwedul-figure Feb 22, 2022
12df003
Merge branch 'master' into dwedul/10948-remove-dbbackend-var
dwedul-figure Feb 22, 2022
3f57be7
[10948]: Get rid of the types.NewDB function in favor of just using t…
dwedul-figure Feb 22, 2022
52ee92c
[10948]: Fix Update the codeql-analysis github action to use go v1.17.
dwedul-figure Feb 22, 2022
55e335b
Merge branch 'master' into dwedul/10948-remove-dbbackend-var
dwedul-figure Feb 22, 2022
1cef616
Merge branch 'master' into dwedul/10948-remove-dbbackend-var
dwedul-figure Feb 28, 2022
b035260
[10948]: Add config file option for the app db backend type.
dwedul-figure Feb 28, 2022
bf44163
Merge branch 'master' into dwedul/10948-remove-dbbackend-var
dwedul-figure Feb 28, 2022
e9ee9b7
[10948]: Adjust the comment on the app-db-backend config entry to cla…
dwedul-figure Feb 28, 2022
0dba287
Merge branch 'master' into dwedul/10948-remove-dbbackend-var
dwedul-figure Feb 28, 2022
4705c1c
[10948]: Add a default of GoLevelDBBackend to GetAppDBBackend. The ol…
dwedul-figure Feb 28, 2022
c8001e0
[10948]: Add the missing quotes around the app-db-backend value.
dwedul-figure Feb 28, 2022
46e6356
Merge branch 'master' into dwedul/10948-remove-dbbackend-var
dwedul-figure Mar 2, 2022
e49f6c5
[10948]: Small tweak to the changelog's deprecated entry.
dwedul-figure Mar 2, 2022
c08225e
Merge branch 'master' into dwedul/10948-remove-dbbackend-var
dwedul-figure Mar 2, 2022
de2cb9b
Add the go version declaration back into the codeql-analysis github a…
dwedul-figure Mar 2, 2022
2d4c6a0
Merge branch 'master' into dwedul/10948-remove-dbbackend-var
dwedul-figure Mar 10, 2022
f6b541c
Merge branch 'master' into dwedul/10948-remove-dbbackend-var
dwedul-figure Mar 10, 2022
6c6e38f
[10948]: Update new use of openDB.
dwedul-figure Mar 10, 2022
33b55d6
Merge branch 'master' into dwedul/10948-remove-dbbackend-var
dwedul-figure Mar 15, 2022
8ecf3c8
Merge branch 'master' into dwedul/10948-remove-dbbackend-var
dwedul-figure Mar 15, 2022
32f758b
[10948]: Put a brief delay after closing the test network. Hopefully …
dwedul-figure Mar 15, 2022
812b014
Merge branch 'master' into dwedul/10948-remove-dbbackend-var
dwedul-figure Mar 15, 2022
de8ad46
Merge branch 'master' into dwedul/10948-remove-dbbackend-var
dwedul-figure Mar 16, 2022
a05638a
Merge branch 'master' into dwedul/10948-remove-dbbackend-var
dwedul-figure Mar 17, 2022
bbbccb6
Merge branch 'master' into dwedul/10948-remove-dbbackend-var
dwedul-figure Mar 17, 2022
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (types/errors) [\#10779](https://github.com/cosmos/cosmos-sdk/pull/10779) Move most functionality in `types/errors` to a standalone `errors` go module, except the `RootCodespace` errors and ABCI response helpers. All functions and types that used to live in `types/errors` are now aliased so this is not a breaking change.
* (gov) [\#10854](https://github.com/cosmos/cosmos-sdk/pull/10854) v1beta2's vote doesn't include the deprecate `option VoteOption` anymore. Instead, it only uses `WeightedVoteOption`.
* (types) [\#11004](https://github.com/cosmos/cosmos-sdk/pull/11004) Added mutable versions of many of the sdk.Dec types operations. This improves performance when used by avoiding reallocating a new bigint for each operation.
* (types) [\#10948](https://github.com/cosmos/cosmos-sdk/issues/10948) Use Tendermint `db-backend` config value instead of compile-time `types.DBBackend` value.
dwedul-figure marked this conversation as resolved.
Show resolved Hide resolved

### Bug Fixes

Expand Down Expand Up @@ -217,6 +218,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Deprecated

* (x/upgrade) [\#9906](https://github.com/cosmos/cosmos-sdk/pull/9906) Deprecate `UpgradeConsensusState` gRPC query since this functionality is only used for IBC, which now has its own [IBC replacement](https://github.com/cosmos/ibc-go/blob/2c880a22e9f9cc75f62b527ca94aa75ce1106001/proto/ibc/core/client/v1/query.proto#L54)
* (types) [\#10948](https://github.com/cosmos/cosmos-sdk/issues/10948) Deprecate the types.DBBackend variable and types.NewLevelDB function in favor of the new types.NewDB function that takes in a db backend type.

## [v0.45.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.45.0) - 2022-01-18

Expand Down
2 changes: 1 addition & 1 deletion server/constructors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func Test_openDB(t *testing.T) {
t.Parallel()
_, err := openDB(t.TempDir())
_, err := openDB(t.TempDir(), "")
require.NoError(t, err)
}

Expand Down
2 changes: 1 addition & 1 deletion server/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com
return err
}

db, err := openDB(config.RootDir)
db, err := openDB(config.RootDir, config.DBBackend)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion server/mock/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func testTxHandler(options middleware.TxHandlerOptions) tx.Handler {
// similar to a real app. Make sure rootDir is empty before running the test,
// in order to guarantee consistent results
func NewApp(rootDir string, logger log.Logger) (abci.Application, error) {
db, err := sdk.NewLevelDB("mock", filepath.Join(rootDir, "data"))
db, err := sdk.NewDB("mock", "", filepath.Join(rootDir, "data"))
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func startStandAlone(ctx *Context, appCreator types.AppCreator) error {
transport := ctx.Viper.GetString(flagTransport)
home := ctx.Viper.GetString(flags.FlagHome)

db, err := openDB(home)
db, err := openDB(home, ctx.Viper.GetString("db-backend"))
if err != nil {
return err
}
Expand Down Expand Up @@ -229,7 +229,7 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
}

traceWriterFile := ctx.Viper.GetString(flagTraceStore)
db, err := openDB(home)
db, err := openDB(home, cfg.DBBackend)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,9 @@ func addrToIP(addr net.Addr) net.IP {
return ip
}

func openDB(rootDir string) (dbm.DB, error) {
func openDB(rootDir, backendType string) (dbm.DB, error) {
dataDir := filepath.Join(rootDir, "data")
return sdk.NewLevelDB("application", dataDir)
return sdk.NewDB("application", backendType, dataDir)
}

func openTraceWriter(traceWriterFile string) (w io.Writer, err error) {
Expand Down
3 changes: 3 additions & 0 deletions simapp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
FlagCommitValue bool
FlagOnOperationValue bool // TODO: Remove in favor of binary search for invariant violation
FlagAllInvariantsValue bool
FlagDBBackendValue string

FlagEnabledValue bool
FlagVerboseValue bool
Expand All @@ -46,6 +47,7 @@ func GetSimulatorFlags() {
flag.BoolVar(&FlagCommitValue, "Commit", false, "have the simulation commit")
flag.BoolVar(&FlagOnOperationValue, "SimulateEveryOperation", false, "run slow invariants every operation")
flag.BoolVar(&FlagAllInvariantsValue, "PrintAllInvariants", false, "print all invariants if a broken invariant is found")
flag.StringVar(&FlagDBBackendValue, "DBBackend", "goleveldb", "custom db backend type")

// simulation flags
flag.BoolVar(&FlagEnabledValue, "Enabled", false, "enable the simulation")
Expand All @@ -71,5 +73,6 @@ func NewConfigFromFlags() simulation.Config {
Commit: FlagCommitValue,
OnOperation: FlagOnOperationValue,
AllInvariants: FlagAllInvariantsValue,
DBBackend: FlagDBBackendValue,
}
}
2 changes: 1 addition & 1 deletion simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a
}

snapshotDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data", "snapshots")
snapshotDB, err := sdk.NewLevelDB("metadata", snapshotDir)
snapshotDB, err := sdk.NewDB("metadata", cast.ToString(appOpts.Get("db-backend")), snapshotDir)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion simapp/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func SetupSimulation(dirPrefix, dbName string) (simtypes.Config, dbm.DB, string,
return simtypes.Config{}, nil, "", nil, false, err
}

db, err := sdk.NewLevelDB(dbName, dir)
db, err := sdk.NewDB(dbName, config.DBBackend, dir)
if err != nil {
return simtypes.Config{}, nil, "", nil, false, err
}
Expand Down
2 changes: 2 additions & 0 deletions types/simulation/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ type Config struct {

OnOperation bool // run slow invariants every operation
AllInvariants bool // print all failed invariants if a broken invariant is found

DBBackend string // custom db backend type
}
27 changes: 26 additions & 1 deletion types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import (

var (
// This is set at compile time. Could be cleveldb, defaults is goleveldb.
DBBackend = ""
DBBackend = "" // Deprecated: Use tendermint config's DBBackend value instead.
backend = dbm.GoLevelDBBackend
)

func init() {
if len(DBBackend) != 0 {
backend = dbm.BackendType(DBBackend)
} else {
DBBackend = string(backend)
}
}

Expand Down Expand Up @@ -85,6 +87,8 @@ func ParseTimeBytes(bz []byte) (time.Time, error) {
}

// NewLevelDB instantiate a new LevelDB instance according to DBBackend.
//
// Deprecated: Use NewDB instead. Suggested backendType is tendermint config's DBBackend value.
func NewLevelDB(name, dir string) (db dbm.DB, err error) {
defer func() {
if r := recover(); r != nil {
Expand All @@ -95,6 +99,27 @@ func NewLevelDB(name, dir string) (db dbm.DB, err error) {
return dbm.NewDB(name, backend, dir)
}

// NewDB instantiate a new DB instance.
// This differs from the tendermint/tm-db.NewDB function in three ways:
// 1) Returns an error instead of panicking.
// 2) Takes in a string for the backend type.
// 3) If the backendType is an empty string, "goleveldb" is used.
func NewDB(name, backendType, dir string) (db dbm.DB, err error) {
dwedul-figure marked this conversation as resolved.
Show resolved Hide resolved
defer func() {
r := recover()
switch {
case r != nil:
err = fmt.Errorf("could not create %q db in %s with name %q: %v", backendType, dir, name, r)
case err != nil:
err = fmt.Errorf("could not create %q db in %s with name %q: %w", backendType, dir, name, err)
}
}()
if len(backendType) == 0 {
backendType = string(dbm.GoLevelDBBackend)
}
return dbm.NewDB(name, dbm.BackendType(backendType), dir)
}

// copy bytes
func CopyBytes(bz []byte) (ret []byte) {
if bz == nil {
Expand Down
67 changes: 67 additions & 0 deletions types/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

sdk "github.com/cosmos/cosmos-sdk/types"

dbm "github.com/tendermint/tm-db"
)

type utilsTestSuite struct {
Expand Down Expand Up @@ -109,3 +113,66 @@ func (s *utilsTestSuite) TestParseTimeBytes() {
_, err = sdk.ParseTimeBytes([]byte{})
s.Require().Error(err)
}

func (s *utilsTestSuite) TestNewDB() {
tests := []struct {
testName string

name string
backendType string

isGoLevelDB bool
isMemDB bool
errContains []string
}{
{
testName: "unknown backendType gives error",
name: "test-unknown",
backendType: "baddbtype",
errContains: []string{"could not create", "test-unknown", "unknown", "baddbtype", "goleveldb"},
},
{
testName: "empty backendType defaults to goleveldb",
name: "test-empty",
backendType: "",
isGoLevelDB: true,
},
{
testName: "goleveldb returns a GoLevelDB",
name: "test-goleveldb",
backendType: "goleveldb",
isGoLevelDB: true,
},
{
testName: "memdb returns a MemDB",
name: "test-memdb",
backendType: "memdb",
isMemDB: true,
},
}

for _, tc := range tests {
s.T().Run(tc.testName, func(t *testing.T) {
dir := t.TempDir()
var db dbm.DB
var err error
require.NotPanics(t, func() {
db, err = sdk.NewDB(tc.name, tc.backendType, dir)
}, "calling NewDB")
if len(tc.errContains) != 0 {
require.Error(t, err, "err")
for _, exp := range tc.errContains {
assert.Contains(t, err.Error(), exp, "err.Error()")
}
} else {
require.NoError(t, err, "err")
require.NotNil(t, db, "db")
assert.NoError(t, db.Close(), "db.Close()")
_, isGoLevelDB := db.(*dbm.GoLevelDB)
assert.Equal(t, tc.isGoLevelDB, isGoLevelDB, "isGoLevelDB")
_, isMemDB := db.(*dbm.MemDB)
assert.Equal(t, tc.isMemDB, isMemDB, "isMemDB")
}
})
}
}