aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-10-20 20:36:48 +0800
committerFelix Lange <fjl@twurst.com>2016-10-20 20:37:01 +0800
commit66ee2dec53f9e18b4def0b0005e291fdd810f327 (patch)
treec0d2865e696699f02b4c3bcade5c1b83b2945a7c
parentf2ae2f7eef1e3e15b9e6f81e2b5895e2d20d12bc (diff)
downloaddexon-66ee2dec53f9e18b4def0b0005e291fdd810f327.tar
dexon-66ee2dec53f9e18b4def0b0005e291fdd810f327.tar.gz
dexon-66ee2dec53f9e18b4def0b0005e291fdd810f327.tar.bz2
dexon-66ee2dec53f9e18b4def0b0005e291fdd810f327.tar.lz
dexon-66ee2dec53f9e18b4def0b0005e291fdd810f327.tar.xz
dexon-66ee2dec53f9e18b4def0b0005e291fdd810f327.tar.zst
dexon-66ee2dec53f9e18b4def0b0005e291fdd810f327.zip
internal/ethapi: add debug.chaindbCompact
-rw-r--r--internal/ethapi/api.go19
-rw-r--r--internal/web3ext/web3ext.go4
2 files changed, 23 insertions, 0 deletions
diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go
index de88a5d1e..b9275518e 100644
--- a/internal/ethapi/api.go
+++ b/internal/ethapi/api.go
@@ -39,6 +39,7 @@ import (
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
"github.com/syndtr/goleveldb/leveldb"
+ "github.com/syndtr/goleveldb/leveldb/util"
"golang.org/x/net/context"
)
@@ -1321,6 +1322,24 @@ func (api *PrivateDebugAPI) ChaindbProperty(property string) (string, error) {
return ldb.LDB().GetProperty(property)
}
+func (api *PrivateDebugAPI) ChaindbCompact() error {
+ ldb, ok := api.b.ChainDb().(interface {
+ LDB() *leveldb.DB
+ })
+ if !ok {
+ return fmt.Errorf("chaindbCompact does not work for memory databases")
+ }
+ for b := byte(0); b < 255; b++ {
+ glog.V(logger.Info).Infof("compacting chain DB range 0x%0.2X-0x%0.2X", b, b+1)
+ err := ldb.LDB().CompactRange(util.Range{Start: []byte{b}, Limit: []byte{b + 1}})
+ if err != nil {
+ glog.Errorf("compaction error: %v", err)
+ return err
+ }
+ }
+ return nil
+}
+
// SetHead rewinds the head of the blockchain to a previous block.
func (api *PrivateDebugAPI) SetHead(number rpc.HexNumber) {
api.b.SetHead(uint64(number.Int64()))
diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go
index cbbab0ece..f935cadca 100644
--- a/internal/web3ext/web3ext.go
+++ b/internal/web3ext/web3ext.go
@@ -338,6 +338,10 @@ web3._extend({
outputFormatter: console.log
}),
new web3._extend.Method({
+ name: 'chaindbCompact',
+ call: 'debug_chaindbCompact',
+ }),
+ new web3._extend.Method({
name: 'metrics',
call: 'debug_metrics',
params: 1