mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 00:30:49 +00:00
Merge pull request #60139 from ClickHouse/revert-60093-lazy-primary-key-loading
Fix data race in `IMergeTreeDataPart`
This commit is contained in:
commit
b216223aa0
@ -347,7 +347,7 @@ const IMergeTreeDataPart::Index & IMergeTreeDataPart::getIndex() const
|
||||
{
|
||||
std::scoped_lock lock(index_mutex);
|
||||
if (!index_loaded)
|
||||
loadIndex(lock);
|
||||
loadIndex();
|
||||
index_loaded = true;
|
||||
return index;
|
||||
}
|
||||
@ -569,6 +569,7 @@ void IMergeTreeDataPart::removeIfNeeded()
|
||||
|
||||
UInt64 IMergeTreeDataPart::getIndexSizeInBytes() const
|
||||
{
|
||||
std::scoped_lock lock(index_mutex);
|
||||
UInt64 res = 0;
|
||||
for (const ColumnPtr & column : index)
|
||||
res += column->byteSize();
|
||||
@ -577,6 +578,7 @@ UInt64 IMergeTreeDataPart::getIndexSizeInBytes() const
|
||||
|
||||
UInt64 IMergeTreeDataPart::getIndexSizeInAllocatedBytes() const
|
||||
{
|
||||
std::scoped_lock lock(index_mutex);
|
||||
UInt64 res = 0;
|
||||
for (const ColumnPtr & column : index)
|
||||
res += column->allocatedBytes();
|
||||
@ -828,7 +830,7 @@ void IMergeTreeDataPart::appendFilesOfIndexGranularity(Strings & /* files */) co
|
||||
{
|
||||
}
|
||||
|
||||
void IMergeTreeDataPart::loadIndex(std::scoped_lock<std::mutex> &) const
|
||||
void IMergeTreeDataPart::loadIndex() const
|
||||
{
|
||||
/// Memory for index must not be accounted as memory usage for query, because it belongs to a table.
|
||||
MemoryTrackerBlockerInThread temporarily_disable_memory_tracker;
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <IO/WriteSettings.h>
|
||||
#include <Core/Block.h>
|
||||
#include <base/types.h>
|
||||
#include <base/defines.h>
|
||||
#include <Core/NamesAndTypes.h>
|
||||
#include <Storages/IStorage.h>
|
||||
#include <Storages/LightweightDeleteDescription.h>
|
||||
@ -565,8 +566,8 @@ protected:
|
||||
/// Lazily loaded in RAM. Contains each index_granularity-th value of primary key tuple.
|
||||
/// Note that marks (also correspond to primary key) are not always in RAM, but cached. See MarkCache.h.
|
||||
mutable std::mutex index_mutex;
|
||||
mutable Index index;
|
||||
mutable bool index_loaded = false;
|
||||
mutable Index index TSA_GUARDED_BY(index_mutex);
|
||||
mutable bool index_loaded TSA_GUARDED_BY(index_mutex) = false;
|
||||
|
||||
/// Total size of all columns, calculated once in calcuateColumnSizesOnDisk
|
||||
ColumnSize total_columns_size;
|
||||
@ -664,7 +665,7 @@ private:
|
||||
virtual void appendFilesOfIndexGranularity(Strings & files) const;
|
||||
|
||||
/// Loads the index file.
|
||||
void loadIndex(std::scoped_lock<std::mutex> &) const;
|
||||
void loadIndex() const TSA_REQUIRES(index_mutex);
|
||||
|
||||
void appendFilesOfIndex(Strings & files) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user