CLICKHOUSE-3714 bool ckeck_CanBeDropped -> void ...

This commit is contained in:
VadimPE 2018-08-03 12:39:01 +03:00
parent 6142d9ae6a
commit b97fa2eb4d
9 changed files with 26 additions and 35 deletions

View File

@ -59,8 +59,8 @@ BlockIO InterpreterAlterQuery::execute()
switch (command.type)
{
case PartitionCommand::DROP_PARTITION:
if (table->checkPartitionCanBeDropped(command.partition))
table->dropPartition(query_ptr, command.partition, command.detach, context);
table->checkPartitionCanBeDropped(command.partition);
table->dropPartition(query_ptr, command.partition, command.detach, context);
break;
case PartitionCommand::ATTACH_PARTITION:
@ -69,12 +69,10 @@ BlockIO InterpreterAlterQuery::execute()
case PartitionCommand::REPLACE_PARTITION:
{
if (table->checkPartitionCanBeDropped(command.partition))
{
String from_database = command.from_database.empty() ? context.getCurrentDatabase() : command.from_database;
auto from_storage = context.getTable(from_database, command.from_table);
table->replacePartitionFrom(from_storage, command.partition, command.replace, context);
}
table->checkPartitionCanBeDropped(command.partition);
String from_database = command.from_database.empty() ? context.getCurrentDatabase() : command.from_database;
auto from_storage = context.getTable(from_database, command.from_table);
table->replacePartitionFrom(from_storage, command.partition, command.replace, context);
}
break;

View File

@ -87,10 +87,7 @@ BlockIO InterpreterDropQuery::executeToTable(String & database_name_, String & t
}
else if (kind == ASTDropQuery::Kind::Drop)
{
if (!database_and_table.second->checkTableCanBeDropped())
throw Exception("Table " + database_name + "." + database_and_table.second->getTableName() +
" couldn't be dropped due to failed pre-drop check",
ErrorCodes::TABLE_WAS_NOT_DROPPED);
database_and_table.second->checkTableCanBeDropped()
database_and_table.second->shutdown();
/// If table was already dropped by anyone, an exception will be thrown

View File

@ -327,12 +327,12 @@ public:
/// Checks that table could be dropped right now
/// If it can - returns true
/// Otherwise - throws an exception with detailed information or returns false
virtual bool checkTableCanBeDropped() const { return true; }
virtual void checkTableCanBeDropped() const {}
/// Checks that Partition could be dropped right now
/// If it can - returns true
/// Otherwise - throws an exception with detailed information or returns false
virtual bool checkPartitionCanBeDropped(const ASTPtr & /*partition*/) { return true; }
virtual void checkPartitionCanBeDropped(const ASTPtr & /*partition*/) {}
/** Notify engine about updated dependencies for this storage. */
virtual void updateDependencies() {}

View File

@ -280,30 +280,30 @@ String StorageMaterializedView::getDataPath() const
return {};
}
bool StorageMaterializedView::checkTableCanBeDropped() const
void StorageMaterializedView::checkTableCanBeDropped() const
{
/// Don't drop the target table if it was created manually via 'TO inner_table' statement
if (!has_inner_table)
return true;
return;
auto target_table = tryGetTargetTable();
if (!target_table)
return true;
return;
return target_table->checkTableCanBeDropped();
target_table->checkTableCanBeDropped();
}
bool StorageMaterializedView::checkPartitionCanBeDropped(const ASTPtr & partition)
void StorageMaterializedView::checkPartitionCanBeDropped(const ASTPtr & partition)
{
/// Don't drop the partition in target table if it was created manually via 'TO inner_table' statement
if (!has_inner_table)
return true;
return;
auto target_table = tryGetTargetTable();
if (!target_table)
return true;
return;
return target_table->checkPartitionCanBeDropped(partition);
target_table->checkPartitionCanBeDropped(partition);
}
void registerStorageMaterializedView(StorageFactory & factory)

View File

@ -42,9 +42,9 @@ public:
void shutdown() override;
bool checkTableCanBeDropped() const override;
void checkTableCanBeDropped() const override;
bool checkPartitionCanBeDropped(const ASTPtr & partition) override;
void checkPartitionCanBeDropped(const ASTPtr & partition) override;
BlockInputStreams read(
const Names & column_names,

View File

@ -126,10 +126,9 @@ bool StorageMergeTree::checkTableCanBeDropped() const
{
const_cast<MergeTreeData &>(getData()).recalculateColumnSizes();
context.checkTableCanBeDropped(database_name, table_name, getData().getTotalActiveSizeInBytes());
return true;
}
bool StorageMergeTree::checkPartitionCanBeDropped(const ASTPtr & partition)
void StorageMergeTree::checkPartitionCanBeDropped(const ASTPtr & partition)
{
const_cast<MergeTreeData &>(getData()).recalculateColumnSizes();
@ -140,7 +139,6 @@ bool StorageMergeTree::checkPartitionCanBeDropped(const ASTPtr & partition)
{
context.checkPartitionCanBeDropped(database_name, table_name, part->bytes_on_disk);
}
return true;
}
void StorageMergeTree::drop()

View File

@ -83,9 +83,9 @@ public:
void alter(const AlterCommands & params, const String & database_name, const String & table_name, const Context & context) override;
bool checkTableCanBeDropped() const override;
void checkTableCanBeDropped() const override;
bool checkPartitionCanBeDropped(const ASTPtr & partition) override;
void checkPartitionCanBeDropped(const ASTPtr & partition) override;
ActionLock getActionLock(StorageActionBlockType action_type) override;

View File

@ -3345,16 +3345,15 @@ void StorageReplicatedMergeTree::attachPartition(const ASTPtr & partition, bool
}
bool StorageReplicatedMergeTree::checkTableCanBeDropped() const
void StorageReplicatedMergeTree::checkTableCanBeDropped() const
{
/// Consider only synchronized data
const_cast<MergeTreeData &>(getData()).recalculateColumnSizes();
context.checkTableCanBeDropped(database_name, table_name, getData().getTotalActiveSizeInBytes());
return true;
}
bool StorageReplicatedMergeTree::checkPartitionCanBeDropped(const ASTPtr & partition)
void StorageReplicatedMergeTree::checkPartitionCanBeDropped(const ASTPtr & partition)
{
const_cast<MergeTreeData &>(getData()).recalculateColumnSizes();
@ -3365,7 +3364,6 @@ bool StorageReplicatedMergeTree::checkPartitionCanBeDropped(const ASTPtr & parti
{
context.checkPartitionCanBeDropped(database_name, table_name, part->bytes_on_disk);
}
return true;
}

View File

@ -138,9 +138,9 @@ public:
bool supportsIndexForIn() const override { return true; }
bool mayBenefitFromIndexForIn(const ASTPtr & left_in_operand) const override { return data.mayBenefitFromIndexForIn(left_in_operand); }
bool checkTableCanBeDropped() const override;
void checkTableCanBeDropped() const override;
bool checkPartitionCanBeDropped(const ASTPtr & partition) override;
void checkPartitionCanBeDropped(const ASTPtr & partition) override;
ActionLock getActionLock(StorageActionBlockType action_type) override;