From ba33fbbf1d026c5b3d312ba3b7ed6cbc61c24fd1 Mon Sep 17 00:00:00 2001 From: zhangxiao871 Date: Wed, 15 Sep 2021 01:14:14 +0800 Subject: [PATCH] add the last logfile that is less than the zxid. --- src/Coordination/ZooKeeperDataReader.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Coordination/ZooKeeperDataReader.cpp b/src/Coordination/ZooKeeperDataReader.cpp index cf644110786..2295109a236 100644 --- a/src/Coordination/ZooKeeperDataReader.cpp +++ b/src/Coordination/ZooKeeperDataReader.cpp @@ -572,12 +572,24 @@ void deserializeLogsAndApplyToStorage(KeeperStorage & storage, const std::string LOG_INFO(log, "Totally have {} logs", existing_logs.size()); - for (auto [zxid, log_path] : existing_logs) + std::vector stored_files; + for (auto it = existing_logs.rbegin(); it != existing_logs.rend(); ++it) { - if (zxid > storage.zxid) - deserializeLogAndApplyToStorage(storage, log_path, log); - else - LOG_INFO(log, "Skipping log {}, it's ZXID {} is smaller than storages ZXID {}", log_path, zxid, storage.zxid); + if (it->first >= storage.zxid) + { + stored_files.emplace_back(it->second); + } + else if (it->first < storage.zxid) + { + /// add the last logfile that is less than the zxid + stored_files.emplace_back(it->second); + break; + } + } + + for (auto & log_path : stored_files) + { + deserializeLogAndApplyToStorage(storage, log_path, log); } }