imay commented on a change in pull request #1624: Fix tablet restore api in
BE(#1623)
URL: https://github.com/apache/incubator-doris/pull/1624#discussion_r312801515
##########
File path: be/src/http/action/restore_tablet_action.cpp
##########
@@ -185,31 +176,48 @@ Status RestoreTabletAction::_restore(const std::string&
key, int64_t tablet_id,
return s;
}
// create hard link for files in
/root_path/data/shard/tablet_id/schema_hash
+ s = _create_hard_link_recursive(latest_tablet_path,
restore_schema_hash_path);
+ if (!s.ok()) {
+ s = FileUtils::remove_all(restore_schema_hash_path);
+ if (!s.ok()) {
+ LOG(WARNING) << "remove invalid tablet path:" <<
restore_schema_hash_path << " failed";
+ }
+ }
+ std::string restore_shard_path =
store->get_absolute_shard_path(std::to_string(tablet_meta.shard_id()));
+ Status status = _reload_tablet(key, restore_shard_path, tablet_id,
schema_hash);
+ return status;
+}
+
+Status RestoreTabletAction::_create_hard_link_recursive(const std::string&
src, const std::string& dst) {
std::vector<std::string> files;
- s = FileUtils::scan_dir(latest_tablet_path, &files);
+ Status s = FileUtils::scan_dir(src, &files);
if (!s.ok()) {
- LOG(WARNING) << "scan dir failed:" << latest_tablet_path;
+ LOG(WARNING) << "scan dir failed:" << src;
return s;
}
for (auto& file : files) {
- std::string from = latest_tablet_path + "/" + file;
- std::string to = restore_schema_hash_path + "/" + file;
- int link_ret = link(from.c_str(), to.c_str());
- if (link_ret != 0) {
- LOG(WARNING) << "link from:" << from
- << " to:" << to << " failed, link ret:" << link_ret;
- std::string restore_tablet_path =
store->get_absolute_tablet_path(&tablet_meta, false);
- LOG(WARNING) << "remove tablet_path:" << restore_tablet_path;
- Status s = FileUtils::remove_all(restore_tablet_path);
+ std::string from = src + "/" + file;
+ std::string to = dst + "/" + file;
+ if (FileUtils::is_dir(from)) {
+ s = FileUtils::create_dir(to);
+ if (!s.ok()) {
+ LOG(WARNING) << "create path failed:" << to;
+ return s;
+ }
+ s = _create_hard_link_recursive(from, to);
Review comment:
RETURN_IF_ERROR()
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]