Skip to content

Commit bd451f3

Browse files
Merge pull request ClickHouse#87088 from ClickHouse/backport/25.8/86563
Backport ClickHouse#86563 to 25.8: Fix Backup db engine raising exception on query with zero sized part files
2 parents 6d69d37 + d90ab1b commit bd451f3

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

src/Backups/BackupImpl.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,16 @@ BackupImpl::readFileImpl(const String & file_name, const SizeAndChecksum & size_
764764
if (open_mode == OpenMode::WRITE)
765765
throw Exception(ErrorCodes::LOGICAL_ERROR, "The backup file should not be opened for writing. Something is wrong internally");
766766

767+
// Zero-sized files are not inserted into `file_infos` during metadata load,
768+
// but they are present in `file_names`. Short-circuit them here and return
769+
// an empty buffer without consulting `file_infos`.
770+
if (size_and_checksum.first == 0)
771+
{
772+
std::lock_guard lock{mutex};
773+
++num_read_files;
774+
return std::make_unique<ReadBufferFromOutsideMemoryFile>(file_name, std::string_view{});
775+
}
776+
767777
BackupFileInfo info;
768778
{
769779
std::lock_guard lock{mutex};
@@ -780,14 +790,6 @@ BackupImpl::readFileImpl(const String & file_name, const SizeAndChecksum & size_
780790
info = it->second;
781791
}
782792

783-
if (info.size == 0)
784-
{
785-
/// Entry's data is empty.
786-
std::lock_guard lock{mutex};
787-
++num_read_files;
788-
return std::make_unique<ReadBufferFromOutsideMemoryFile>(info.data_file_name, std::string_view{});
789-
}
790-
791793
if (info.encrypted_by_disk != read_encrypted)
792794
{
793795
throw Exception(

tests/queries/0_stateless/02731_zero_objects_in_metadata.reference

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@
22
1 []
33
[]
44
1 []
5+
[]
6+
1 []
7+
1 []
8+
[]
59
1 []
610
[]

tests/queries/0_stateless/02731_zero_objects_in_metadata.sh

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
77

88
for DISK in s3_disk s3_cache
99
do
10+
BACKUP_NAME="test_s3_backup_${CLICKHOUSE_TEST_UNIQUE_NAME}_${DISK}"
11+
BACKUP_DB_NAME="test_backup_db_${CLICKHOUSE_DATABASE}"
12+
1013
${CLICKHOUSE_CLIENT} --query "
1114
DROP TABLE IF EXISTS test;
1215
CREATE TABLE test (id Int32, empty Array(Int32))
@@ -15,16 +18,23 @@ do
1518
1619
INSERT INTO test (id) VALUES (1);
1720
SELECT * FROM test;
18-
"
1921
20-
${CLICKHOUSE_CLIENT} --query "
21-
BACKUP TABLE test TO Disk('backups', 'test_s3_backup');
22+
BACKUP TABLE test TO Disk('backups', '${BACKUP_NAME}') FORMAT Null;
2223
DROP TABLE test;
23-
RESTORE TABLE test FROM Disk('backups', 'test_s3_backup');
24-
" &>/dev/null
24+
RESTORE TABLE test FROM Disk('backups', '${BACKUP_NAME}') FORMAT Null;
2525
26-
${CLICKHOUSE_CLIENT} --query "
2726
SELECT * FROM test;
2827
SELECT empty FROM test;
28+
29+
DROP DATABASE IF EXISTS "${BACKUP_DB_NAME}";
30+
-- we create a backup db that points to the current test's CLICKHOUSE_DATABASE
31+
-- otherwise it will have no tables.
32+
CREATE DATABASE "${BACKUP_DB_NAME}"
33+
ENGINE=Backup('${CLICKHOUSE_DATABASE}', Disk('backups', '${BACKUP_NAME}'));
34+
35+
SELECT * FROM "${BACKUP_DB_NAME}".test;
36+
SELECT empty FROM "${BACKUP_DB_NAME}".test;
37+
38+
DROP DATABASE "${BACKUP_DB_NAME}";
2939
"
3040
done

0 commit comments

Comments
 (0)