Skip to content

Commit 509a64f

Browse files
authored
cmd, core, ethdb: enable Pebble on 32 bits and OpenBSD too (#28335)
* cmd, core, ethdb: enable Pebble on 32 bits and OpenBSD too * ethdb/pebble: use Pebble's internal constant calculation
1 parent 425cb6f commit 509a64f

File tree

6 files changed

+26
-98
lines changed

6 files changed

+26
-98
lines changed

cmd/utils/flags.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -961,17 +961,12 @@ var (
961961
DataDirFlag,
962962
AncientFlag,
963963
RemoteDBFlag,
964+
DBEngineFlag,
964965
StateSchemeFlag,
965966
HttpHeaderFlag,
966967
}
967968
)
968969

969-
func init() {
970-
if rawdb.PebbleEnabled {
971-
DatabaseFlags = append(DatabaseFlags, DBEngineFlag)
972-
}
973-
}
974-
975970
// MakeDataDir retrieves the currently requested data directory, terminating
976971
// if none (or the empty string) is specified. If the node is starting a testnet,
977972
// then a subdirectory of the specified datadir will be used.

core/rawdb/database.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/ethereum/go-ethereum/ethdb"
3131
"github.com/ethereum/go-ethereum/ethdb/leveldb"
3232
"github.com/ethereum/go-ethereum/ethdb/memorydb"
33+
"github.com/ethereum/go-ethereum/ethdb/pebble"
3334
"github.com/ethereum/go-ethereum/log"
3435
"github.com/olekukonko/tablewriter"
3536
)
@@ -321,6 +322,16 @@ func NewLevelDBDatabase(file string, cache int, handles int, namespace string, r
321322
return NewDatabase(db), nil
322323
}
323324

325+
// NewPebbleDBDatabase creates a persistent key-value database without a freezer
326+
// moving immutable chain segments into cold storage.
327+
func NewPebbleDBDatabase(file string, cache int, handles int, namespace string, readonly, ephemeral bool) (ethdb.Database, error) {
328+
db, err := pebble.New(file, cache, handles, namespace, readonly, ephemeral)
329+
if err != nil {
330+
return nil, err
331+
}
332+
return NewDatabase(db), nil
333+
}
334+
324335
const (
325336
dbPebble = "pebble"
326337
dbLeveldb = "leveldb"
@@ -375,26 +386,16 @@ func openKeyValueDatabase(o OpenOptions) (ethdb.Database, error) {
375386
return nil, fmt.Errorf("db.engine choice was %v but found pre-existing %v database in specified data directory", o.Type, existingDb)
376387
}
377388
if o.Type == dbPebble || existingDb == dbPebble {
378-
if PebbleEnabled {
379-
log.Info("Using pebble as the backing database")
380-
return NewPebbleDBDatabase(o.Directory, o.Cache, o.Handles, o.Namespace, o.ReadOnly, o.Ephemeral)
381-
} else {
382-
return nil, errors.New("db.engine 'pebble' not supported on this platform")
383-
}
389+
log.Info("Using pebble as the backing database")
390+
return NewPebbleDBDatabase(o.Directory, o.Cache, o.Handles, o.Namespace, o.ReadOnly, o.Ephemeral)
384391
}
385392
if o.Type == dbLeveldb || existingDb == dbLeveldb {
386393
log.Info("Using leveldb as the backing database")
387394
return NewLevelDBDatabase(o.Directory, o.Cache, o.Handles, o.Namespace, o.ReadOnly)
388395
}
389-
// No pre-existing database, no user-requested one either. Default to Pebble
390-
// on supported platforms and LevelDB on anything else.
391-
if PebbleEnabled {
392-
log.Info("Defaulting to pebble as the backing database")
393-
return NewPebbleDBDatabase(o.Directory, o.Cache, o.Handles, o.Namespace, o.ReadOnly, o.Ephemeral)
394-
} else {
395-
log.Info("Defaulting to leveldb as the backing database")
396-
return NewLevelDBDatabase(o.Directory, o.Cache, o.Handles, o.Namespace, o.ReadOnly)
397-
}
396+
// No pre-existing database, no user-requested one either. Default to Pebble.
397+
log.Info("Defaulting to pebble as the backing database")
398+
return NewPebbleDBDatabase(o.Directory, o.Cache, o.Handles, o.Namespace, o.ReadOnly, o.Ephemeral)
398399
}
399400

400401
// Open opens both a disk-based key-value database such as leveldb or pebble, but also

core/rawdb/databases_64bit.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

core/rawdb/databases_non64bit.go

Lines changed: 0 additions & 34 deletions
This file was deleted.

ethdb/pebble/pebble.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
// You should have received a copy of the GNU Lesser General Public License
1515
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
1616

17-
//go:build (arm64 || amd64) && !openbsd
18-
1917
// Package pebble implements the key-value database layer based on pebble.
2018
package pebble
2119

@@ -148,8 +146,15 @@ func New(file string, cache int, handles int, namespace string, readonly bool, e
148146

149147
// The max memtable size is limited by the uint32 offsets stored in
150148
// internal/arenaskl.node, DeferredBatchOp, and flushableBatchEntry.
151-
// Taken from https://github.com/cockroachdb/pebble/blob/master/open.go#L38
152-
maxMemTableSize := 4<<30 - 1 // Capped by 4 GB
149+
//
150+
// - MaxUint32 on 64-bit platforms;
151+
// - MaxInt on 32-bit platforms.
152+
//
153+
// It is used when slices are limited to Uint32 on 64-bit platforms (the
154+
// length limit for slices is naturally MaxInt on 32-bit platforms).
155+
//
156+
// Taken from https://github.com/cockroachdb/pebble/blob/master/internal/constants/constants.go
157+
maxMemTableSize := (1<<31)<<(^uint(0)>>63) - 1
153158

154159
// Two memory tables is configured which is identical to leveldb,
155160
// including a frozen memory table and another live one.

ethdb/pebble/pebble_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
// You should have received a copy of the GNU Lesser General Public License
1515
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
1616

17-
//go:build (arm64 || amd64) && !openbsd
18-
1917
package pebble
2018

2119
import (

0 commit comments

Comments
 (0)