dataroaring commented on code in PR #47300: URL: https://github.com/apache/doris/pull/47300#discussion_r1956181777
########## be/src/cloud/cloud_snapshot_loader.cpp: ########## @@ -0,0 +1,234 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "cloud/cloud_snapshot_loader.h" + +#include <gen_cpp/Types_types.h> + +#include <unordered_map> + +#include "cloud/cloud_snapshot_mgr.h" +#include "cloud/cloud_storage_engine.h" +#include "common/logging.h" +#include "io/fs/broker_file_system.h" +#include "io/fs/file_system.h" +#include "io/fs/hdfs_file_system.h" +#include "io/fs/path.h" +#include "io/fs/remote_file_system.h" +#include "io/fs/s3_file_system.h" +#include "olap/olap_common.h" +#include "olap/olap_define.h" +#include "olap/rowset/rowset_factory.h" +#include "olap/rowset/rowset_meta.h" +#include "olap/rowset/rowset_writer.h" +#include "olap/rowset/rowset_writer_context.h" +#include "olap/tablet.h" +#include "util/slice.h" + +namespace doris { +namespace { +bool _end_with(std::string_view str, std::string_view match) { + return str.size() >= match.size() && + str.compare(str.size() - match.size(), match.size(), match) == 0; +} +} // namespace + +CloudSnapshotLoader::CloudSnapshotLoader(CloudStorageEngine& engine, ExecEnv* env, int64_t job_id, int64_t task_id, + const TNetworkAddress& broker_addr, + const std::map<std::string, std::string>& broker_prop) + : BaseSnapshotLoader(env, job_id, task_id, broker_addr, broker_prop), + _engine(engine) {}; + +Status CloudSnapshotLoader::init(TStorageBackendType::type type, const std::string& location, std::string vault_id) { + RETURN_IF_ERROR(BaseSnapshotLoader::init(type, location)); + _storage_resource = _engine.get_storage_resource(vault_id); + if (!_storage_resource) { + return Status::InternalError("vault id not found, vault id {}", vault_id); + } + return Status::OK(); +} + +io::RemoteFileSystemSPtr CloudSnapshotLoader::storage_fs() { + return _storage_resource->fs; +} + +Status CloudSnapshotLoader::upload(const std::map<std::string, std::string>& src_to_dest_path, + std::map<int64_t, std::vector<std::string>>* tablet_files) { + return Status::NotSupported("upload not supported"); +} + +Status CloudSnapshotLoader::download(const std::map<std::string, std::string>& src_to_dest_path, + std::vector<int64_t>* downloaded_tablet_ids) { + if (!_remote_fs || !_storage_resource) { + return Status::InternalError("Storage backend not initialized."); + } + + LOG(INFO) << "begin to transfer snapshot files. num: " << src_to_dest_path.size() + << ", broker addr: " << _broker_addr << ", job: " << _job_id + << ", task id: " << _task_id; + + // check if job has already been cancelled + int tmp_counter = 1; + RETURN_IF_ERROR(_report_every(0, &tmp_counter, 0, 0, TTaskType::type::DOWNLOAD)); + + Status status = Status::OK(); + + // 1. for each src path, transfer files to target path + int report_counter = 0; + int total_num = src_to_dest_path.size(); + int finished_num = 0; + for (const auto& iter : src_to_dest_path) { + const std::string& remote_path = iter.first; + const std::string& tablet_str = iter.second; + int64_t target_tablet_id = -1; + try { + target_tablet_id = std::stoll(tablet_str); + } catch (std::exception& e) { + return Status::InternalError("failed to parse target tablet id {}, {}", tablet_str, e.what()); + } + const std::string target_path = _storage_resource->remote_tablet_path(target_tablet_id); + + // 1.1. check target path not exists + bool target_path_exist = false; + if (!storage_fs()->exists(target_path, &target_path_exist).ok() || + target_path_exist) { + std::stringstream ss; + ss << "failed to download snapshot files, target path already exists: " << target_path; + LOG(WARNING) << ss.str(); + return Status::InternalError(ss.str()); + } Review Comment: If a retry happens, then it fails? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org