mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 23:42:23 +00:00
docs: fix supported database types
This commit is contained in:
parent
2f5137e9b7
commit
70e59d83c9
8 changed files with 51 additions and 9 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/internal/testcli"
|
"github.com/nspcc-dev/neo-go/internal/testcli"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config"
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
@ -19,7 +20,7 @@ func TestDBRestoreDump(t *testing.T) {
|
||||||
chainPath := filepath.Join(tmpDir, "neogotestchain")
|
chainPath := filepath.Join(tmpDir, "neogotestchain")
|
||||||
cfg, err := config.LoadFile(filepath.Join("..", "..", "config", "protocol.unit_testnet.yml"))
|
cfg, err := config.LoadFile(filepath.Join("..", "..", "config", "protocol.unit_testnet.yml"))
|
||||||
require.NoError(t, err, "could not load config")
|
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
|
cfg.ApplicationConfiguration.DBConfiguration.LevelDBOptions.DataDirectoryPath = chainPath
|
||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/cli/server"
|
"github.com/nspcc-dev/neo-go/cli/server"
|
||||||
"github.com/nspcc-dev/neo-go/internal/testcli"
|
"github.com/nspcc-dev/neo-go/internal/testcli"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config"
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
@ -25,7 +26,7 @@ func TestServerStart(t *testing.T) {
|
||||||
saveCfg := func(t *testing.T, f func(cfg *config.Config)) string {
|
saveCfg := func(t *testing.T, f func(cfg *config.Config)) string {
|
||||||
cfg := *ptr
|
cfg := *ptr
|
||||||
chainPath := filepath.Join(t.TempDir(), "neogotestchain")
|
chainPath := filepath.Join(t.TempDir(), "neogotestchain")
|
||||||
cfg.ApplicationConfiguration.DBConfiguration.Type = "leveldb"
|
cfg.ApplicationConfiguration.DBConfiguration.Type = dbconfig.LevelDB
|
||||||
cfg.ApplicationConfiguration.DBConfiguration.LevelDBOptions.DataDirectoryPath = chainPath
|
cfg.ApplicationConfiguration.DBConfiguration.LevelDBOptions.DataDirectoryPath = chainPath
|
||||||
f(&cfg)
|
f(&cfg)
|
||||||
out, err := yaml.Marshal(cfg)
|
out, err := yaml.Marshal(cfg)
|
||||||
|
|
|
@ -350,7 +350,7 @@ func TestInitBlockChain(t *testing.T) {
|
||||||
_, err := initBlockChain(config.Config{
|
_, err := initBlockChain(config.Config{
|
||||||
ApplicationConfiguration: config.ApplicationConfiguration{
|
ApplicationConfiguration: config.ApplicationConfiguration{
|
||||||
DBConfiguration: dbconfig.DBConfiguration{
|
DBConfiguration: dbconfig.DBConfiguration{
|
||||||
Type: "inmemory",
|
Type: dbconfig.InMemoryDB,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
|
@ -53,8 +53,8 @@ DBConfiguration:
|
||||||
ReadOnly: false
|
ReadOnly: false
|
||||||
```
|
```
|
||||||
where:
|
where:
|
||||||
- `Type` is the database type (string value). Supported types: `levelDB` and
|
- `Type` is the database type (string value). Supported types: `leveldb`, `boltdb` and
|
||||||
`boltDB`.
|
`inmemory` (not recommended for production usage).
|
||||||
- `LevelDBOptions` are settings for LevelDB. Includes the DB files path and ReadOnly mode toggle.
|
- `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
|
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.
|
database. Database doesn't allow changes in this mode, a warning will be logged on DB persist attempts.
|
||||||
|
|
|
@ -288,7 +288,7 @@ func TestManagement_StartFromHeight(t *testing.T) {
|
||||||
// Create database to be able to start another chain from the same height later.
|
// Create database to be able to start another chain from the same height later.
|
||||||
ldbDir := t.TempDir()
|
ldbDir := t.TempDir()
|
||||||
dbConfig := dbconfig.DBConfiguration{
|
dbConfig := dbconfig.DBConfiguration{
|
||||||
Type: "leveldb",
|
Type: dbconfig.LevelDB,
|
||||||
LevelDBOptions: dbconfig.LevelDBOptions{
|
LevelDBOptions: dbconfig.LevelDBOptions{
|
||||||
DataDirectoryPath: ldbDir,
|
DataDirectoryPath: ldbDir,
|
||||||
},
|
},
|
||||||
|
|
11
pkg/core/storage/dbconfig/store_type.go
Normal file
11
pkg/core/storage/dbconfig/store_type.go
Normal file
|
@ -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"
|
||||||
|
)
|
|
@ -114,11 +114,11 @@ func NewStore(cfg dbconfig.DBConfiguration) (Store, error) {
|
||||||
var store Store
|
var store Store
|
||||||
var err error
|
var err error
|
||||||
switch cfg.Type {
|
switch cfg.Type {
|
||||||
case "leveldb":
|
case dbconfig.LevelDB:
|
||||||
store, err = NewLevelDBStore(cfg.LevelDBOptions)
|
store, err = NewLevelDBStore(cfg.LevelDBOptions)
|
||||||
case "inmemory":
|
case dbconfig.InMemoryDB:
|
||||||
store = NewMemoryStore()
|
store = NewMemoryStore()
|
||||||
case "boltdb":
|
case dbconfig.BoltDB:
|
||||||
store, err = NewBoltDBStore(cfg.BoltDBOptions)
|
store, err = NewBoltDBStore(cfg.BoltDBOptions)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown storage: %s", cfg.Type)
|
return nil, fmt.Errorf("unknown storage: %s", cfg.Type)
|
||||||
|
|
29
pkg/core/storage/store_type_test.go
Normal file
29
pkg/core/storage/store_type_test.go
Normal file
|
@ -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())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue