Merge pull request #51252 from ClickHouse/tavplubix-patch-6

Fix a stupid bug on Replicated database recovery
This commit is contained in:
Alexander Tokmakov 2023-06-22 15:06:41 +03:00 committed by GitHub
commit 5377373960
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -710,8 +710,9 @@ BlockIO DatabaseReplicated::tryEnqueueReplicatedDDL(const ASTPtr & query, Contex
static UUID getTableUUIDIfReplicated(const String & metadata, ContextPtr context)
{
bool looks_like_replicated = metadata.find("ReplicatedMergeTree") != std::string::npos;
if (!looks_like_replicated)
bool looks_like_replicated = metadata.find("Replicated") != std::string::npos;
bool looks_like_merge_tree = metadata.find("MergeTree") != std::string::npos;
if (!looks_like_replicated || !looks_like_merge_tree)
return UUIDHelpers::Nil;
ParserCreateQuery parser;
@ -1180,7 +1181,7 @@ void DatabaseReplicated::dropTable(ContextPtr local_context, const String & tabl
std::lock_guard lock{metadata_mutex};
UInt64 new_digest = tables_metadata_digest;
new_digest -= getMetadataHash(table_name);
if (txn && !txn->isCreateOrReplaceQuery())
if (txn && !txn->isCreateOrReplaceQuery() && !is_recovering)
txn->addOp(zkutil::makeSetRequest(replica_path + "/digest", toString(new_digest), -1));
DatabaseAtomic::dropTableImpl(local_context, table_name, sync);
@ -1234,7 +1235,7 @@ void DatabaseReplicated::renameTable(ContextPtr local_context, const String & ta
new_digest -= DB::getMetadataHash(to_table_name, statement_to);
new_digest += DB::getMetadataHash(table_name, statement_to);
}
if (txn)
if (txn && !is_recovering)
txn->addOp(zkutil::makeSetRequest(replica_path + "/digest", toString(new_digest), -1));
DatabaseAtomic::renameTable(local_context, table_name, to_database, to_table_name, exchange, dictionary);
@ -1260,7 +1261,7 @@ void DatabaseReplicated::commitCreateTable(const ASTCreateQuery & query, const S
std::lock_guard lock{metadata_mutex};
UInt64 new_digest = tables_metadata_digest;
new_digest += DB::getMetadataHash(query.getTable(), statement);
if (txn && !txn->isCreateOrReplaceQuery())
if (txn && !txn->isCreateOrReplaceQuery() && !is_recovering)
txn->addOp(zkutil::makeSetRequest(replica_path + "/digest", toString(new_digest), -1));
DatabaseAtomic::commitCreateTable(query, table, table_metadata_tmp_path, table_metadata_path, query_context);
@ -1284,7 +1285,7 @@ void DatabaseReplicated::commitAlterTable(const StorageID & table_id,
UInt64 new_digest = tables_metadata_digest;
new_digest -= getMetadataHash(table_id.table_name);
new_digest += DB::getMetadataHash(table_id.table_name, statement);
if (txn)
if (txn && !is_recovering)
txn->addOp(zkutil::makeSetRequest(replica_path + "/digest", toString(new_digest), -1));
DatabaseAtomic::commitAlterTable(table_id, table_metadata_tmp_path, table_metadata_path, statement, query_context);
@ -1307,7 +1308,7 @@ void DatabaseReplicated::detachTablePermanently(ContextPtr local_context, const
std::lock_guard lock{metadata_mutex};
UInt64 new_digest = tables_metadata_digest;
new_digest -= getMetadataHash(table_name);
if (txn)
if (txn && !is_recovering)
txn->addOp(zkutil::makeSetRequest(replica_path + "/digest", toString(new_digest), -1));
DatabaseAtomic::detachTablePermanently(local_context, table_name);
@ -1331,7 +1332,7 @@ void DatabaseReplicated::removeDetachedPermanentlyFlag(ContextPtr local_context,
if (attach)
{
new_digest += getMetadataHash(table_name);
if (txn)
if (txn && !is_recovering)
txn->addOp(zkutil::makeSetRequest(replica_path + "/digest", toString(new_digest), -1));
}