Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/memtable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ class Memtable {
void remove(const std::string &key);
void clear();

[[nodiscard]] auto begin() const {
std::shared_lock lock(mutex_);
return data_.begin();
}
[[nodiscard]] auto end() const {
std::shared_lock lock(mutex_);
return data_.end();
}
// Iteration is NOT internally synchronised. The previous version took a
// shared_lock here but released it at function return, leaving the
// returned iterator unprotected against concurrent writers - the lock
// was guarding nothing. Callers must externally exclude writers for the
// iteration's lifetime (e.g. Engine::flush_if_full holds write_mutex_
// while iterating to write an SSTable). For callers without an
// exclusion guarantee, use snapshot() instead.
[[nodiscard]] auto begin() const { return data_.begin(); }
[[nodiscard]] auto end() const { return data_.end(); }
[[nodiscard]] std::size_t size() const {
std::shared_lock lock(mutex_);
return data_.size();
Expand Down
Loading