mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Optimize code
This commit is contained in:
parent
cca8df6b78
commit
2a51286527
@ -418,7 +418,10 @@ void InterpreterSystemQuery::dropReplica(ASTSystemQuery & query)
|
||||
storage_replicated->getStatus(status);
|
||||
if (query.replica == status.replica_name)
|
||||
throw Exception("We can't drop local replica, please use `DROP TABLE` if you want to clean the data and drop this replica", ErrorCodes::LOGICAL_ERROR);
|
||||
storage_replicated->dropReplica(zookeeper, status.zookeeper_path, query.replica, status.is_readonly ,false);
|
||||
if (zookeeper->exists(status.zookeeper_path + "/replicas/" + query.replica + "/is_active"))
|
||||
throw Exception("Can't drop replica: " + query.replica + ", because it's active",
|
||||
ErrorCodes::LOGICAL_ERROR);
|
||||
storage_replicated->dropReplica(zookeeper, status.zookeeper_path, query.replica, status.is_readonly);
|
||||
LOG_TRACE(log, "DROP REPLICA " + table_id.getNameForLogs() + " [" + query.replica + "]: OK");
|
||||
}
|
||||
else
|
||||
@ -437,7 +440,10 @@ void InterpreterSystemQuery::dropReplica(ASTSystemQuery & query)
|
||||
storage_replicated->getStatus(status);
|
||||
if (query.replica == status.replica_name)
|
||||
throw Exception("We can't drop local replica, please use `DROP TABLE` if you want to clean the data and drop this replica", ErrorCodes::LOGICAL_ERROR);
|
||||
storage_replicated->dropReplica(zookeeper, status.zookeeper_path, query.replica, status.is_readonly ,false);
|
||||
if (zookeeper->exists(status.zookeeper_path + "/replicas/" + query.replica + "/is_active"))
|
||||
throw Exception("Can't drop replica: " + query.replica + ", because it's active",
|
||||
ErrorCodes::LOGICAL_ERROR);
|
||||
storage_replicated->dropReplica(zookeeper, status.zookeeper_path, query.replica, status.is_readonly);
|
||||
}
|
||||
}
|
||||
LOG_TRACE(log, "DROP REPLICA " + query.replica + " DATABSE " + database->getDatabaseName() + ": OK");
|
||||
@ -463,7 +469,10 @@ void InterpreterSystemQuery::dropReplica(ASTSystemQuery & query)
|
||||
ErrorCodes::LOGICAL_ERROR);
|
||||
if (status.replica_path.compare(query.replica_zk_path + "/replicas/" + status.replica_name) == 0)
|
||||
{
|
||||
storage_replicated->dropReplica(zookeeper, query.replica_zk_path, query.replica, status.is_readonly ,false);
|
||||
if (zookeeper->exists(query.replica_zk_path + "/replicas/" + query.replica + "/is_active"))
|
||||
throw Exception("Can't drop replica: " + query.replica + ", because it's active",
|
||||
ErrorCodes::LOGICAL_ERROR);
|
||||
storage_replicated->dropReplica(zookeeper, query.replica_zk_path, query.replica, status.is_readonly);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -494,7 +503,10 @@ void InterpreterSystemQuery::dropReplica(ASTSystemQuery & query)
|
||||
storage_replicated->getStatus(status);
|
||||
if (query.replica == status.replica_name)
|
||||
throw Exception("We can't drop local replica, please use `DROP TABLE` if you want to clean the data and drop this replica", ErrorCodes::LOGICAL_ERROR);
|
||||
storage_replicated->dropReplica(zookeeper, status.zookeeper_path, query.replica, status.is_readonly ,false);
|
||||
if (zookeeper->exists(status.zookeeper_path + "/replicas/" + query.replica + "/is_active"))
|
||||
throw Exception("Can't drop replica: " + query.replica + ", because it's active",
|
||||
ErrorCodes::LOGICAL_ERROR);
|
||||
storage_replicated->dropReplica(zookeeper, status.zookeeper_path, query.replica, status.is_readonly);
|
||||
}
|
||||
}
|
||||
LOG_TRACE(log, "DROP REPLICA " + query.replica + " DATABSE " + database->getDatabaseName() + ": OK");
|
||||
|
@ -632,7 +632,7 @@ void StorageReplicatedMergeTree::drop()
|
||||
throw Exception("Can't drop readonly replicated table (need to drop data in ZooKeeper as well)", ErrorCodes::TABLE_IS_READ_ONLY);
|
||||
|
||||
shutdown();
|
||||
dropReplica(zookeeper, zookeeper_path, replica_name, is_readonly ,true);
|
||||
dropReplica(zookeeper, zookeeper_path, replica_name, is_readonly);
|
||||
}
|
||||
|
||||
dropAllData();
|
||||
@ -750,7 +750,7 @@ static time_t tryGetPartCreateTime(zkutil::ZooKeeperPtr & zookeeper, const Strin
|
||||
return res;
|
||||
}
|
||||
|
||||
void StorageReplicatedMergeTree::dropReplica(zkutil::ZooKeeperPtr zookeeper, const String & zookeeper_path, const String & replica, bool is_readonly, bool is_drop_table)
|
||||
void StorageReplicatedMergeTree::dropReplica(zkutil::ZooKeeperPtr zookeeper, const String & zookeeper_path, const String & replica, bool is_readonly)
|
||||
{
|
||||
static Poco::Logger * log = &Poco::Logger::get("StorageReplicatedMergeTree::dropReplica");
|
||||
|
||||
@ -761,13 +761,6 @@ void StorageReplicatedMergeTree::dropReplica(zkutil::ZooKeeperPtr zookeeper, con
|
||||
if (zookeeper->expired())
|
||||
throw Exception("Table was not dropped because ZooKeeper session has expired.", ErrorCodes::TABLE_WAS_NOT_DROPPED);
|
||||
|
||||
if (!is_drop_table)
|
||||
{
|
||||
if (zookeeper->exists(zookeeper_path + "/replicas/" + replica + "/is_active"))
|
||||
throw Exception("Can't drop replica: " + replica + ", because it's active",
|
||||
ErrorCodes::LOGICAL_ERROR);
|
||||
}
|
||||
|
||||
auto remote_replica_path = zookeeper_path + "/replicas" + "/" + replica;
|
||||
LOG_INFO(log, "Removing replica {}", remote_replica_path);
|
||||
/// It may left some garbage if replica_path subtree are concurently modified
|
||||
|
@ -182,7 +182,7 @@ public:
|
||||
|
||||
/** Remove a specific replica from zookeeper.
|
||||
*/
|
||||
static void dropReplica(zkutil::ZooKeeperPtr zookeeper, const String & zookeeper_path, const String & replica, bool is_readonly, bool is_drop_table);
|
||||
static void dropReplica(zkutil::ZooKeeperPtr zookeeper, const String & zookeeper_path, const String & replica, bool is_readonly);
|
||||
|
||||
private:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user