fix a bug in projections

This commit is contained in:
Alexander Tokmakov 2023-07-08 14:58:38 +02:00
parent e08f140d62
commit 44ae3a0986
7 changed files with 38 additions and 8 deletions

View File

@ -312,15 +312,20 @@ IMergeTreeDataPart::IMergeTreeDataPart(
const IMergeTreeDataPart * parent_part_)
: DataPartStorageHolder(data_part_storage_)
, storage(storage_)
, name(name_)
, mutable_name(name_)
, name(mutable_name)
, info(info_)
, index_granularity_info(storage_, part_type_)
, part_type(part_type_)
, parent_part(parent_part_)
, parent_part_name(parent_part ? parent_part->name : "")
, use_metadata_cache(storage.use_metadata_cache)
{
if (parent_part)
{
chassert(parent_part_name.starts_with(parent_part->info.partition_id)); /// Make sure there's no prefix
state = MergeTreeDataPartState::Active;
}
incrementStateMetric(state);
incrementTypeMetric(part_type);
@ -337,6 +342,12 @@ IMergeTreeDataPart::~IMergeTreeDataPart()
decrementTypeMetric(part_type);
}
void IMergeTreeDataPart::setName(const String & new_name)
{
mutable_name = new_name;
for (auto & proj_part : projection_parts)
proj_part.second->parent_part_name = new_name;
}
String IMergeTreeDataPart::getNewName(const MergeTreePartInfo & new_part_info) const
{

View File

@ -200,9 +200,14 @@ public:
/// If token is not empty, block id is calculated based on it instead of block data
String getZeroLevelPartBlockID(std::string_view token) const;
void setName(const String & new_name);
const MergeTreeData & storage;
String name;
private:
String mutable_name;
public:
const String & name; // const ref to private mutable_name
MergeTreePartInfo info;
/// Part unique identifier.
@ -386,6 +391,7 @@ public:
bool isProjectionPart() const { return parent_part != nullptr; }
const IMergeTreeDataPart * getParentPart() const { return parent_part; }
String getParentPartName() const { return parent_part_name; }
const std::map<String, std::shared_ptr<IMergeTreeDataPart>> & getProjectionParts() const { return projection_parts; }
@ -519,6 +525,7 @@ protected:
/// Not null when it's a projection part.
const IMergeTreeDataPart * parent_part;
String parent_part_name;
std::map<String, std::shared_ptr<IMergeTreeDataPart>> projection_parts;

View File

@ -7455,7 +7455,19 @@ void MergeTreeData::reportBrokenPart(MergeTreeData::DataPartPtr data_part) const
return;
if (data_part->isProjectionPart())
data_part = data_part->getParentPart()->shared_from_this();
{
String parent_part_name = data_part->getParentPartName();
auto parent_part = getPartIfExists(parent_part_name, {DataPartState::PreActive, DataPartState::Active, DataPartState::Outdated});
if (!parent_part)
{
LOG_WARNING(log, "Did not find parent part {} for potentially broken projection part {}",
parent_part_name, data_part->getDataPartStorage().getFullPath());
return;
}
data_part = parent_part;
}
if (data_part->getDataPartStorage().isBroken())
{

View File

@ -917,7 +917,7 @@ public:
{
LOG_DEBUG(log, "Merged a projection part in level {}", current_level);
selected_parts[0]->renameTo(projection.name + ".proj", true);
selected_parts[0]->name = projection.name;
selected_parts[0]->setName(projection.name);
selected_parts[0]->is_temp = false;
ctx->new_data_part->addProjectionPart(name, std::move(selected_parts[0]));

View File

@ -788,7 +788,7 @@ std::pair<std::vector<String>, bool> ReplicatedMergeTreeSinkImpl<async_insert>::
part->info.level = 0;
part->info.mutation = 0;
part->name = part->getNewName(part->info);
part->setName(part->getNewName(part->info));
StorageReplicatedMergeTree::LogEntry log_entry;
@ -914,7 +914,7 @@ std::pair<std::vector<String>, bool> ReplicatedMergeTreeSinkImpl<async_insert>::
/// Note that it may also appear on filesystem right now in PreActive state due to concurrent inserts of the same data.
/// It will be checked when we will try to rename directory.
part->name = existing_part_name;
part->setName(existing_part_name);
part->info = MergeTreePartInfo::fromPartName(existing_part_name, storage.format_version);
/// Used only for exception messages.
block_number = part->info.min_block;

View File

@ -2260,7 +2260,7 @@ void StorageMergeTree::fillNewPartName(MutableDataPartPtr & part, DataPartsLock
{
part->info.min_block = part->info.max_block = increment.get();
part->info.mutation = 0;
part->name = part->getNewName(part->info);
part->setName(part->getNewName(part->info));
}
}

View File

@ -9262,7 +9262,7 @@ bool StorageReplicatedMergeTree::createEmptyPartInsteadOfLost(zkutil::ZooKeeperP
}
MergeTreeData::MutableDataPartPtr new_data_part = createEmptyPart(new_part_info, partition, lost_part_name, NO_TRANSACTION_PTR);
new_data_part->name = lost_part_name;
new_data_part->setName(lost_part_name);
try
{