Browse Source

libs/db: conditional compilation (#3628)

* libs/db: conditional compilation

For cleveldb: go build -tags cleveldb
For boltdb: go build -tags boltdb

Fixes #3611

* document db_backend param better

* remove deprecated LevelDBBackend

* update changelog

* add missing lines

* add new line

* fix TestRemoteDB

* add a line about boltdb tag

* Revert "remove deprecated LevelDBBackend"

This reverts commit 1aa85453f7.

* make PR non breaking

* change DEPRECATED label format

https://stackoverflow.com/a/36360323/820520
pull/3633/head
Anton Kaliaev 5 years ago
committed by GitHub
parent
commit
a7358bc69f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 88 additions and 28 deletions
  1. +5
    -0
      CHANGELOG_PENDING.md
  2. +3
    -3
      Makefile
  3. +13
    -2
      config/config.go
  4. +12
    -1
      config/toml.go
  5. +5
    -7
      docs/introduction/install.md
  6. +12
    -1
      docs/tendermint-core/configuration.md
  7. +1
    -0
      libs/db/backend_test.go
  8. +2
    -0
      libs/db/boltdb.go
  9. +2
    -0
      libs/db/boltdb_test.go
  10. +1
    -1
      libs/db/c_level_db.go
  11. +3
    -3
      libs/db/c_level_db_test.go
  12. +27
    -8
      libs/db/db.go
  13. +1
    -1
      libs/db/remotedb/remotedb_test.go
  14. +1
    -1
      lite/proxy/verifier.go

+ 5
- 0
CHANGELOG_PENDING.md View File

@ -38,6 +38,11 @@
- [rpc] \#3362 `/dial_seeds` & `/dial_peers` return errors if addresses are incorrect (except when IP lookup fails)
- [node] \#3362 returns an error if `persistent_peers` list is invalid (except when IP lookup fails)
- [p2p] \#3531 Terminate session on nonce wrapping (@climber73)
- [libs/db] \#3611 Conditional compilation
* Use `cleveldb` tag instead of `gcc` to compile Tendermint with CLevelDB or
use `make build_c` / `make install_c` (full instructions can be found at
https://tendermint.com/docs/introduction/install.html#compile-with-cleveldb-support)
* Use `boltdb` tag to compile Tendermint with bolt db
### BUG FIXES:
- [p2p] \#3532 limit the number of attempts to connect to a peer in seed mode


+ 3
- 3
Makefile View File

@ -23,7 +23,7 @@ build:
CGO_ENABLED=0 go build $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/tendermint/
build_c:
CGO_ENABLED=1 go build $(BUILD_FLAGS) -tags "$(BUILD_TAGS) gcc" -o $(OUTPUT) ./cmd/tendermint/
CGO_ENABLED=1 go build $(BUILD_FLAGS) -tags "$(BUILD_TAGS) cleveldb" -o $(OUTPUT) ./cmd/tendermint/
build_race:
CGO_ENABLED=0 go build -race $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/tendermint
@ -32,7 +32,7 @@ install:
CGO_ENABLED=0 go install $(BUILD_FLAGS) -tags $(BUILD_TAGS) ./cmd/tendermint
install_c:
CGO_ENABLED=1 go install $(BUILD_FLAGS) -tags "$(BUILD_TAGS) gcc" ./cmd/tendermint
CGO_ENABLED=1 go install $(BUILD_FLAGS) -tags "$(BUILD_TAGS) cleveldb" ./cmd/tendermint
########################################
### Protobuf
@ -132,7 +132,7 @@ clean_certs:
rm -f db/remotedb/::.crt db/remotedb/::.key
test_libs: gen_certs
go test -tags gcc $(PACKAGES)
go test -tags clevedb boltdb $(PACKAGES)
make clean_certs
grpc_dbserver:


+ 13
- 2
config/config.go View File

@ -153,7 +153,18 @@ type BaseConfig struct {
// and verifying their commits
FastSync bool `mapstructure:"fast_sync"`
// Database backend: leveldb | memdb | cleveldb
// Database backend: goleveldb | cleveldb | boltdb
// * goleveldb (github.com/syndtr/goleveldb - most popular implementation)
// - pure go
// - stable
// * cleveldb (uses levigo wrapper)
// - fast
// - requires gcc
// - use cleveldb build tag (go build -tags cleveldb)
// * boltdb (uses etcd's fork of bolt - github.com/etcd-io/bbolt)
// - EXPERIMENTAL
// - may be faster is some use-cases (random reads - indexer)
// - use boltdb build tag (go build -tags boltdb)
DBBackend string `mapstructure:"db_backend"`
// Database directory
@ -207,7 +218,7 @@ func DefaultBaseConfig() BaseConfig {
ProfListenAddress: "",
FastSync: true,
FilterPeers: false,
DBBackend: "leveldb",
DBBackend: "goleveldb",
DBPath: "data",
}
}


+ 12
- 1
config/toml.go View File

@ -81,7 +81,18 @@ moniker = "{{ .BaseConfig.Moniker }}"
# and verifying their commits
fast_sync = {{ .BaseConfig.FastSync }}
# Database backend: leveldb | memdb | cleveldb
# Database backend: goleveldb | cleveldb | boltdb
# * goleveldb (github.com/syndtr/goleveldb - most popular implementation)
# - pure go
# - stable
# * cleveldb (uses levigo wrapper)
# - fast
# - requires gcc
# - use cleveldb build tag (go build -tags cleveldb)
# * boltdb (uses etcd's fork of bolt - github.com/etcd-io/bbolt)
# - EXPERIMENTAL
# - may be faster is some use-cases (random reads - indexer)
# - use boltdb build tag (go build -tags boltdb)
db_backend = "{{ .BaseConfig.DBBackend }}"
# Database directory


+ 5
- 7
docs/introduction/install.md View File

@ -79,9 +79,7 @@ make install
Install [LevelDB](https://github.com/google/leveldb) (minimum version is 1.7).
### Ubuntu
Install LevelDB with snappy (optionally):
Install LevelDB with snappy (optionally). Below are commands for Ubuntu:
```
sudo apt-get update
@ -100,23 +98,23 @@ wget https://github.com/google/leveldb/archive/v1.20.tar.gz && \
rm -f v1.20.tar.gz
```
Set database backend to cleveldb:
Set a database backend to `cleveldb`:
```
# config/config.toml
db_backend = "cleveldb"
```
To install Tendermint, run
To install Tendermint, run:
```
CGO_LDFLAGS="-lsnappy" make install_c
```
or run
or run:
```
CGO_LDFLAGS="-lsnappy" make build_c
```
to put the binary in `./build`.
which puts the binary in `./build`.

+ 12
- 1
docs/tendermint-core/configuration.md View File

@ -30,7 +30,18 @@ moniker = "anonymous"
# and verifying their commits
fast_sync = true
# Database backend: leveldb | memdb | cleveldb
# Database backend: goleveldb | cleveldb | boltdb
# * goleveldb (github.com/syndtr/goleveldb - most popular implementation)
# - pure go
# - stable
# * cleveldb (uses levigo wrapper)
# - fast
# - requires gcc
# - use cleveldb build tag (go build -tags cleveldb)
# * boltdb (uses etcd's fork of bolt - github.com/etcd-io/bbolt)
# - EXPERIMENTAL
# - may be faster is some use-cases (random reads - indexer)
# - use boltdb build tag (go build -tags boltdb)
db_backend = "leveldb"
# Database directory


+ 1
- 0
libs/db/backend_test.go View File

@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
cmn "github.com/tendermint/tendermint/libs/common"
)


+ 2
- 0
libs/db/boltdb.go View File

@ -1,3 +1,5 @@
// +build boltdb
package db
import (


+ 2
- 0
libs/db/boltdb_test.go View File

@ -1,3 +1,5 @@
// +build boltdb
package db
import (


+ 1
- 1
libs/db/c_level_db.go View File

@ -1,4 +1,4 @@
// +build gcc
// +build cleveldb
package db


+ 3
- 3
libs/db/c_level_db_test.go View File

@ -1,4 +1,4 @@
// +build gcc
// +build cleveldb
package db
@ -93,7 +93,7 @@ func TestCLevelDBBackend(t *testing.T) {
// Can't use "" (current directory) or "./" here because levigo.Open returns:
// "Error initializing DB: IO error: test_XXX.db: Invalid argument"
dir := os.TempDir()
db := NewDB(name, LevelDBBackend, dir)
db := NewDB(name, CLevelDBBackend, dir)
defer cleanupDBDir(dir, name)
_, ok := db.(*CLevelDB)
@ -103,7 +103,7 @@ func TestCLevelDBBackend(t *testing.T) {
func TestCLevelDBStats(t *testing.T) {
name := fmt.Sprintf("test_%x", cmn.RandStr(12))
dir := os.TempDir()
db := NewDB(name, LevelDBBackend, dir)
db := NewDB(name, CLevelDBBackend, dir)
defer cleanupDBDir(dir, name)
assert.NotEmpty(t, db.Stats())


+ 27
- 8
libs/db/db.go View File

@ -5,18 +5,37 @@ import (
"strings"
)
//----------------------------------------
// Main entry
type DBBackendType string
// These are valid backend types.
const (
LevelDBBackend DBBackendType = "leveldb" // legacy, defaults to goleveldb unless +gcc
CLevelDBBackend DBBackendType = "cleveldb"
// LevelDBBackend is a legacy type. Defaults to goleveldb unless cleveldb
// build tag was used, in which it becomes cleveldb.
// Deprecated: Use concrete types (golevedb, cleveldb, etc.)
LevelDBBackend DBBackendType = "leveldb"
// GoLevelDBBackend represents goleveldb (github.com/syndtr/goleveldb - most
// popular implementation)
// - pure go
// - stable
GoLevelDBBackend DBBackendType = "goleveldb"
MemDBBackend DBBackendType = "memdb"
FSDBBackend DBBackendType = "fsdb" // using the filesystem naively
BoltDBBackend DBBackendType = "boltdb"
// CLevelDBBackend represents cleveldb (uses levigo wrapper)
// - fast
// - requires gcc
// - use cleveldb build tag (go build -tags cleveldb)
CLevelDBBackend DBBackendType = "cleveldb"
// MemDBBackend represents in-memoty key value store, which is mostly used
// for testing.
MemDBBackend DBBackendType = "memdb"
// FSDBBackend represents filesystem database
// - EXPERIMENTAL
// - slow
FSDBBackend DBBackendType = "fsdb"
// BoltDBBackend represents bolt (uses etcd's fork of bolt -
// github.com/etcd-io/bbolt)
// - EXPERIMENTAL
// - may be faster is some use-cases (random reads - indexer)
// - use boltdb build tag (go build -tags boltdb)
BoltDBBackend DBBackendType = "boltdb"
)
type dbCreator func(name string, dir string) (DB, error)


+ 1
- 1
libs/db/remotedb/remotedb_test.go View File

@ -28,7 +28,7 @@ func TestRemoteDB(t *testing.T) {
client, err := remotedb.NewRemoteDB(ln.Addr().String(), cert)
require.Nil(t, err, "expecting a successful client creation")
dbName := "test-remote-db"
require.Nil(t, client.InitRemote(&remotedb.Init{Name: dbName, Type: "leveldb"}))
require.Nil(t, client.InitRemote(&remotedb.Init{Name: dbName, Type: "goleveldb"}))
defer func() {
err := os.RemoveAll(dbName + ".db")
if err != nil {


+ 1
- 1
lite/proxy/verifier.go View File

@ -14,7 +14,7 @@ func NewVerifier(chainID, rootDir string, client lclient.SignStatusClient, logge
logger.Info("lite/proxy/NewVerifier()...", "chainID", chainID, "rootDir", rootDir, "client", client)
memProvider := lite.NewDBProvider("trusted.mem", dbm.NewMemDB()).SetLimit(cacheSize)
lvlProvider := lite.NewDBProvider("trusted.lvl", dbm.NewDB("trust-base", dbm.LevelDBBackend, rootDir))
lvlProvider := lite.NewDBProvider("trusted.lvl", dbm.NewDB("trust-base", dbm.GoLevelDBBackend, rootDir))
trust := lite.NewMultiProvider(
memProvider,
lvlProvider,


Loading…
Cancel
Save