Skip to content

Commit adc0693

Browse files
authored
Merge pull request ClickHouse#79936 from ClickHouse/hanfei/remove-and-sync-snapshot-code
remove some useless code and sync some code for snapshot
2 parents 06fab1d + c91ee72 commit adc0693

File tree

6 files changed

+12
-24
lines changed

6 files changed

+12
-24
lines changed

src/Backups/BackupCoordinationOnCluster.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ namespace
102102
{
103103
BackupFileInfos file_infos;
104104

105-
static String serialize(const BackupFileInfos & file_infos_, bool is_lightweight_snapshot)
105+
static String serialize(const BackupFileInfos & file_infos_)
106106
{
107107
WriteBufferFromOwnString out;
108108
writeBinary(file_infos_.size(), out);
@@ -115,17 +115,13 @@ namespace
115115
writeBinary(info.base_checksum, out);
116116
writeBinary(info.encrypted_by_disk, out);
117117
writeBinary(info.reference_target, out);
118-
if (is_lightweight_snapshot)
119-
{
120-
writeBinary(info.object_key, out);
121-
}
122118
/// We don't store `info.data_file_name` and `info.data_file_index` because they're determined automalically
123119
/// after reading file infos for all the hosts (see the class BackupCoordinationFileInfos).
124120
}
125121
return out.str();
126122
}
127123

128-
static FileInfos deserialize(const String & str, bool is_lightweight_snapshot)
124+
static FileInfos deserialize(const String & str)
129125
{
130126
ReadBufferFromString in{str};
131127
FileInfos res;
@@ -142,10 +138,6 @@ namespace
142138
readBinary(info.base_checksum, in);
143139
readBinary(info.encrypted_by_disk, in);
144140
readBinary(info.reference_target, in);
145-
if (is_lightweight_snapshot)
146-
{
147-
readBinary(info.object_key, in);
148-
}
149141
}
150142
return res;
151143
}
@@ -172,7 +164,6 @@ size_t BackupCoordinationOnCluster::findCurrentHostIndex(const String & current_
172164
BackupCoordinationOnCluster::BackupCoordinationOnCluster(
173165
const UUID & backup_uuid_,
174166
bool is_plain_backup_,
175-
bool is_lightweight_snapshot_,
176167
const String & root_zookeeper_path_,
177168
zkutil::GetZooKeeper get_zookeeper_,
178169
const BackupKeeperSettings & keeper_settings_,
@@ -191,7 +182,6 @@ BackupCoordinationOnCluster::BackupCoordinationOnCluster(
191182
, current_host(current_host_)
192183
, current_host_index(findCurrentHostIndex(current_host, all_hosts))
193184
, plain_backup(is_plain_backup_)
194-
, lightweight_snapshot(is_lightweight_snapshot_)
195185
, process_list_element(process_list_element_)
196186
, log(getLogger("BackupCoordinationOnCluster"))
197187
, with_retries(log, get_zookeeper_, keeper_settings, process_list_element_, [root_zookeeper_path_](Coordination::ZooKeeperWithFaultInjection::Ptr zk) { zk->sync(root_zookeeper_path_); })
@@ -759,7 +749,7 @@ void BackupCoordinationOnCluster::addFileInfos(BackupFileInfos && file_infos_)
759749
}
760750

761751
/// Serialize `file_infos_` and write it to ZooKeeper's nodes.
762-
String file_infos_str = FileInfos::serialize(file_infos_, lightweight_snapshot);
752+
String file_infos_str = FileInfos::serialize(file_infos_);
763753
serializeToMultipleZooKeeperNodes(zookeeper_path + "/file_infos/" + current_host, file_infos_str, "addFileInfos");
764754
}
765755

@@ -798,7 +788,7 @@ void BackupCoordinationOnCluster::prepareFileInfos() const
798788
for (const String & host : hosts_with_file_infos)
799789
{
800790
String file_infos_str = deserializeFromMultipleZooKeeperNodes(zookeeper_path + "/file_infos/" + host, "prepareFileInfos");
801-
auto deserialized_file_infos = FileInfos::deserialize(file_infos_str, lightweight_snapshot).file_infos;
791+
auto deserialized_file_infos = FileInfos::deserialize(file_infos_str).file_infos;
802792
file_infos->addFileInfos(std::move(deserialized_file_infos), host);
803793
}
804794
}

