diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2014-11-25 16:26:20 +0100 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2014-11-25 16:26:35 +0100 |
commit | 63d1ae5556ea40dde0cca20addda4bba40005496 (patch) | |
tree | 84300b58849b139c71381704d54f640ffff694f7 /src/main.cpp | |
parent | ac0b2393a447bb20f8b0489a67237c98a1cfff4a (diff) | |
download | bitcoin-63d1ae5556ea40dde0cca20addda4bba40005496.tar.xz |
Do all block index writes in a batch
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/src/main.cpp b/src/main.cpp index 88fb31980f..832d7747f8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1784,24 +1784,23 @@ bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode) { // First make sure all block and undo data is flushed to disk. FlushBlockFile(); // Then update all block file information (which may refer to block and undo files). - bool fileschanged = false; - for (set<int>::iterator it = setDirtyFileInfo.begin(); it != setDirtyFileInfo.end(); ) { - if (!pblocktree->WriteBlockFileInfo(*it, vinfoBlockFile[*it])) { - return state.Abort("Failed to write to block index"); + { + std::vector<std::pair<int, const CBlockFileInfo*> > vFiles; + vFiles.reserve(setDirtyFileInfo.size()); + for (set<int>::iterator it = setDirtyFileInfo.begin(); it != setDirtyFileInfo.end(); ) { + vFiles.push_back(make_pair(*it, &vinfoBlockFile[*it])); + setDirtyFileInfo.erase(it++); + } + std::vector<const CBlockIndex*> vBlocks; + vBlocks.reserve(setDirtyBlockIndex.size()); + for (set<CBlockIndex*>::iterator it = setDirtyBlockIndex.begin(); it != setDirtyBlockIndex.end(); ) { + vBlocks.push_back(*it); + setDirtyBlockIndex.erase(it++); + } + if (!pblocktree->WriteBatchSync(vFiles, nLastBlockFile, vBlocks)) { + return state.Abort("Files to write to block index database"); } - fileschanged = true; - setDirtyFileInfo.erase(it++); - } - if (fileschanged && !pblocktree->WriteLastBlockFile(nLastBlockFile)) { - return state.Abort("Failed to write to block index"); - } - for (set<CBlockIndex*>::iterator it = setDirtyBlockIndex.begin(); it != setDirtyBlockIndex.end(); ) { - if (!pblocktree->WriteBlockIndex(CDiskBlockIndex(*it))) { - return state.Abort("Failed to write to block index"); - } - setDirtyBlockIndex.erase(it++); } - pblocktree->Sync(); // Finally flush the chainstate (which may refer to block index entries). if (!pcoinsTip->Flush()) return state.Abort("Failed to write to coin database"); |