changed sync requirement, use hash_bytes

This commit is contained in:
Brannon King 2020-03-03 11:35:25 -07:00
parent 80237390ff
commit a050ee1e61
7 changed files with 13 additions and 10 deletions

View file

@ -105,14 +105,15 @@ namespace sqlite
return code;
}
inline int sync(database& db, std::size_t attempts = 200)
inline int sync(database& db, std::size_t attempts = 20)
{
int code = SQLITE_OK;
for (auto i = 0u; i < attempts; ++i) {
code = sqlite3_wal_checkpoint_v2(db.connection().get(), nullptr, SQLITE_CHECKPOINT_FULL, nullptr, nullptr);
if (code != SQLITE_OK) {
sqlite3_wal_checkpoint_v2(db.connection().get(), nullptr, SQLITE_CHECKPOINT_PASSIVE, nullptr, nullptr);
using namespace std::chrono_literals;
std::this_thread::sleep_for(100ms);
std::this_thread::sleep_for(200ms);
continue;
}
break;

View file

@ -5,6 +5,8 @@
#include <blob.h>
#include <string>
#include <primitives/robin_hood.h>
class uint160 : public CBaseBlob<160>
{
public:
@ -47,7 +49,7 @@ namespace std {
{
size_t operator()(const uint160& k) const
{
return *reinterpret_cast<const size_t*>(k.begin());
return robin_hood::hash_bytes(k.begin(), k.size());
}
};
@ -56,7 +58,7 @@ namespace std {
{
size_t operator()(const uint256& k) const
{
return *reinterpret_cast<const size_t*>(k.begin());
return robin_hood::hash_bytes(k.begin(), k.size());
}
};
}

View file

@ -42,7 +42,7 @@ namespace std {
{
size_t operator()(const CKeyID& k) const
{
return *reinterpret_cast<const size_t*>(k.begin());
return robin_hood::hash_bytes(k.begin(), k.size());
}
};
}

View file

@ -33,7 +33,7 @@ namespace std {
{
size_t operator()(const CScriptID& k) const
{
return *reinterpret_cast<const size_t*>(k.begin());
return robin_hood::hash_bytes(k.begin(), k.size());
}
};
}

View file

@ -148,7 +148,7 @@ bool CCoinsViewDB::BatchWrite(const CCoinsMap &mapCoins, const uint256 &hashBloc
code = sqlite::sync(db);
if (code != SQLITE_OK) {
LogPrintf("%s: Error syncing coin database. SQLite error: %d\n", __func__, code);
return false;
// don't return false as it may happen if someone else is reading our DB
}
}
return true;
@ -338,7 +338,7 @@ bool CBlockTreeDB::BatchWrite(const std::vector<std::pair<int, const CBlockFileI
code = sqlite::sync(db);
if (code != SQLITE_OK) {
LogPrintf("%s: Error syncing block database. SQLite error: %d\n", __func__, code);
return false;
// don't return false here as this may happen if someone else is reading our DB
}
}
return true;

View file

@ -2206,7 +2206,7 @@ bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &
if (!CheckDiskSpace(48 * 2 * 2 * pcoinsTip->GetCacheSize()))
return state.Error("out of disk space");
if (syncToDisk && !pclaimTrie->SyncToDisk())
return state.Error("Failed to write to claim trie database");
LogPrintf("Failed to sync claim trie database to disk");
// Flush the chainstate (which may refer to block index entries).
if (!pcoinsTip->Flush(syncToDisk))
return AbortNode(state, "Failed to write to coin database");

View file

@ -148,7 +148,7 @@ extern std::atomic_bool g_is_mempool_loaded;
struct BlockMapHasher {
std::size_t operator()(const CBlockIndex* block) const {
return *reinterpret_cast<const std::size_t*>(block->hash.begin());
return robin_hood::hash_bytes(block->hash.begin(), block->hash.size());
}
};