Changeset View
Changeset View
Standalone View
Standalone View
src/txdb.cpp
Show First 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) { | ||||
if (batch.SizeEstimate() > batch_size) { | if (batch.SizeEstimate() > batch_size) { | ||||
LogPrint(BCLog::COINDB, "Writing partial batch of %.2f MiB\n", | LogPrint(BCLog::COINDB, "Writing partial batch of %.2f MiB\n", | ||||
batch.SizeEstimate() * (1.0 / 1048576.0)); | batch.SizeEstimate() * (1.0 / 1048576.0)); | ||||
db.WriteBatch(batch); | db.WriteBatch(batch); | ||||
batch.Clear(); | batch.Clear(); | ||||
if (crash_simulate) { | if (crash_simulate) { | ||||
static FastRandomContext rng; | static FastRandomContext rng; | ||||
if (rng.randrange(crash_simulate) == 0) { | if (rng.randrange(crash_simulate) == 0) { | ||||
LogPrintf("Simulating a crash. Goodbye.\n"); | LogPrint(BCLog::COINDB, "Simulating a crash. Goodbye.\n"); | ||||
_Exit(0); | _Exit(0); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// In the last batch, mark the database as consistent with hashBlock again. | // In the last batch, mark the database as consistent with hashBlock again. | ||||
batch.Erase(DB_HEAD_BLOCKS); | batch.Erase(DB_HEAD_BLOCKS); | ||||
▲ Show 20 Lines • Show All 244 Lines • ▼ Show 20 Lines | |||||
bool CCoinsViewDB::Upgrade() { | bool CCoinsViewDB::Upgrade() { | ||||
std::unique_ptr<CDBIterator> pcursor(db.NewIterator()); | std::unique_ptr<CDBIterator> pcursor(db.NewIterator()); | ||||
pcursor->Seek(std::make_pair(DB_COINS, uint256())); | pcursor->Seek(std::make_pair(DB_COINS, uint256())); | ||||
if (!pcursor->Valid()) { | if (!pcursor->Valid()) { | ||||
return true; | return true; | ||||
} | } | ||||
int64_t count = 0; | int64_t count = 0; | ||||
LogPrintf("Upgrading utxo-set database...\n"); | LogPrint(BCLog::COINDB, "Upgrading utxo-set database...\n"); | ||||
LogPrintf("[0%%]..."); | LogPrint(BCLog::COINDB, "[0%%]..."); | ||||
size_t batch_size = 1 << 24; | size_t batch_size = 1 << 24; | ||||
CDBBatch batch(db); | CDBBatch batch(db); | ||||
uiInterface.SetProgressBreakAction(StartShutdown); | uiInterface.SetProgressBreakAction(StartShutdown); | ||||
int reportDone = 0; | int reportDone = 0; | ||||
std::pair<uint8_t, uint256> key; | std::pair<uint8_t, uint256> key; | ||||
std::pair<uint8_t, uint256> prev_key = {DB_COINS, uint256()}; | std::pair<uint8_t, uint256> prev_key = {DB_COINS, uint256()}; | ||||
while (pcursor->Valid()) { | while (pcursor->Valid()) { | ||||
boost::this_thread::interruption_point(); | boost::this_thread::interruption_point(); | ||||
Show All 10 Lines | while (pcursor->Valid()) { | ||||
0x100 * *key.second.begin() + *(key.second.begin() + 1); | 0x100 * *key.second.begin() + *(key.second.begin() + 1); | ||||
int percentageDone = (int)(high * 100.0 / 65536.0 + 0.5); | int percentageDone = (int)(high * 100.0 / 65536.0 + 0.5); | ||||
uiInterface.ShowProgress( | uiInterface.ShowProgress( | ||||
_("Upgrading UTXO database") + "\n" + | _("Upgrading UTXO database") + "\n" + | ||||
_("(press q to shutdown and continue later)") + "\n", | _("(press q to shutdown and continue later)") + "\n", | ||||
percentageDone); | percentageDone); | ||||
if (reportDone < percentageDone / 10) { | if (reportDone < percentageDone / 10) { | ||||
// report max. every 10% step | // report max. every 10% step | ||||
LogPrintf("[%d%%]...", percentageDone); | LogPrint(BCLog::COINDB, "[%d%%]...", percentageDone); | ||||
reportDone = percentageDone / 10; | reportDone = percentageDone / 10; | ||||
} | } | ||||
} | } | ||||
CCoins old_coins; | CCoins old_coins; | ||||
if (!pcursor->GetValue(old_coins)) { | if (!pcursor->GetValue(old_coins)) { | ||||
return error("%s: cannot parse CCoins record", __func__); | return error("%s: cannot parse CCoins record", __func__); | ||||
} | } | ||||
Show All 19 Lines | while (pcursor->Valid()) { | ||||
} | } | ||||
pcursor->Next(); | pcursor->Next(); | ||||
} | } | ||||
db.WriteBatch(batch); | db.WriteBatch(batch); | ||||
db.CompactRange({DB_COINS, uint256()}, key); | db.CompactRange({DB_COINS, uint256()}, key); | ||||
uiInterface.SetProgressBreakAction(std::function<void(void)>()); | uiInterface.SetProgressBreakAction(std::function<void(void)>()); | ||||
LogPrintf("[%s].\n", ShutdownRequested() ? "CANCELLED" : "DONE"); | LogPrint(BCLog::COINDB, "[%s].\n", | ||||
ShutdownRequested() ? "CANCELLED" : "DONE"); | |||||
return !ShutdownRequested(); | return !ShutdownRequested(); | ||||
} | } |