| 45 | }; |
| 46 | |
| 47 | void OverlayDB::commit() |
| 48 | { |
| 49 | if (m_db) |
| 50 | { |
| 51 | ldb::WriteBatch batch; |
| 52 | // cnote << "Committing nodes to disk DB:"; |
| 53 | #if DEV_GUARDED_DB |
| 54 | DEV_READ_GUARDED(x_this) |
| 55 | #endif |
| 56 | { |
| 57 | for (auto const& i: m_main) |
| 58 | { |
| 59 | if (i.second.second) |
| 60 | batch.Put(ldb::Slice((char const*)i.first.data(), i.first.size), ldb::Slice(i.second.first.data(), i.second.first.size())); |
| 61 | // cnote << i.first << "#" << m_main[i.first].second; |
| 62 | } |
| 63 | for (auto const& i: m_aux) |
| 64 | if (i.second.second) |
| 65 | { |
| 66 | bytes b = i.first.asBytes(); |
| 67 | b.push_back(255); // for aux |
| 68 | batch.Put(bytesConstRef(&b), bytesConstRef(&i.second.first)); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | for (unsigned i = 0; i < 10; ++i) |
| 73 | { |
| 74 | ldb::Status o = m_db->Write(m_writeOptions, &batch); |
| 75 | if (o.ok()) |
| 76 | break; |
| 77 | if (i == 9) |
| 78 | { |
| 79 | cwarn << "Fail writing to state database. Bombing out."; |
| 80 | exit(-1); |
| 81 | } |
| 82 | cwarn << "Error writing to state database: " << o.ToString(); |
| 83 | WriteBatchNoter n; |
| 84 | batch.Iterate(&n); |
| 85 | cwarn << "Sleeping for" << (i + 1) << "seconds, then retrying."; |
| 86 | this_thread::sleep_for(chrono::seconds(i + 1)); |
| 87 | } |
| 88 | #if DEV_GUARDED_DB |
| 89 | DEV_WRITE_GUARDED(x_this) |
| 90 | #endif |
| 91 | { |
| 92 | m_aux.clear(); |
| 93 | m_main.clear(); |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | bytes OverlayDB::lookupAux(h256 const& _h) const |
| 99 | { |
nothing calls this directly
no test coverage detected