Merge pull request #29946 from azat/log-fix-data-race

Fix data-race between LogSink::writeMarks() and LogSource in StorageLog
This commit is contained in:
alexey-milovidov 2021-10-15 01:30:58 +03:00 committed by GitHub
commit bc1662b9fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -183,7 +183,10 @@ void LogSource::readData(const NameAndTypePair & name_and_type, ColumnPtr & colu
UInt64 offset = 0;
if (!stream_for_prefix && mark_number)
{
std::lock_guard marks_lock(file_it->second.marks_mutex);
offset = file_it->second.marks[mark_number].offset;
}
auto & data_file_path = file_it->second.data_file_path;
auto it = streams.try_emplace(stream_name, storage.disk, data_file_path, offset, read_settings).first;
@ -457,7 +460,10 @@ void LogSink::writeMarks(MarksForColumns && marks)
writeIntBinary(mark.second.offset, *marks_stream);
size_t column_index = mark.first;
storage.files[storage.column_names_by_idx[column_index]].marks.push_back(mark.second);
auto & file = storage.files[storage.column_names_by_idx[column_index]];
std::lock_guard marks_lock(file.marks_mutex);
file.marks.push_back(mark.second);
}
}

View File

@ -82,6 +82,8 @@ private:
size_t column_index;
String data_file_path;
std::mutex marks_mutex;
Marks marks;
};
using Files = std::map<String, ColumnData>; /// file name -> column data