Skip to content

Commit 8cacddd

Browse files
yuhaijun999ketor
authored andcommitted
[fix][store] Fix br restore bugs.
1 parent d2810f5 commit 8cacddd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+4044
-843
lines changed

src/br/backup.cc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,13 @@ butil::Status Backup::Init() {
8888
dingodb::pb::common::VersionInfo version_info_local = dingodb::GetVersionInfo();
8989
status = CompareVersion(version_info_local, version_info_remote);
9090
if (!status.ok()) {
91-
DINGO_LOG(ERROR) << status.error_cstr();
92-
return status;
91+
if (FLAGS_backup_strict_version_comparison) {
92+
DINGO_LOG(ERROR) << status.error_cstr();
93+
return status;
94+
} else {
95+
std::cout << "ignore version compare" << std::endl;
96+
DINGO_LOG(INFO) << "ignore version compare";
97+
}
9398
}
9499

95100
std::cout << "version compare ok" << std::endl;
@@ -1198,8 +1203,13 @@ butil::Status Backup::CompareVersion(const dingodb::pb::common::VersionInfo& ver
11981203
if (version_info_local.git_commit_hash() != version_info_remote.git_commit_hash()) {
11991204
std::string s = fmt::format("git_commit_hash is different. local : {} remote : {}",
12001205
version_info_local.git_commit_hash(), version_info_remote.git_commit_hash());
1201-
DINGO_LOG(ERROR) << s;
1202-
return butil::Status(dingodb::pb::error::EBACKUP_VERSION_NOT_MATCH, s);
1206+
if (FLAGS_backup_strict_version_comparison) {
1207+
DINGO_LOG(ERROR) << s;
1208+
return butil::Status(dingodb::pb::error::EBACKUP_VERSION_NOT_MATCH, s);
1209+
} else {
1210+
DINGO_LOG(WARNING) << s;
1211+
return butil::Status(dingodb::pb::error::EBACKUP_VERSION_NOT_MATCH, s);
1212+
}
12031213
}
12041214

12051215
return butil::Status::OK();

src/br/backup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class Backup : public std::enable_shared_from_this<Backup> {
100100
bool is_already_register_backup_to_coordinator_;
101101

102102
// is exit register backup to coordinator thread. default true.
103-
bool is_exit_register_backup_to_coordinator_thread_;
103+
std::atomic<bool> is_exit_register_backup_to_coordinator_thread_;
104104

105105
bool region_auto_split_enable_after_finish_;
106106
bool region_auto_merge_enable_after_finish_;

src/br/interation.cc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ bool ServerInteraction::Init(std::vector<std::string> addrs) {
4040
}
4141

4242
for (auto& endpoint : endpoints_) {
43-
DINGO_LOG(INFO) << fmt::format("Init channel {}:{}", butil::ip2str(endpoint.ip).c_str(), endpoint.port);
43+
if (FLAGS_br_log_switch_restore_detail || FLAGS_br_log_switch_restore_detail_detail ||
44+
FLAGS_br_log_switch_backup_detail || FLAGS_br_log_switch_backup_detail_detail) {
45+
DINGO_LOG(INFO) << fmt::format("Init channel {}:{}", butil::ip2str(endpoint.ip).c_str(), endpoint.port);
46+
}
47+
4448
std::unique_ptr<brpc::Channel> channel = std::make_unique<brpc::Channel>();
4549
if (channel->Init(endpoint, nullptr) != 0) {
4650
DINGO_LOG(ERROR) << fmt::format("Init channel failed, {}:{}", butil::ip2str(endpoint.ip).c_str(), endpoint.port);
@@ -132,4 +136,21 @@ butil::Status ServerInteraction::CreateInteraction(const std::vector<std::string
132136
return butil::Status::OK();
133137
}
134138

139+
butil::Status ServerInteraction::CreateInteraction(const std::string& addrs,
140+
std::shared_ptr<ServerInteraction>& interaction) {
141+
butil::Status status;
142+
interaction = std::make_shared<br::ServerInteraction>();
143+
if (!interaction->Init(addrs)) {
144+
std::string s = fmt::format("Fail to init interaction, addrs");
145+
for (const auto& addr : addrs) {
146+
s += fmt::format(" {}", addr);
147+
}
148+
DINGO_LOG(ERROR) << s;
149+
status = butil::Status(dingodb::pb::error::EINTERNAL, s);
150+
return status;
151+
}
152+
153+
return butil::Status::OK();
154+
}
155+
135156
} // namespace br

src/br/interation.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class ServerInteraction {
5151
static butil::Status CreateInteraction(const std::vector<std::string>& addrs,
5252
std::shared_ptr<ServerInteraction>& interaction);
5353

54+
static butil::Status CreateInteraction(const std::string& addrs, std::shared_ptr<ServerInteraction>& interaction);
55+
5456
bool Init(const std::string& addrs);
5557
bool Init(std::vector<std::string> addrs);
5658

@@ -157,8 +159,12 @@ butil::Status ServerInteraction::SendRequest(const std::string& service_name, co
157159

158160
} while (retry_count < FLAGS_br_server_interaction_max_retry);
159161

160-
DINGO_LOG(ERROR) << fmt::format("{} response failed, error: {} {}", api_name,
161-
dingodb::pb::error::Errno_Name(status.error_code()), status.error_cstr());
162+
DINGO_LOG(ERROR) << fmt::format(
163+
"{} response failed, retry_count:{} status.error_code:{}({}) status.error_cstr:{} response.error.errcode:{}({}) "
164+
"response.error.errmsg:{}",
165+
api_name, retry_count, dingodb::pb::error::Errno_Name(status.error_code()), status.error_code(),
166+
status.error_cstr(), dingodb::pb::error::Errno_Name(response.error().errcode()),
167+
static_cast<int64_t>(response.error().errcode()), response.error().errmsg());
162168

163169
return status;
164170
}

src/br/main.cc

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -450,23 +450,37 @@ int main(int argc, char* argv[]) {
450450
if (dingodb::FLAGS_show_version || argc == 1) {
451451
dingodb::DingoShowVerion();
452452
printf(
453-
"Usage: --br_coor_url=[ip:port] --br_type=[backup|restore] --br_backup_type=[full] --backupts='[YYYY-MM-DD "
453+
"Usage: --br_coor_url=[ip:port] --br_type=[backup] --br_backup_type=[full] --backupts='[YYYY-MM-DD "
454454
"HH:MM:SS ]' --storage=local://[path_dir]\n");
455455
printf(
456-
"Usage: --br_coor_url=[file://./conf/coor_list] --br_type=[backup|restore] --br_backup_type=[full] "
456+
"Usage: --br_coor_url=[file://./conf/coor_list] --br_type=[backup] --br_backup_type=[full] "
457457
"--backupts='[YYYY-MM-DD "
458458
"HH:MM:SS ]' --storage=local://[path_dir]\n");
459+
460+
printf(
461+
"Usage: --br_coor_url=[ip:port] --br_type=[restore] --br_restore_type=[full] "
462+
"--storage=local://[path_dir]\n");
463+
printf(
464+
"Usage: --br_coor_url=[file://./conf/coor_list] --br_type=[restore] --br_restore_type=[full] "
465+
"--storage=local://[path_dir]\n");
459466
printf("Example: \n");
460467
printf(
461468
"./dingodb_br --br_coor_url=127.0.0.1:22001 --br_type=backup --br_backup_type=full --backupts='2020-01-01 "
462469
"00:00:00 +08:00' "
463470
"--storage=local:///opt/backup-2020-01-01\n");
464471

465472
printf(
466-
"./dingodb_br --br_coor_url=[file://./conf/coor_list] --br_type=backup --br_backup_type=full "
473+
"./dingodb_br --br_coor_url=file://./conf/coor_list --br_type=backup --br_backup_type=full "
467474
"--backupts='2020-01-01 "
468475
"00:00:00 +08:00' "
469476
"--storage=local:///opt/backup-2020-01-01\n");
477+
printf(
478+
"./dingodb_br --br_coor_url=127.0.0.1:22001 --br_type=restore --br_restore_type=full "
479+
"--storage=local:///opt/backup-2020-01-01\n");
480+
481+
printf(
482+
"./dingodb_br --br_coor_url=file://./conf/coor_list --br_type=restore --br_restore_type=full "
483+
"--storage=local:///opt/backup-2020-01-01\n");
470484
exit(-1);
471485
}
472486

@@ -485,8 +499,8 @@ int main(int argc, char* argv[]) {
485499
butil::Status status;
486500
std::shared_ptr<br::ServerInteraction> coordinator_interaction = std::make_shared<br::ServerInteraction>();
487501
if (br::FLAGS_br_coor_url.empty()) {
488-
DINGO_LOG(WARNING) << "coordinator url is empty, try to use file://./coor_list";
489-
br::FLAGS_br_coor_url = "file://./coor_list";
502+
DINGO_LOG(WARNING) << "coordinator url is empty, try to use file://.conf/coor_list";
503+
br::FLAGS_br_coor_url = "file://./conf/coor_list";
490504

491505
std::string path = br::FLAGS_br_coor_url;
492506
path = path.replace(path.find("file://"), 7, "");

src/br/parameter.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,12 @@ DEFINE_int64(create_region_timeout_s, 60, "restore create region to coordinator
8181
// restore region timeout s (second)
8282
DEFINE_int64(restore_region_timeout_s, 600, "restore region timeout s. default 600s");
8383

84+
// br backup version comparison dingo-store version comparison
85+
DEFINE_bool(backup_strict_version_comparison, true,
86+
"br backup version vs dingo-store version must be consistent. default true.");
87+
88+
// br restore version comparison dingo-store version comparison
89+
DEFINE_bool(restore_strict_version_comparison, true,
90+
"br restore version vs dingo-store version must be consistent. default true.");
91+
8492
} // namespace br

src/br/parameter.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ DECLARE_int64(create_region_timeout_s);
103103
// restore region timeout s (second)
104104
DECLARE_int64(restore_region_timeout_s);
105105

106+
// br backup version comparison dingo-store version comparison
107+
DECLARE_bool(backup_strict_version_comparison);
108+
109+
// br restore version comparison dingo-store version comparison
110+
DECLARE_bool(restore_strict_version_comparison);
111+
106112
} // namespace br
107113

108114
#endif // DINGODB_BR_PARAMETER_H_

0 commit comments

Comments
 (0)