Merge pull request #43104 from vitlibar/fix-backup-of-lazy-db

Fix race for backup of tables in Lazy databases
This commit is contained in:
Vitaly Baranov 2022-11-14 21:11:50 +01:00 committed by GitHub
commit b8286b836d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 2 deletions

View File

@ -442,7 +442,7 @@ void BackupEntriesCollector::gatherTablesMetadata()
if (it != database_info.tables.end())
{
const auto & partitions = it->second.partitions;
if (partitions && !storage->supportsBackupPartition())
if (partitions && storage && !storage->supportsBackupPartition())
{
throw Exception(
ErrorCodes::CANNOT_BACKUP_TABLE,

View File

@ -177,6 +177,7 @@ std::vector<std::pair<ASTPtr, StoragePtr>> DatabaseMemory::getTablesForBackup(co
if (create.getTable() != table_name)
throw Exception(ErrorCodes::INCONSISTENT_METADATA_FOR_BACKUP, "Got a create query with unexpected name {} for temporary table {}", backQuoteIfNeed(create.getTable()), backQuoteIfNeed(table_name));
chassert(storage);
storage->adjustCreateQueryForBackup(create_table_query);
res.emplace_back(create_table_query, storage);
}

View File

@ -1214,6 +1214,7 @@ DatabaseReplicated::getTablesForBackup(const FilterByNameFunction & filter, cons
String table_name = unescapeForFileName(escaped_table_name);
if (!filter(table_name))
continue;
String zk_metadata;
if (!zookeeper->tryGet(zookeeper_path + "/metadata/" + escaped_table_name, zk_metadata))
throw Exception(ErrorCodes::INCONSISTENT_METADATA_FOR_BACKUP, "Metadata for table {} was not found in ZooKeeper", table_name);
@ -1233,6 +1234,10 @@ DatabaseReplicated::getTablesForBackup(const FilterByNameFunction & filter, cons
if (storage)
storage->adjustCreateQueryForBackup(create_table_query);
}
/// `storage` is allowed to be null here. In this case it means that this storage exists on other replicas
/// but it has not been created on this replica yet.
res.emplace_back(create_table_query, storage);
}

View File

@ -329,6 +329,10 @@ std::vector<std::pair<ASTPtr, StoragePtr>> DatabaseWithOwnTablesBase::getTablesF
for (auto it = getTablesIterator(local_context, filter); it->isValid(); it->next())
{
auto storage = it->table();
if (!storage)
continue; /// Probably the table has been just dropped.
auto create_table_query = tryGetCreateTableQuery(it->name(), local_context);
if (!create_table_query)
throw Exception(ErrorCodes::INCONSISTENT_METADATA_FOR_BACKUP, "Couldn't get a create query for table {}.{}", backQuoteIfNeed(getDatabaseName()), backQuoteIfNeed(it->name()));
@ -337,7 +341,6 @@ std::vector<std::pair<ASTPtr, StoragePtr>> DatabaseWithOwnTablesBase::getTablesF
if (create.getTable() != it->name())
throw Exception(ErrorCodes::INCONSISTENT_METADATA_FOR_BACKUP, "Got a create query with unexpected name {} for table {}.{}", backQuoteIfNeed(create.getTable()), backQuoteIfNeed(getDatabaseName()), backQuoteIfNeed(it->name()));
auto storage = it->table();
storage->adjustCreateQueryForBackup(create_table_query);
res.emplace_back(create_table_query, storage);
}