Fix crash when BACKUP & RESTORE are called without ON CLUSTER for replicated DB.

This commit is contained in:
Vitaly Baranov 2022-04-29 12:34:39 +02:00
parent 2a645bb187
commit b1295311c9
2 changed files with 17 additions and 0 deletions

View File

@ -7,6 +7,7 @@
#include <Backups/IBackupEntry.h> #include <Backups/IBackupEntry.h>
#include <Backups/IRestoreTask.h> #include <Backups/IRestoreTask.h>
#include <Backups/RestoreCoordinationDistributed.h> #include <Backups/RestoreCoordinationDistributed.h>
#include <Backups/RestoreCoordinationLocal.h>
#include <Backups/formatTableNameOrTemporaryTableName.h> #include <Backups/formatTableNameOrTemporaryTableName.h>
#include <Common/escapeForFileName.h> #include <Common/escapeForFileName.h>
#include <Databases/IDatabase.h> #include <Databases/IDatabase.h>
@ -471,6 +472,8 @@ namespace
{ {
if (!restore_settings.coordination_zk_path.empty()) if (!restore_settings.coordination_zk_path.empty())
restore_coordination = std::make_shared<RestoreCoordinationDistributed>(restore_settings.coordination_zk_path, [context=context] { return context->getZooKeeper(); }); restore_coordination = std::make_shared<RestoreCoordinationDistributed>(restore_settings.coordination_zk_path, [context=context] { return context->getZooKeeper(); });
else
restore_coordination = std::make_shared<RestoreCoordinationLocal>();
} }
/// Prepares internal structures for making tasks for restoring. /// Prepares internal structures for making tasks for restoring.

View File

@ -158,3 +158,17 @@ def test_different_tables_on_nodes():
[[1, "Don\\'t"], [2, "count"], [3, "your"], [4, "chickens"]] [[1, "Don\\'t"], [2, "count"], [3, "your"], [4, "chickens"]]
) )
assert node2.query("SELECT * FROM tbl") == TSV([-333, -222, -111, 0, 111]) assert node2.query("SELECT * FROM tbl") == TSV([-333, -222, -111, 0, 111])
def test_backup_restore_on_single_replica():
node1.query("CREATE DATABASE mydb ON CLUSTER 'cluster' ENGINE=Replicated('/clickhouse/path/','{shard}','{replica}')")
node1.query("CREATE TABLE mydb.test (`name` String, `value` UInt32) ENGINE = ReplicatedMergeTree ORDER BY value")
node1.query("INSERT INTO mydb.test VALUES ('abc', 1), ('def', 2)")
node1.query("INSERT INTO mydb.test VALUES ('ghi', 3)")
backup_name = new_backup_name()
node1.query(f"BACKUP DATABASE mydb TO {backup_name}")
node1.query("DROP DATABASE mydb NO DELAY")
node1.query(f"RESTORE DATABASE mydb FROM {backup_name}")