Skip to content

Commit

Permalink
journal: simplify object recorder locker aggregation
Browse files Browse the repository at this point in the history
Use move semantics and RAII to control the locking of the
per-object recorder lock.

Signed-off-by: Jason Dillaman <[email protected]>
  • Loading branch information
Jason Dillaman committed Nov 19, 2019
1 parent b35926e commit 5a5b5c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
15 changes: 11 additions & 4 deletions src/journal/JournalRecorder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ void JournalRecorder::open_object_set() {

uint8_t splay_width = m_journal_metadata->get_splay_width();

lock_object_recorders();
auto lockers{lock_object_recorders()};
for (const auto& p : m_object_ptrs) {
const auto& object_recorder = p.second;
uint64_t object_number = object_recorder->get_object_number();
Expand All @@ -270,7 +270,6 @@ void JournalRecorder::open_object_set() {
create_next_object_recorder(object_recorder);
}
}
unlock_object_recorders();
}

bool JournalRecorder::close_object_set(uint64_t active_set) {
Expand All @@ -280,7 +279,7 @@ bool JournalRecorder::close_object_set(uint64_t active_set) {
// object recorders will invoke overflow handler as they complete
// closing the object to ensure correct order of future appends
uint8_t splay_width = m_journal_metadata->get_splay_width();
lock_object_recorders();
auto lockers{lock_object_recorders()};
for (const auto& p : m_object_ptrs) {
const auto& object_recorder = p.second;
if (object_recorder->get_object_number() / splay_width != active_set) {
Expand All @@ -295,7 +294,6 @@ bool JournalRecorder::close_object_set(uint64_t active_set) {
}
}
}
unlock_object_recorders();
return (m_in_flight_object_closes == 0);
}

Expand Down Expand Up @@ -406,4 +404,13 @@ void JournalRecorder::handle_overflow(ObjectRecorder *object_recorder) {
close_and_advance_object_set(object_number / splay_width);
}

JournalRecorder::Lockers JournalRecorder::lock_object_recorders() {
Lockers lockers;
lockers.reserve(m_object_ptrs.size());
for (auto& lock : m_object_locks) {
lockers.emplace_back(lock);
}
return lockers;
}

} // namespace journal
13 changes: 2 additions & 11 deletions src/journal/JournalRecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class JournalRecorder {

private:
typedef std::map<uint8_t, ceph::ref_t<ObjectRecorder>> ObjectRecorderPtrs;
typedef std::vector<std::unique_lock<ceph::mutex>> Lockers;

struct Listener : public JournalMetadataListener {
JournalRecorder *journal_recorder;
Expand Down Expand Up @@ -120,17 +121,7 @@ class JournalRecorder {
void handle_closed(ObjectRecorder *object_recorder);
void handle_overflow(ObjectRecorder *object_recorder);

void lock_object_recorders() {
for (auto& lock : m_object_locks) {
lock.lock();
}
}

void unlock_object_recorders() {
for (auto& lock : m_object_locks) {
lock.unlock();
}
}
Lockers lock_object_recorders();
};

} // namespace journal
Expand Down

0 comments on commit 5a5b5c5

Please sign in to comment.