From f72c67e82c03fe628ffb5adb2bb67abde24c5011 Mon Sep 17 00:00:00 2001 From: Nobuhiro Ban Date: Tue, 23 Jul 2024 22:04:42 +0900 Subject: [PATCH] handle read error on iterating sortdb --- src/limestone/sortdb_wrapper.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/limestone/sortdb_wrapper.h b/src/limestone/sortdb_wrapper.h index ceb7d82d..87b06854 100644 --- a/src/limestone/sortdb_wrapper.h +++ b/src/limestone/sortdb_wrapper.h @@ -90,13 +90,16 @@ class sortdb_wrapper { } void each(const std::function& fun) { - Iterator* it = sortdb_->NewIterator(ReadOptions()); // NOLINT (typical usage of API) + std::unique_ptr it{sortdb_->NewIterator(ReadOptions())}; for (it->SeekToFirst(); it->Valid(); it->Next()) { Slice key = it->key(); Slice value = it->value(); fun(std::string_view(key.data(), key.size()), std::string_view(value.data(), value.size())); } - delete it; // NOLINT (typical usage of API) + if (!it->status().ok()) { + LOG_LP(ERROR) << "sortdb iterator invalidated, status: " << it->status().ToString(); + throw std::runtime_error("error in sortdb read iteration"); + } } private: