mirror of https://github.com/bitcoin/bitcoin
index: decrease ThreadSync cs_main contention
Only NextSyncBlock requires cs_main lock. The other function calls like Commit or Rewind will lock or not cs_main internally when they need it. Avoiding keeping cs_main locked when Commit() or Rewind() write data to disk.
This commit is contained in:
parent
f1469eb454
commit
0faafb57f8
|
@ -159,23 +159,20 @@ void BaseIndex::Sync()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
const CBlockIndex* pindex_next = WITH_LOCK(cs_main, return NextSyncBlock(pindex, m_chainstate->m_chain));
|
||||||
LOCK(cs_main);
|
if (!pindex_next) {
|
||||||
const CBlockIndex* pindex_next = NextSyncBlock(pindex, m_chainstate->m_chain);
|
SetBestBlockIndex(pindex);
|
||||||
if (!pindex_next) {
|
m_synced = true;
|
||||||
SetBestBlockIndex(pindex);
|
// No need to handle errors in Commit. See rationale above.
|
||||||
m_synced = true;
|
Commit();
|
||||||
// No need to handle errors in Commit. See rationale above.
|
break;
|
||||||
Commit();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (pindex_next->pprev != pindex && !Rewind(pindex, pindex_next->pprev)) {
|
|
||||||
FatalErrorf("%s: Failed to rewind index %s to a previous chain tip",
|
|
||||||
__func__, GetName());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
pindex = pindex_next;
|
|
||||||
}
|
}
|
||||||
|
if (pindex_next->pprev != pindex && !Rewind(pindex, pindex_next->pprev)) {
|
||||||
|
FatalErrorf("%s: Failed to rewind index %s to a previous chain tip", __func__, GetName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pindex = pindex_next;
|
||||||
|
|
||||||
|
|
||||||
auto current_time{std::chrono::steady_clock::now()};
|
auto current_time{std::chrono::steady_clock::now()};
|
||||||
if (last_log_time + SYNC_LOG_INTERVAL < current_time) {
|
if (last_log_time + SYNC_LOG_INTERVAL < current_time) {
|
||||||
|
|
Loading…
Reference in New Issue