Skip to content

Commit

Permalink
Enable parallel sync only for initial sync
Browse files Browse the repository at this point in the history
  • Loading branch information
martinboehm committed Apr 12, 2019
1 parent 8fb4772 commit dffcded
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions db/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@ func (w *SyncWorker) ResyncIndex(onNewBlock bchain.OnNewBlockFunc, initialSync b
if err == nil {
w.is.FinishedSync(bh)
}
return nil
return err
case errSynced:
// this is not actually error but flag that resync wasn't necessary
w.is.FinishedSyncNoChange()
w.metrics.IndexDBSize.Set(float64(w.db.DatabaseSizeOnDisk()))
if initialSync {
d := time.Since(start)
glog.Info("resync: finished in ", d)
}
return nil
}

Expand Down Expand Up @@ -113,7 +117,8 @@ func (w *SyncWorker) resyncIndex(onNewBlock bchain.OnNewBlockFunc, initialSync b
}
// if parallel operation is enabled and the number of blocks to be connected is large,
// use parallel routine to load majority of blocks
if w.syncWorkers > 1 {
// use parallel sync only in case of initial sync because it puts the db to inconsistent state
if w.syncWorkers > 1 && initialSync {
remoteBestHeight, err := w.chain.GetBestBlockHeight()
if err != nil {
return err
Expand Down

0 comments on commit dffcded

Please sign in to comment.