src/Backups/BackupCoordinationOnCluster.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class BackupCoordinationOnCluster : public IBackupCoordination
2424
BackupCoordinationOnCluster(
2525
const UUID & backup_uuid_,
2626
bool is_plain_backup_,
27-
bool is_lightweight_snapshot_,
2827
const String & root_zookeeper_path_,
2928
zkutil::GetZooKeeper get_zookeeper_,
3029
const BackupKeeperSettings & keeper_settings_,
@@ -108,7 +107,6 @@ class BackupCoordinationOnCluster : public IBackupCoordination
108107
const String current_host;
109108
const size_t current_host_index;
110109
const bool plain_backup;
111-
const bool lightweight_snapshot;
112110
const QueryStatusPtr process_list_element;
113111
const LoggerPtr log;
114112

src/Backups/BackupImpl.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,19 @@ BackupImpl::BackupImpl(
9292
BackupFactory::CreateParams params_,
9393
const ArchiveParams & archive_params_,
9494
std::shared_ptr<IBackupReader> reader_,
95-
std::shared_ptr<IBackupReader> lightweight_snapshot_reader_)
95+
SnapshotReaderCreator lightweight_snapshot_reader_creator_)
9696
: params(std::move(params_))
9797
, backup_info(params.backup_info)
9898
, backup_name_for_logging(backup_info.toStringForLogging())
9999
, use_archive(!archive_params_.archive_name.empty())
100100
, archive_params(archive_params_)
101101
, open_mode(OpenMode::READ)
102102
, reader(std::move(reader_))
103-
, lightweight_snapshot_reader(std::move(lightweight_snapshot_reader_))
103+
, lightweight_snapshot_reader_creator(lightweight_snapshot_reader_creator_)
104104
, version(INITIAL_BACKUP_VERSION)
105105
, base_backup_info(params.base_backup_info)
106106
, log(getLogger("BackupImpl"))
107107
{
108-
if (params.is_lightweight_snapshot && !lightweight_snapshot_reader_)
109-
{
110-
throw Exception(ErrorCodes::LOGICAL_ERROR, "Cannot create lightweight backup reader");
111-
}
112108
open();
113109
}
114110

src/Backups/BackupImpl.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ class BackupImpl : public IBackup
3333
size_t max_volume_size = 0;
3434
};
3535

36+
using SnapshotReaderCreator = std::function<std::shared_ptr<IBackupReader>(const String &, const String &)>;
37+
3638
/// RESTORE
3739
BackupImpl(
3840
BackupFactory::CreateParams params_,
3941
const ArchiveParams & archive_params_,
4042
std::shared_ptr<IBackupReader> reader_,
41-
std::shared_ptr<IBackupReader> lightweight_snapshot_reader_ = nullptr);
43+
SnapshotReaderCreator lightweight_snapshot_reader_creator_ = {});
4244

4345
/// BACKUP
4446
BackupImpl(
@@ -118,6 +120,7 @@ class BackupImpl : public IBackup
118120
/// Only used for lightweight backup, we read data from original object storage so the endpoint may be different from the backup files.
119121
std::shared_ptr<IBackupReader> lightweight_snapshot_reader;
120122
std::shared_ptr<IBackupWriter> lightweight_snapshot_writer;
123+
SnapshotReaderCreator lightweight_snapshot_reader_creator;
121124
std::shared_ptr<IBackupCoordination> coordination;
122125

123126
mutable std::mutex mutex;

src/Backups/BackupsWorker.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,6 @@ BackupsWorker::makeBackupCoordination(bool on_cluster, const BackupSettings & ba
10011001
return std::make_shared<BackupCoordinationOnCluster>(
10021002
*backup_settings.backup_uuid,
10031003
!backup_settings.deduplicate_files,
1004-
backup_settings.experimental_lightweight_snapshot,
10051004
root_zk_path,
10061005
get_zookeeper,
10071006
keeper_settings,

src/Backups/IBackupEntry.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class IBackupEntry
4646
virtual bool isFromRemoteFile() const { return false; }
4747
/// if it is a BackupEntryFromRemotePath, return the object key which the file refers to.
4848
virtual String getRemotePath() const { return "invalid remote path"; }
49+
virtual String getEndpointURI() const { return "invalid endpoint"; }
50+
virtual String getNamespace() const { return "invalid namespace"; }
4951
virtual String getFilePath() const { return ""; }
5052
virtual DiskPtr getDisk() const { return nullptr; }
5153

0 commit comments

Comments
 (0)