|
|
@@ -1120,7 +1120,7 @@ uint64_t DatabaseService::repairStaleResidentRows() {
|
|
|
}
|
|
|
namespace sd = smartbotic::database;
|
|
|
const auto started = std::chrono::steady_clock::now();
|
|
|
- uint64_t checked = 0, reloaded = 0, failed = 0, memNewerTotal = 0;
|
|
|
+ uint64_t checked = 0, reloaded = 0, failed = 0, memNewerTotal = 0, memNewerWritten = 0;
|
|
|
constexpr size_t kBatch = 256;
|
|
|
|
|
|
for (const auto& name : store_->listCollections()) {
|
|
|
@@ -1175,12 +1175,27 @@ uint64_t DatabaseService::repairStaleResidentRows() {
|
|
|
}
|
|
|
if (!memNewer.empty()) {
|
|
|
// An old LMDB copy that missed a write (a mirror failure before
|
|
|
- // 2.21.0 recorded them): memory holds the later write. Left as it
|
|
|
- // is; reads have been showing LMDB's older copy, and the next
|
|
|
- // write to the row mirrors memory's version over it.
|
|
|
+ // 2.21.0 recorded them): memory holds the later write. By default
|
|
|
+ // left as it is; reads have been showing LMDB's older copy, and
|
|
|
+ // the next write to the row mirrors memory's version over it.
|
|
|
+ // v2.21.7 - `memory_newer: write` copies memory's version to LMDB
|
|
|
+ // now. Opt-in: it makes a write nobody has looked at the one
|
|
|
+ // every read returns.
|
|
|
memNewerTotal += memNewer.size();
|
|
|
- spdlog::warn("version audit: {}: {} resident row(s) are NEWER than LMDB's copy, "
|
|
|
- "left in memory (e.g. {})", name, memNewer.size(), memDetail);
|
|
|
+ if (config_.consistencyMemoryNewer == "write") {
|
|
|
+ std::vector<std::pair<std::string, std::string>> rows;
|
|
|
+ for (const auto& id : memNewer) rows.emplace_back(name, id);
|
|
|
+ const auto r = store_->syncDocStoreFromMemory(rows);
|
|
|
+ memNewerWritten += r.written;
|
|
|
+ failed += r.failed.size();
|
|
|
+ spdlog::warn("version audit: {}: {} resident row(s) are NEWER than LMDB's copy, "
|
|
|
+ "{} written to LMDB (memory_newer=write; e.g. {})",
|
|
|
+ name, memNewer.size(), r.written, memDetail);
|
|
|
+ } else {
|
|
|
+ spdlog::warn("version audit: {}: {} resident row(s) are NEWER than LMDB's copy, "
|
|
|
+ "left in memory (memory_newer=report; e.g. {})",
|
|
|
+ name, memNewer.size(), memDetail);
|
|
|
+ }
|
|
|
}
|
|
|
if (stale.empty()) continue;
|
|
|
|
|
|
@@ -1208,8 +1223,9 @@ uint64_t DatabaseService::repairStaleResidentRows() {
|
|
|
std::chrono::steady_clock::now() - started).count();
|
|
|
if (reloaded > 0 || failed > 0 || memNewerTotal > 0) {
|
|
|
spdlog::warn("version audit: {} resident row(s) checked, {} reloaded from LMDB, "
|
|
|
- "{} newer in memory (left), {} failed ({} ms)",
|
|
|
- checked, reloaded, memNewerTotal, failed, ms);
|
|
|
+ "{} newer in memory ({} written to LMDB, {} left), {} failed ({} ms)",
|
|
|
+ checked, reloaded, memNewerTotal, memNewerWritten,
|
|
|
+ memNewerTotal - memNewerWritten, failed, ms);
|
|
|
} else {
|
|
|
spdlog::info("version audit: {} resident row(s) agree with LMDB ({} ms)", checked, ms);
|
|
|
}
|
|
|
@@ -1709,6 +1725,12 @@ DatabaseService::Config DatabaseService::parseConfig(const nlohmann::json& json)
|
|
|
const auto& c = db["consistency"];
|
|
|
config.consistencyDiskOnly = c.value("disk_only", config.consistencyDiskOnly);
|
|
|
config.consistencyMemoryOnly = c.value("memory_only", config.consistencyMemoryOnly);
|
|
|
+ config.consistencyMemoryNewer = c.value("memory_newer", config.consistencyMemoryNewer);
|
|
|
+ }
|
|
|
+ if (config.consistencyMemoryNewer != "report" && config.consistencyMemoryNewer != "write") {
|
|
|
+ spdlog::error("storage.consistency.memory_newer '{}' is not report|write; using report",
|
|
|
+ config.consistencyMemoryNewer);
|
|
|
+ config.consistencyMemoryNewer = "report";
|
|
|
}
|
|
|
if (config.consistencyDiskOnly != "adopt" && config.consistencyDiskOnly != "report" &&
|
|
|
config.consistencyDiskOnly != "remove") {
|