Skip to content

Commit

Permalink
handle read error on iterating sortdb
Browse files Browse the repository at this point in the history
  • Loading branch information
ban-nobuhiro committed Jul 23, 2024
1 parent dd126b7 commit f72c67e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/limestone/sortdb_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,16 @@ class sortdb_wrapper {
}

void each(const std::function<void(std::string_view, std::string_view)>& fun) {
Iterator* it = sortdb_->NewIterator(ReadOptions()); // NOLINT (typical usage of API)
std::unique_ptr<Iterator> 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:
Expand Down

0 comments on commit f72c67e

Please sign in to comment.