Skip to content

Commit

Permalink
rgw: remove unnecessary OpsLogFile::flush_mutex
Browse files Browse the repository at this point in the history
this mutex was only held by one function, OpsLogFile::flush(). this
private member function is only ever called from the background thread,
so doesn't need to be protected by a mutex

as a further cleanup, i renamed 'cond' and 'mutex' now that we don't
need to differentiate between different locks

Signed-off-by: Casey Bodley <[email protected]>
  • Loading branch information
cbodley committed Apr 25, 2022
1 parent cf6f99e commit 279d664
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
15 changes: 7 additions & 8 deletions src/rgw/rgw_log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,8 @@ void OpsLogFile::reopen() {

void OpsLogFile::flush()
{
std::scoped_lock flush_lock(flush_mutex);
{
std::scoped_lock log_lock(log_mutex);
std::scoped_lock log_lock(mutex);
assert(flush_buffer.empty());
flush_buffer.swap(log_buffer);
data_size = 0;
Expand Down Expand Up @@ -389,15 +388,15 @@ void OpsLogFile::flush()
}

void* OpsLogFile::entry() {
std::unique_lock lock(log_mutex);
std::unique_lock lock(mutex);
while (!stopped) {
if (!log_buffer.empty()) {
lock.unlock();
flush();
lock.lock();
continue;
}
cond_flush.wait(lock);
cond.wait(lock);
}
flush();
return NULL;
Expand All @@ -410,8 +409,8 @@ void OpsLogFile::start() {

void OpsLogFile::stop() {
{
std::unique_lock lock(log_mutex);
cond_flush.notify_one();
std::unique_lock lock(mutex);
cond.notify_one();
stopped = true;
}
join();
Expand All @@ -427,14 +426,14 @@ OpsLogFile::~OpsLogFile()

int OpsLogFile::log_json(struct req_state* s, bufferlist& bl)
{
std::unique_lock lock(log_mutex);
std::unique_lock lock(mutex);
if (data_size + bl.length() >= max_data_size) {
ldout(s->cct, 0) << "ERROR: RGW ops log file buffer too full, dropping log for txn: " << s->trans_id << dendl;
return -1;
}
log_buffer.push_back(bl);
data_size += bl.length();
cond_flush.notify_all();
cond.notify_all();
return 0;
}

Expand Down
5 changes: 2 additions & 3 deletions src/rgw/rgw_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,10 @@ class JsonOpsLogSink : public OpsLogSink {

class OpsLogFile : public JsonOpsLogSink, public Thread, public DoutPrefixProvider {
CephContext* cct;
ceph::mutex log_mutex = ceph::make_mutex("OpsLogFile_log");
ceph::mutex flush_mutex = ceph::make_mutex("OpsLogFile_flush");
ceph::mutex mutex = ceph::make_mutex("OpsLogFile");
std::vector<bufferlist> log_buffer;
std::vector<bufferlist> flush_buffer;
ceph::condition_variable cond_flush;
ceph::condition_variable cond;
std::ofstream file;
bool stopped;
uint64_t data_size;
Expand Down

0 comments on commit 279d664

Please sign in to comment.