From 70e59d83c9b524ebd61006544897f262928f501b Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 5 Oct 2022 09:05:36 +0300 Subject: [PATCH] docs: fix supported database types --- cli/server/cli_dump_test.go | 3 +- cli/server/cli_server_test.go | 3 +- cli/server/server_test.go | 2 +- docs/node-configuration.md | 4 +-- .../native/native_test/management_test.go | 2 +- pkg/core/storage/dbconfig/store_type.go | 11 +++++++ pkg/core/storage/store.go | 6 ++-- pkg/core/storage/store_type_test.go | 29 +++++++++++++++++++ 8 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 pkg/core/storage/dbconfig/store_type.go create mode 100644 pkg/core/storage/store_type_test.go diff --git a/cli/server/cli_dump_test.go b/cli/server/cli_dump_test.go index 4911de3bc..b743f9015 100644 --- a/cli/server/cli_dump_test.go +++ b/cli/server/cli_dump_test.go @@ -8,6 +8,7 @@ import ( "github.com/nspcc-dev/neo-go/internal/testcli" "github.com/nspcc-dev/neo-go/pkg/config" + "github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig" "github.com/stretchr/testify/require" "gopkg.in/yaml.v3" ) @@ -19,7 +20,7 @@ func TestDBRestoreDump(t *testing.T) { chainPath := filepath.Join(tmpDir, "neogotestchain") cfg, err := config.LoadFile(filepath.Join("..", "..", "config", "protocol.unit_testnet.yml")) require.NoError(t, err, "could not load config") - cfg.ApplicationConfiguration.DBConfiguration.Type = "leveldb" + cfg.ApplicationConfiguration.DBConfiguration.Type = dbconfig.LevelDB cfg.ApplicationConfiguration.DBConfiguration.LevelDBOptions.DataDirectoryPath = chainPath return cfg } diff --git a/cli/server/cli_server_test.go b/cli/server/cli_server_test.go index ccaf646e9..2170ec85c 100644 --- a/cli/server/cli_server_test.go +++ b/cli/server/cli_server_test.go @@ -13,6 +13,7 @@ import ( "github.com/nspcc-dev/neo-go/cli/server" "github.com/nspcc-dev/neo-go/internal/testcli" "github.com/nspcc-dev/neo-go/pkg/config" + "github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig" "github.com/stretchr/testify/require" "gopkg.in/yaml.v3" ) @@ -25,7 +26,7 @@ func TestServerStart(t *testing.T) { saveCfg := func(t *testing.T, f func(cfg *config.Config)) string { cfg := *ptr chainPath := filepath.Join(t.TempDir(), "neogotestchain") - cfg.ApplicationConfiguration.DBConfiguration.Type = "leveldb" + cfg.ApplicationConfiguration.DBConfiguration.Type = dbconfig.LevelDB cfg.ApplicationConfiguration.DBConfiguration.LevelDBOptions.DataDirectoryPath = chainPath f(&cfg) out, err := yaml.Marshal(cfg) diff --git a/cli/server/server_test.go b/cli/server/server_test.go index ff51b431b..36d751cb1 100644 --- a/cli/server/server_test.go +++ b/cli/server/server_test.go @@ -350,7 +350,7 @@ func TestInitBlockChain(t *testing.T) { _, err := initBlockChain(config.Config{ ApplicationConfiguration: config.ApplicationConfiguration{ DBConfiguration: dbconfig.DBConfiguration{ - Type: "inmemory", + Type: dbconfig.InMemoryDB, }, }, }, nil) diff --git a/docs/node-configuration.md b/docs/node-configuration.md index 9f4fa8d3a..fc4fb9340 100644 --- a/docs/node-configuration.md +++ b/docs/node-configuration.md @@ -53,8 +53,8 @@ DBConfiguration: ReadOnly: false ``` where: -- `Type` is the database type (string value). Supported types: `levelDB` and - `boltDB`. +- `Type` is the database type (string value). Supported types: `leveldb`, `boltdb` and + `inmemory` (not recommended for production usage). - `LevelDBOptions` are settings for LevelDB. Includes the DB files path and ReadOnly mode toggle. If ReadOnly mode is on, then an error will be returned on attempt to connect to unexisting or empty database. Database doesn't allow changes in this mode, a warning will be logged on DB persist attempts. diff --git a/pkg/core/native/native_test/management_test.go b/pkg/core/native/native_test/management_test.go index 37699f59d..68f808895 100644 --- a/pkg/core/native/native_test/management_test.go +++ b/pkg/core/native/native_test/management_test.go @@ -288,7 +288,7 @@ func TestManagement_StartFromHeight(t *testing.T) { // Create database to be able to start another chain from the same height later. ldbDir := t.TempDir() dbConfig := dbconfig.DBConfiguration{ - Type: "leveldb", + Type: dbconfig.LevelDB, LevelDBOptions: dbconfig.LevelDBOptions{ DataDirectoryPath: ldbDir, }, diff --git a/pkg/core/storage/dbconfig/store_type.go b/pkg/core/storage/dbconfig/store_type.go new file mode 100644 index 000000000..9faf08ec2 --- /dev/null +++ b/pkg/core/storage/dbconfig/store_type.go @@ -0,0 +1,11 @@ +package dbconfig + +// Available storage types. +const ( + // BoltDB represents Bolt DB storage name. + BoltDB = "boltdb" + // LevelDB represents Level DB storage name. + LevelDB = "leveldb" + // InMemoryDB represents in-memory storage name. + InMemoryDB = "inmemory" +) diff --git a/pkg/core/storage/store.go b/pkg/core/storage/store.go index 931d153ff..caa8a4e73 100644 --- a/pkg/core/storage/store.go +++ b/pkg/core/storage/store.go @@ -114,11 +114,11 @@ func NewStore(cfg dbconfig.DBConfiguration) (Store, error) { var store Store var err error switch cfg.Type { - case "leveldb": + case dbconfig.LevelDB: store, err = NewLevelDBStore(cfg.LevelDBOptions) - case "inmemory": + case dbconfig.InMemoryDB: store = NewMemoryStore() - case "boltdb": + case dbconfig.BoltDB: store, err = NewBoltDBStore(cfg.BoltDBOptions) default: return nil, fmt.Errorf("unknown storage: %s", cfg.Type) diff --git a/pkg/core/storage/store_type_test.go b/pkg/core/storage/store_type_test.go new file mode 100644 index 000000000..bb5bd8936 --- /dev/null +++ b/pkg/core/storage/store_type_test.go @@ -0,0 +1,29 @@ +package storage + +import ( + "path/filepath" + "testing" + + "github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig" + "github.com/stretchr/testify/require" +) + +func TestStorageNames(t *testing.T) { + tmp := t.TempDir() + cfg := dbconfig.DBConfiguration{ + LevelDBOptions: dbconfig.LevelDBOptions{ + DataDirectoryPath: filepath.Join(tmp, "level"), + }, + BoltDBOptions: dbconfig.BoltDBOptions{ + FilePath: filepath.Join(tmp, "bolt"), + }, + } + for _, name := range []string{dbconfig.BoltDB, dbconfig.LevelDB, dbconfig.InMemoryDB} { + t.Run(name, func(t *testing.T) { + cfg.Type = name + s, err := NewStore(cfg) + require.NoError(t, err) + require.NoError(t, s.Close()) + }) + } +}