@@ -30,6 +30,7 @@ import (
30
30
"github.com/ethereum/go-ethereum/ethdb"
31
31
"github.com/ethereum/go-ethereum/ethdb/leveldb"
32
32
"github.com/ethereum/go-ethereum/ethdb/memorydb"
33
+ "github.com/ethereum/go-ethereum/ethdb/pebble"
33
34
"github.com/ethereum/go-ethereum/log"
34
35
"github.com/olekukonko/tablewriter"
35
36
)
@@ -321,6 +322,16 @@ func NewLevelDBDatabase(file string, cache int, handles int, namespace string, r
321
322
return NewDatabase (db ), nil
322
323
}
323
324
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
+
324
335
const (
325
336
dbPebble = "pebble"
326
337
dbLeveldb = "leveldb"
@@ -375,26 +386,16 @@ func openKeyValueDatabase(o OpenOptions) (ethdb.Database, error) {
375
386
return nil , fmt .Errorf ("db.engine choice was %v but found pre-existing %v database in specified data directory" , o .Type , existingDb )
376
387
}
377
388
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 )
384
391
}
385
392
if o .Type == dbLeveldb || existingDb == dbLeveldb {
386
393
log .Info ("Using leveldb as the backing database" )
387
394
return NewLevelDBDatabase (o .Directory , o .Cache , o .Handles , o .Namespace , o .ReadOnly )
388
395
}
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 )
398
399
}
399
400
400
401
// Open opens both a disk-based key-value database such as leveldb or pebble, but also
0 commit comments