Use constants instead of magic numbers
parent
741f410a5b
commit
359d7ee1c4
23
blockbook.go
23
blockbook.go
|
@ -18,6 +18,21 @@ import (
|
||||||
"github.com/pkg/profile"
|
"github.com/pkg/profile"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// how many blocks are connected before database is compacted in connectBlocksParallel
|
||||||
|
const compactAfterBlocks = 40000
|
||||||
|
|
||||||
|
// resync index at least each resyncIndexPeriodMs (could be more often if invoked by message from ZeroMQ)
|
||||||
|
const resyncIndexPeriodMs = 935093
|
||||||
|
|
||||||
|
// debounce too close requests for resync
|
||||||
|
const debounceResyncIndexMs = 1009
|
||||||
|
|
||||||
|
// resync mempool at least each resyncIndexPeriodMs (could be more often if invoked by message from ZeroMQ)
|
||||||
|
const resyncMempoolPeriodMs = 60017
|
||||||
|
|
||||||
|
// debounce too close requests for resync mempool (ZeroMQ sends message for each tx, when new block there are many transactions)
|
||||||
|
const debounceResyncMempoolMs = 1009
|
||||||
|
|
||||||
var (
|
var (
|
||||||
rpcURL = flag.String("rpcurl", "http://localhost:8332", "url of bitcoin RPC service")
|
rpcURL = flag.String("rpcurl", "http://localhost:8332", "url of bitcoin RPC service")
|
||||||
rpcUser = flag.String("rpcuser", "rpc", "rpc username")
|
rpcUser = flag.String("rpcuser", "rpc", "rpc username")
|
||||||
|
@ -174,7 +189,7 @@ func main() {
|
||||||
*syncChunk,
|
*syncChunk,
|
||||||
*syncWorkers,
|
*syncWorkers,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
glog.Fatalf("connectBlocksParallel %v", err)
|
glog.Fatalf("connectBlocksParallelInChunks %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,7 +233,7 @@ func syncIndexLoop() {
|
||||||
defer close(chanSyncIndexDone)
|
defer close(chanSyncIndexDone)
|
||||||
glog.Info("syncIndexLoop starting")
|
glog.Info("syncIndexLoop starting")
|
||||||
// resync index about every 15 minutes if there are no chanSyncIndex requests, with debounce 1 second
|
// resync index about every 15 minutes if there are no chanSyncIndex requests, with debounce 1 second
|
||||||
tickAndDebounce(935093*time.Millisecond, 1009*time.Millisecond, chanSyncIndex, func() {
|
tickAndDebounce(resyncIndexPeriodMs*time.Millisecond, debounceResyncIndexMs*time.Millisecond, chanSyncIndex, func() {
|
||||||
if err := resyncIndex(false); err != nil {
|
if err := resyncIndex(false); err != nil {
|
||||||
glog.Error("syncIndexLoop", err)
|
glog.Error("syncIndexLoop", err)
|
||||||
}
|
}
|
||||||
|
@ -230,7 +245,7 @@ func syncMempoolLoop() {
|
||||||
defer close(chanSyncMempoolDone)
|
defer close(chanSyncMempoolDone)
|
||||||
glog.Info("syncMempoolLoop starting")
|
glog.Info("syncMempoolLoop starting")
|
||||||
// resync mempool about every minute if there are no chanSyncMempool requests, with debounce 1 second
|
// resync mempool about every minute if there are no chanSyncMempool requests, with debounce 1 second
|
||||||
tickAndDebounce(60017*time.Millisecond, 1009*time.Millisecond, chanSyncMempool, func() {
|
tickAndDebounce(resyncMempoolPeriodMs*time.Millisecond, debounceResyncMempoolMs*time.Millisecond, chanSyncMempool, func() {
|
||||||
if err := mempool.Resync(); err != nil {
|
if err := mempool.Resync(); err != nil {
|
||||||
glog.Error("syncMempoolLoop", err)
|
glog.Error("syncMempoolLoop", err)
|
||||||
}
|
}
|
||||||
|
@ -467,7 +482,7 @@ func connectBlocksParallel(
|
||||||
if h > 0 && h%1000 == 0 {
|
if h > 0 && h%1000 == 0 {
|
||||||
glog.Info("connecting block ", h, " ", hash)
|
glog.Info("connecting block ", h, " ", hash)
|
||||||
if bulk {
|
if bulk {
|
||||||
if h%50000 == 0 {
|
if h%compactAfterBlocks == 0 {
|
||||||
// wait for the workers to finish block
|
// wait for the workers to finish block
|
||||||
WaitAgain:
|
WaitAgain:
|
||||||
for {
|
for {
|
||||||
|
|
|
@ -15,6 +15,10 @@ import (
|
||||||
"github.com/tecbot/gorocksdb"
|
"github.com/tecbot/gorocksdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// iterator creates snapshot, which takes lots of resources
|
||||||
|
// when doing huge scan, it is better to close it and reopen from time to time to free the resources
|
||||||
|
const disconnectBlocksRefreshIterator = uint64(1000000)
|
||||||
|
|
||||||
func RepairRocksDB(name string) error {
|
func RepairRocksDB(name string) error {
|
||||||
glog.Infof("rocksdb: repair")
|
glog.Infof("rocksdb: repair")
|
||||||
opts := gorocksdb.NewDefaultOptions()
|
opts := gorocksdb.NewDefaultOptions()
|
||||||
|
@ -429,7 +433,7 @@ func (d *RocksDB) DisconnectBlocks(
|
||||||
it.Seek(seekKey)
|
it.Seek(seekKey)
|
||||||
it.Next()
|
it.Next()
|
||||||
}
|
}
|
||||||
for count = 0; it.Valid() && count < 1000000; it.Next() {
|
for count = 0; it.Valid() && count < disconnectBlocksRefreshIterator; it.Next() {
|
||||||
totalOutputs++
|
totalOutputs++
|
||||||
count++
|
count++
|
||||||
key = it.Key().Data()
|
key = it.Key().Data()
|
||||||
|
|
Loading…
Reference in New Issue