Skip to content

Commit 4bc664b

Browse files
committed
EH: CS-315 make sure that the accounting and reporting code is thread safe
1 parent 9a4c34f commit 4bc664b

File tree

6 files changed

+104
-34
lines changed

6 files changed

+104
-34
lines changed

source/daemons/qmaster/ocs_JsonAccountingFileWriter.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,19 @@ namespace ocs {
4646
// get accounting data
4747
rapidjson::StringBuffer json_buffer;
4848
rapidjson::Writer<rapidjson::StringBuffer> writer(json_buffer);
49-
ret = sge_write_rusage(nullptr, &writer, job_report, job, ja_task, category_string,
50-
&usage_pattern_list, 0, false, false);
49+
50+
// we need to protect the usage_pattern_list via the config_mutex
51+
sge_mutex_lock(config_mutex_name.c_str(), __func__, __LINE__, &config_mutex);
52+
ret = sge_write_rusage(nullptr, &writer, job_report, job, ja_task, category_string, &usage_pattern_list, 0,
53+
false, false);
54+
sge_mutex_unlock(config_mutex_name.c_str(), __func__, __LINE__, &config_mutex);
5155

5256
if (ret) {
5357
// append data to buffer
5458
json_buffer.Put('\n');
55-
sge_mutex_lock(typeid(*this).name(), __func__, __LINE__, &mutex);
59+
sge_mutex_lock(typeid(*this).name(), __func__, __LINE__, &buffer_mutex);
5660
buffer += json_buffer.GetString();
57-
sge_mutex_unlock(typeid(*this).name(), __func__, __LINE__, &mutex);
61+
sge_mutex_unlock(typeid(*this).name(), __func__, __LINE__, &buffer_mutex);
5862

5963
// If immediate flushing is enabled, flush the buffer now
6064
if (accounting_immediate_flush) {
@@ -66,4 +70,3 @@ namespace ocs {
6670
DRETURN(ret);
6771
}
6872
}
69-

source/daemons/qmaster/ocs_JsonReportingFileWriter.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,19 @@ namespace ocs {
5858
// get accounting data
5959
rapidjson::StringBuffer json_buffer;
6060
rapidjson::Writer<rapidjson::StringBuffer> writer(json_buffer);
61-
bool ret = sge_write_rusage(nullptr, &writer, job_report, job, ja_task, category_string,
62-
&usage_pattern_list, 0, false, true);
61+
62+
// we need to protect the usage_pattern_list via the config_mutex
63+
sge_mutex_lock(config_mutex_name.c_str(), __func__, __LINE__, &config_mutex);
64+
bool ret = sge_write_rusage(nullptr, &writer, job_report, job, ja_task, category_string, &usage_pattern_list, 0,
65+
false, true);
66+
sge_mutex_unlock(config_mutex_name.c_str(), __func__, __LINE__, &config_mutex);
67+
6368
if (ret) {
6469
// append data to buffer
6570
json_buffer.Put('\n');
66-
sge_mutex_lock(typeid(*this).name(), __func__, __LINE__, &mutex);
71+
sge_mutex_lock(typeid(*this).name(), __func__, __LINE__, &buffer_mutex);
6772
buffer += json_buffer.GetString();
68-
sge_mutex_unlock(typeid(*this).name(), __func__, __LINE__, &mutex);
73+
sge_mutex_unlock(typeid(*this).name(), __func__, __LINE__, &buffer_mutex);
6974
}
7075

7176
DRETURN(ret);
@@ -75,9 +80,9 @@ namespace ocs {
7580
JsonReportingFileWriter::create_record(rapidjson::StringBuffer &stringBuffer) {
7681
stringBuffer.Put('\n');
7782

78-
sge_mutex_lock(typeid(*this).name(), __func__, __LINE__, &mutex);
83+
sge_mutex_lock(typeid(*this).name(), __func__, __LINE__, &buffer_mutex);
7984
buffer += stringBuffer.GetString();
80-
sge_mutex_unlock(typeid(*this).name(), __func__, __LINE__, &mutex);
85+
sge_mutex_unlock(typeid(*this).name(), __func__, __LINE__, &buffer_mutex);
8186
}
8287

8388
bool

source/daemons/qmaster/ocs_MonitoringFileWriter.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ namespace ocs {
4040
DENTER(TOP_LAYER);
4141

4242
// append data to buffer
43-
sge_mutex_lock(typeid(*this).name(), __func__, __LINE__, &mutex);
43+
sge_mutex_lock(typeid(*this).name(), __func__, __LINE__, &buffer_mutex);
4444
this->buffer += json_data;
4545
this->buffer += "\n";
46-
sge_mutex_unlock(typeid(*this).name(), __func__, __LINE__, &mutex);
46+
sge_mutex_unlock(typeid(*this).name(), __func__, __LINE__, &buffer_mutex);
4747

4848
DRETURN(true);
4949
}

0 commit comments

Comments
 (0)