Merge pull request #19856 from karalabe/chaindb-property-fix

internal/ethapi: fix debug.chaindbProperty
ChrisChinchilla-patch-3
Péter Szilágyi 5 years ago committed by GitHub
commit e8c9579fb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      internal/ethapi/api.go

@ -44,7 +44,6 @@ import (
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
"github.com/syndtr/goleveldb/leveldb"
"github.com/tyler-smith/go-bip39" "github.com/tyler-smith/go-bip39"
) )
@ -1633,22 +1632,18 @@ func NewPrivateDebugAPI(b Backend) *PrivateDebugAPI {
return &PrivateDebugAPI{b: b} return &PrivateDebugAPI{b: b}
} }
// ChaindbProperty returns leveldb properties of the chain database. // ChaindbProperty returns leveldb properties of the key-value database.
func (api *PrivateDebugAPI) ChaindbProperty(property string) (string, error) { func (api *PrivateDebugAPI) ChaindbProperty(property string) (string, error) {
ldb, ok := api.b.ChainDb().(interface {
LDB() *leveldb.DB
})
if !ok {
return "", fmt.Errorf("chaindbProperty does not work for memory databases")
}
if property == "" { if property == "" {
property = "leveldb.stats" property = "leveldb.stats"
} else if !strings.HasPrefix(property, "leveldb.") { } else if !strings.HasPrefix(property, "leveldb.") {
property = "leveldb." + property property = "leveldb." + property
} }
return ldb.LDB().GetProperty(property) return api.b.ChainDb().Stat(property)
} }
// ChaindbCompact flattens the entire key-value database into a single level,
// removing all unused slots and merging all keys.
func (api *PrivateDebugAPI) ChaindbCompact() error { func (api *PrivateDebugAPI) ChaindbCompact() error {
for b := byte(0); b < 255; b++ { for b := byte(0); b < 255; b++ {
log.Info("Compacting chain database", "range", fmt.Sprintf("0x%0.2X-0x%0.2X", b, b+1)) log.Info("Compacting chain database", "range", fmt.Sprintf("0x%0.2X-0x%0.2X", b, b+1))

Loading…
Cancel
Save