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: switch default database backend from goleveldb to pebble #1636

Draft
wants to merge 8 commits into
base: v0.34.x-celestia
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
70 changes: 54 additions & 16 deletions cmd/cometbft/commands/compact.go
Original file line number Diff line number Diff line change
@@ -1,41 +1,53 @@
package commands

import (
"errors"
"fmt"
"os"
"path/filepath"
"sync"

"github.com/cockroachdb/pebble"
"github.com/spf13/cobra"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/opt"
"github.com/syndtr/goleveldb/leveldb/util"

cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/log"
)

var CompactGoLevelDBCmd = &cobra.Command{
Use: "experimental-compact-goleveldb",
Aliases: []string{"experimental_compact_goleveldb"},
Short: "force compacts the CometBFT storage engine (only GoLevelDB supported)",
var CompactCmd = &cobra.Command{
Use: "experimental-compact",
Aliases: []string{"experimental_compact"},
Short: "force compacts the CometBFT storage engine (supports GoLevelDB and Pebble)",
Long: `
This is a temporary utility command that performs a force compaction on the state
and blockstores to reduce disk space for a pruning node. This should only be run
once the node has stopped. This command will likely be omitted in the future after
the planned refactor to the storage engine.
This command forces a compaction of the CometBFT storage engine.

Currently, only GoLevelDB is supported.
`,
Currently, GoLevelDB and Pebble are supported.
`,
RunE: func(cmd *cobra.Command, args []string) error {
if config.DBBackend != "goleveldb" {
return errors.New("compaction is currently only supported with goleveldb")
configFile, err := cmd.Flags().GetString("config")
if err != nil {
return err
}

compactGoLevelDBs(config.RootDir, logger)
return nil
conf := cfg.DefaultConfig()
conf.SetRoot(configFile)

logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))

switch conf.DBBackend {
case "goleveldb":
return compactGoLevelDBs(conf.RootDir, logger)
case "pebble":
return compactPebbleDBs(conf.RootDir, logger)
default:
return fmt.Errorf("compaction is currently only supported with goleveldb and pebble, got %s", conf.DBBackend)
}
},
}

func compactGoLevelDBs(rootDir string, logger log.Logger) {
func compactGoLevelDBs(rootDir string, logger log.Logger) error {
dbNames := []string{"state", "blockstore"}
o := &opt.Options{
DisableSeeksCompaction: true,
Expand Down Expand Up @@ -64,4 +76,30 @@ func compactGoLevelDBs(rootDir string, logger log.Logger) {
}()
}
wg.Wait()
return nil
}

func compactPebbleDBs(rootDir string, logger log.Logger) error {
dbNames := []string{"state", "blockstore", "evidence", "tx_index"}
for _, dbName := range dbNames {
dbPath := filepath.Join(rootDir, "data", dbName+".db")
logger.Info("Compacting db", "path", dbPath)

db, err := pebble.Open(dbPath, &pebble.Options{})
if err != nil {
return fmt.Errorf("failed to open db %s: %w", dbPath, err)
}

err = db.Compact(nil, nil, true)
if err != nil {
db.Close()
return fmt.Errorf("failed to compact db %s: %w", dbPath, err)
}

err = db.Close()
if err != nil {
return fmt.Errorf("failed to close db %s: %w", dbPath, err)
}
}
return nil
}
2 changes: 1 addition & 1 deletion cmd/cometbft/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func main() {
cmd.GenNodeKeyCmd,
cmd.VersionCmd,
cmd.RollbackStateCmd,
cmd.CompactGoLevelDBCmd,
cmd.CompactCmd,
debug.DebugCmd,
cli.NewCompletionCmd(rootCmd, true),
)
Expand Down
22 changes: 5 additions & 17 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,25 +182,13 @@ type BaseConfig struct { //nolint: maligned
// and verifying their commits
FastSyncMode bool `mapstructure:"fast_sync"`

// Database backend: goleveldb | cleveldb | boltdb | rocksdb
// Database backend: goleveldb | cleveldb | boltdb | rocksdb | pebble
// * 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)
// * rocksdb (uses github.com/tecbot/gorocksdb)
// - EXPERIMENTAL
// - requires gcc
// - use rocksdb build tag (go build -tags rocksdb)
// * rocksdb (uses github.com/linxGnu/grocksdb)
// * pebble (uses github.com/cockroachdb/pebble - most performant implementation)
// * badgerdb (uses github.com/dgraph-io/badger)
// - EXPERIMENTAL
// - use badgerdb build tag (go build -tags badgerdb)
DBBackend string `mapstructure:"db_backend"`

// Database directory
Expand Down Expand Up @@ -250,7 +238,7 @@ func DefaultBaseConfig() BaseConfig {
LogFormat: LogFormatPlain,
FastSyncMode: true,
FilterPeers: false,
DBBackend: "goleveldb",
DBBackend: "pebble",
DBPath: "data",
}
}
Expand Down Expand Up @@ -531,7 +519,7 @@ type P2PConfig struct { //nolint: maligned
ExternalAddress string `mapstructure:"external_address"`

// Comma separated list of seed nodes to connect to
// We only use these if we cant connect to peers in the addrbook
// We only use these if we can't connect to peers in the addrbook
Seeds string `mapstructure:"seeds"`

// Comma separated list of nodes to keep persistent connections to
Expand Down
20 changes: 4 additions & 16 deletions config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,14 @@ moniker = "{{ .BaseConfig.Moniker }}"
# and verifying their commits
fast_sync = {{ .BaseConfig.FastSyncMode }}

# Database backend: goleveldb | cleveldb | boltdb | rocksdb | badgerdb
# Database backend: goleveldb | cleveldb | boltdb | rocksdb | badgerdb | pebble
# * 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)
# * rocksdb (uses github.com/tecbot/gorocksdb)
# - EXPERIMENTAL
# - requires gcc
# - use rocksdb build tag (go build -tags rocksdb)
# * rocksdb (uses github.com/linxGnu/grocksdb)
# * pebble (uses github.com/cockroachdb/pebble - most performant implementation)
# * badgerdb (uses github.com/dgraph-io/badger)
# - EXPERIMENTAL
# - use badgerdb build tag (go build -tags badgerdb)
db_backend = "{{ .BaseConfig.DBBackend }}"
db_backend = "pebble"

# Database directory
db_dir = "{{ js .BaseConfig.DBPath }}"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/generator/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
}

// The following specify randomly chosen values for testnet nodes.
nodeDatabases = uniformChoice{"goleveldb"}
nodeDatabases = uniformChoice{"pebble"}
ipv6 = uniformChoice{false, true}
// FIXME: grpc disabled due to https://github.com/tendermint/tendermint/issues/5439
nodeABCIProtocols = uniformChoice{"unix", "tcp", "builtin"}
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/pkg/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func NewTestnetFromManifest(manifest Manifest, file string, ifd InfrastructureDa
ExternalIP: extIP,
ProxyPort: ind.Port,
Mode: ModeValidator,
Database: "goleveldb",
Database: "pebble",
ABCIProtocol: Protocol(testnet.ABCIProtocol),
PrivvalProtocol: ProtocolFile,
StartAt: nodeManifest.StartAt,
Expand Down Expand Up @@ -393,7 +393,7 @@ func (n Node) Validate(testnet Testnet) error {
return fmt.Errorf("invalid block sync setting %q", n.BlockSyncVersion)
}
switch n.Database {
case "goleveldb":
case "pebble":
default:
return fmt.Errorf("invalid database setting %q", n.Database)
}
Expand Down
6 changes: 3 additions & 3 deletions test/loadtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ the timestamp of the block the transaction was executed in to determine transact
minimum, maximum, and average latency as well as the standard deviation.

Below is a basic invocation of the report tool with a data directory under `/home/test/.cometbft/data/`
where the data was saved in a `goleveldb` database.
where the data was saved in a `pebble` database.


```bash
./build/report --database-type goleveldb --data-dir ~/.cometbft/data
./build/report --database-type pebble --data-dir ~/.cometbft/data
```

The `report` tool also supports outputting the raw data as `csv`. This can be
Expand All @@ -61,7 +61,7 @@ Below is an invocation of the report tool that outputs the data to a `csv` file
in `out.csv`

```bash
./build/report --database-type goleveldb --data-dir ~/.cometbft/data --csv out.csv
./build/report --database-type pebble --data-dir ~/.cometbft/data --csv out.csv
```

The `report` tool outputs the data for each experiment separately, identified
Expand Down
2 changes: 1 addition & 1 deletion test/loadtime/cmd/report/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

var (
db = flag.String("database-type", "goleveldb", "the type of database holding the blockstore")
db = flag.String("database-type", "pebble", "the type of database holding the blockstore")
dir = flag.String("data-dir", "", "path to the directory containing the CometBFT databases")
csvOut = flag.String("csv", "", "dump the extracted latencies as raw csv for use in additional tooling")
)
Expand Down
Loading