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

chore(pebbledb): remove isForceSync flag #125

Merged
merged 4 commits into from
Jan 25, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
- Removed supprot for RemoteDB ([\#118](https://github.com/cometbft/cometbft-
db/issues/118))
- Remove remotedb ([\#121](https://github.com/cometbft/cometbft-db/pull/121))
1 change: 0 additions & 1 deletion .changelog/unreleased/chore/114.md

This file was deleted.

2 changes: 1 addition & 1 deletion .changelog/unreleased/features/112-pebbledb.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Added support for pebbledb [v1.0.0](https://github.com/cockroachdb/pebble/releases/tag/v1.0.0) ([\#112](https://github.com/cometbft/cometbft-db/pull/112))
- Add [pebbledb](https://github.com/cockroachdb/pebble) ([\#112](https://github.com/cometbft/cometbft-db/pull/112))
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@ linters-settings:
- 'fmt.Printf'
- 'fmt.Print'
- 'fmt.Println'
- 'myFunction'
- 'myFunction'
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ Go 1.21+
performance, and includes advanced features such as serializable ACID
transactions, write batches, compression, and more.

- **[PebbleDB](https://github.com/cockroachdb/pebble) [experimental]:** Pebble
melekes marked this conversation as resolved.
Show resolved Hide resolved
is a LevelDB/RocksDB inspired key-value store focused on performance and
internal usage by CockroachDB. Pebble inherits the RocksDB file formats and a
few extensions such as range deletion tombstones, table-level bloom filters,
and updates to the MANIFEST format.

XXX: there are reports of broken upgrade process when using [Cosmos

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
XXX: there are reports of broken upgrade process when using [Cosmos
CAVEAT: there are reports of broken upgrade process when using [Cosmos

XXX is a jargon more appropriate for the code docs, I think.

SDK](https://github.com/cosmos/cosmos-sdk).

## Meta-databases

- **PrefixDB [stable]:** A database which wraps another database and uses a
Expand All @@ -66,11 +75,6 @@ Go 1.21+
the Cosmos SDK to give different modules their own namespaced database in a
single application database.

- **RemoteDB [experimental]:** A database that connects to distributed
CometBFT db instances via [gRPC](https://grpc.io/). This can help with
detaching difficult deployments such as LevelDB, and can also ease dependency
management for CometBFT developers.

## Tests

To test common databases, run `make test`. If all databases are available on the
Expand Down
2 changes: 1 addition & 1 deletion badger_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewBadgerDB(dbName, dir string) (*BadgerDB, error) {
// the final directory to use for the database.
path := filepath.Join(dir, dbName)

if err := os.MkdirAll(path, 0755); err != nil {
if err := os.MkdirAll(path, 0o755); err != nil {
return nil, err
}
opts := badger.DefaultOptions(path)
Expand Down
4 changes: 1 addition & 3 deletions boltdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import (
"go.etcd.io/bbolt"
)

var (
bucket = []byte("tm")
)
var bucket = []byte("tm")

func init() {
registerDBCreator(BoltDBBackend, func(name, dir string) (DB, error) {
Expand Down
7 changes: 3 additions & 4 deletions cleveldb_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func (itr cLevelDBIterator) Domain() ([]byte, []byte) {

// Valid implements Iterator.
func (itr cLevelDBIterator) Valid() bool {

// Once invalid, forever invalid.
if itr.isInvalid {
return false
Expand All @@ -76,9 +75,9 @@ func (itr cLevelDBIterator) Valid() bool {
}

// If key is end or past it, invalid.
var start = itr.start
var end = itr.end
var key = itr.source.Key()
start := itr.start
end := itr.end
key := itr.source.Key()
if itr.isReverse {
if start != nil && bytes.Compare(key, start) < 0 {
itr.isInvalid = true
Expand Down
3 changes: 0 additions & 3 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,3 @@ comment:
layout: "reach, diff, files, tree"
behavior: default # update if exists else create new
require_changes: true

ignore:
- "remotedb/proto"
56 changes: 0 additions & 56 deletions pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,11 @@ import (
"github.com/cockroachdb/pebble"
)

// ForceSync is a a compile time flag to force using Sync for NoSync functions (Set, Delete, Write).

/*
This is set at compile time. Could be 0 or 1, defaults is 1.
It forces using Sync for NoSync functions (Set, Delete, Write)

Notice if ForceSync=0: performance will be better. However, there is an issue when upgrading.
And the workaround (if using ForceSync=0):
At the upgrade-block, the sdk will panic without flushing data to disk or closing dbs properly.

Upgrade guide:
1. After seeing `UPGRADE "xxxx" NEED at height....`, restart current version with `-X github.com/tendermint/tm-db.ForceSync=1`
2. Restart new version as normal

Example: Upgrading sifchain from v0.14.0 to v0.15.0

# log:
panic: UPGRADE "0.15.0" NEEDED at height: 8170210: {"binaries":{"linux/amd64":"https://github.com/Sifchain/sifnode/releases/download/v0.15.0/sifnoded-v0.15.0-linux-amd64.zip?checksum=0c03b5846c5a13dcc0d9d3127e4f0cee0aeddcf2165177b2f2e0d60dbcf1a5ea"}}

# step1
git reset --hard
git checkout v0.14.0
go mod edit -replace github.com/tendermint/tm-db=github.com/baabeetaa/tm-db@pebble
go mod tidy
go install -tags pebbledb -ldflags "-w -s -X github.com/cosmos/cosmos-sdk/types.DBBackend=pebbledb -X github.com/tendermint/tm-db.ForceSync=1" ./cmd/sifnoded

$HOME/go/bin/sifnoded start --db_backend=pebbledb

# step 2
git reset --hard
git checkout v0.15.0
go mod edit -replace github.com/tendermint/tm-db=github.com/baabeetaa/tm-db@pebble
go mod tidy
go install -tags pebbledb -ldflags "-w -s -X github.com/cosmos/cosmos-sdk/types.DBBackend=pebbledb" ./cmd/sifnoded

$HOME/go/bin/sifnoded start --db_backend=pebbledb
*/
var (
ForceSync = "1"
isForceSync = false
)

func init() {
dbCreator := func(name string, dir string) (DB, error) {
return NewPebbleDB(name, dir)
}
registerDBCreator(PebbleDBBackend, dbCreator)

if ForceSync == "1" {
isForceSync = true
}
}

// PebbleDB is a PebbleDB backend.
Expand Down Expand Up @@ -130,10 +84,6 @@ func (db *PebbleDB) Set(key []byte, value []byte) error {
}

wopts := pebble.NoSync
if isForceSync {
wopts = pebble.Sync
}

err := db.db.Set(key, value, wopts)
if err != nil {
return err
Expand Down Expand Up @@ -163,9 +113,6 @@ func (db *PebbleDB) Delete(key []byte) error {
}

wopts := pebble.NoSync
if isForceSync {
wopts = pebble.Sync
}
err := db.db.Delete(key, wopts)
if err != nil {
return err
Expand Down Expand Up @@ -298,9 +245,6 @@ func (b *pebbleDBBatch) Write() error {
}

wopts := pebble.NoSync
if isForceSync {
wopts = pebble.Sync
}
err := b.batch.Commit(wopts)
if err != nil {
return err
Expand Down
10 changes: 0 additions & 10 deletions pebble_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ func TestPebbleDBBackend(t *testing.T) {
assert.True(t, ok)
}

// func TestPebbleDBStats(t *testing.T) {
// name := fmt.Sprintf("test_%x", randStr(12))
// dir := os.TempDir()
// db, err := NewDB(name, PebbleDBBackend, dir)
// require.NoError(t, err)
// defer cleanupDBDir(dir, name)

// assert.NotEmpty(t, db.Stats())
// }

func BenchmarkPebbleDBRandomReadsWrites(b *testing.B) {
name := fmt.Sprintf("test_%x", randStr(12))
dir := os.TempDir()
Expand Down
7 changes: 3 additions & 4 deletions rocksdb_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func (itr *rocksDBIterator) Domain() ([]byte, []byte) {

// Valid implements Iterator.
func (itr *rocksDBIterator) Valid() bool {

// Once invalid, forever invalid.
if itr.isInvalid {
return false
Expand All @@ -75,9 +74,9 @@ func (itr *rocksDBIterator) Valid() bool {
}

// If key is end or past it, invalid.
var start = itr.start
var end = itr.end
var key = moveSliceToBytes(itr.source.Key())
start := itr.start
end := itr.end
key := moveSliceToBytes(itr.source.Key())
if itr.isReverse {
if start != nil && bytes.Compare(key, start) < 0 {
itr.isInvalid = true
Expand Down
Loading