Use bulk option only for initial load of DB

This commit is contained in:
Martin Boehm 2018-02-05 17:47:20 +01:00
parent d6e9b5caa4
commit fdd9c9b99f

View File

@ -344,6 +344,8 @@ func resyncIndex(bulk bool) error {
glog.Info("resync: local is behind") glog.Info("resync: local is behind")
hash = header.Next hash = header.Next
startHeight = localBestHeight startHeight = localBestHeight
// bulk load is allowed only for empty db, otherwise we could get rocksdb "error db has more levels than options.num_levels"
bulk = false
} else { } else {
// If the local block is missing, we're indexing from the genesis block // If the local block is missing, we're indexing from the genesis block
// or from the start block specified by flags // or from the start block specified by flags
@ -359,7 +361,7 @@ func resyncIndex(bulk bool) error {
// if parallel operation is enabled and the number of blocks to be connected is large, // if parallel operation is enabled and the number of blocks to be connected is large,
// use parallel routine to load majority of blocks // use parallel routine to load majority of blocks
if bulk && *syncWorkers > 1 { if *syncWorkers > 1 {
chainBestHeight, err := chain.GetBestBlockHeight() chainBestHeight, err := chain.GetBestBlockHeight()
if err != nil { if err != nil {
return err return err
@ -370,6 +372,7 @@ func resyncIndex(bulk bool) error {
startHeight, startHeight,
chainBestHeight, chainBestHeight,
*syncWorkers, *syncWorkers,
bulk,
) )
if err != nil { if err != nil {
return err return err
@ -415,11 +418,15 @@ func connectBlocksParallel(
lower uint32, lower uint32,
higher uint32, higher uint32,
numWorkers int, numWorkers int,
bulk bool,
) error { ) error {
err := index.ReopenWithBulk(true) var err error
if bulk {
err = index.ReopenWithBulk(true)
if err != nil { if err != nil {
return err return err
} }
}
var wg sync.WaitGroup var wg sync.WaitGroup
hch := make(chan string, numWorkers) hch := make(chan string, numWorkers)
@ -459,6 +466,7 @@ func connectBlocksParallel(
hch <- hash hch <- hash
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 h%50000 == 0 { if h%50000 == 0 {
// wait for the workers to finish block // wait for the workers to finish block
WaitAgain: WaitAgain:
@ -472,16 +480,17 @@ func connectBlocksParallel(
} }
break break
} }
if err = index.CompactDatabase(true); err != nil { if err = index.CompactDatabase(bulk); err != nil {
break break
} }
} }
} }
} }
}
close(hch) close(hch)
wg.Wait() wg.Wait()
if err == nil { if err == nil && bulk {
err = index.ReopenWithBulk(false) err = index.ReopenWithBulk(false)
} }