Skip to content

Commit f67ee64

Browse files
yuhaijun999ketor
authored andcommitted
[feat][br] Allow dingo-store to be backed up without an index document node.
1 parent 4c27a76 commit f67ee64

File tree

10 files changed

+326
-176
lines changed

10 files changed

+326
-176
lines changed

src/br/backup.cc

Lines changed: 141 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,18 @@ butil::Status Backup::DoRun() {
306306
std::vector<std::string> coordinator_addrs =
307307
br::InteractionManager::GetInstance().GetCoordinatorInteraction()->GetAddrs();
308308

309-
std::vector<std::string> store_addrs = br::InteractionManager::GetInstance().GetStoreInteraction()->GetAddrs();
309+
std::vector<std::string> store_addrs = br::InteractionManager::GetInstance().GetStoreInteraction() != nullptr
310+
? br::InteractionManager::GetInstance().GetStoreInteraction()->GetAddrs()
311+
: std::vector<std::string>();
310312

311-
std::vector<std::string> index_addrs = br::InteractionManager::GetInstance().GetIndexInteraction()->GetAddrs();
313+
std::vector<std::string> index_addrs = br::InteractionManager::GetInstance().GetIndexInteraction() != nullptr
314+
? br::InteractionManager::GetInstance().GetIndexInteraction()->GetAddrs()
315+
: std::vector<std::string>();
312316

313-
std::vector<std::string> document_addrs = br::InteractionManager::GetInstance().GetDocumentInteraction()->GetAddrs();
317+
std::vector<std::string> document_addrs =
318+
br::InteractionManager::GetInstance().GetDocumentInteraction() != nullptr
319+
? br::InteractionManager::GetInstance().GetDocumentInteraction()->GetAddrs()
320+
: std::vector<std::string>();
314321

315322
// create backup meta
316323
{
@@ -322,24 +329,30 @@ butil::Status Backup::DoRun() {
322329
}
323330

324331
std::shared_ptr<br::ServerInteraction> store_interaction;
325-
status = ServerInteraction::CreateInteraction(store_addrs, store_interaction);
326-
if (!status.ok()) {
327-
DINGO_LOG(ERROR) << Utils::FormatStatusError(status);
328-
return status;
332+
if (!store_addrs.empty()) {
333+
status = ServerInteraction::CreateInteraction(store_addrs, store_interaction);
334+
if (!status.ok()) {
335+
DINGO_LOG(ERROR) << Utils::FormatStatusError(status);
336+
return status;
337+
}
329338
}
330339

331340
std::shared_ptr<br::ServerInteraction> index_interaction;
332-
status = ServerInteraction::CreateInteraction(index_addrs, index_interaction);
333-
if (!status.ok()) {
334-
DINGO_LOG(ERROR) << Utils::FormatStatusError(status);
335-
return status;
341+
if (!index_addrs.empty()) {
342+
status = ServerInteraction::CreateInteraction(index_addrs, index_interaction);
343+
if (!status.ok()) {
344+
DINGO_LOG(ERROR) << Utils::FormatStatusError(status);
345+
return status;
346+
}
336347
}
337348

338349
std::shared_ptr<br::ServerInteraction> document_interaction;
339-
status = ServerInteraction::CreateInteraction(document_addrs, document_interaction);
340-
if (!status.ok()) {
341-
DINGO_LOG(ERROR) << Utils::FormatStatusError(status);
342-
return status;
350+
if (!document_addrs.empty()) {
351+
status = ServerInteraction::CreateInteraction(document_addrs, document_interaction);
352+
if (!status.ok()) {
353+
DINGO_LOG(ERROR) << Utils::FormatStatusError(status);
354+
return status;
355+
}
343356
}
344357

345358
backup_meta_ =
@@ -366,24 +379,30 @@ butil::Status Backup::DoRun() {
366379
}
367380

368381
std::shared_ptr<br::ServerInteraction> store_interaction;
369-
status = ServerInteraction::CreateInteraction(store_addrs, store_interaction);
370-
if (!status.ok()) {
371-
DINGO_LOG(ERROR) << Utils::FormatStatusError(status);
372-
return status;
382+
if (!store_addrs.empty()) {
383+
status = ServerInteraction::CreateInteraction(store_addrs, store_interaction);
384+
if (!status.ok()) {
385+
DINGO_LOG(ERROR) << Utils::FormatStatusError(status);
386+
return status;
387+
}
373388
}
374389

375390
std::shared_ptr<br::ServerInteraction> index_interaction;
376-
status = ServerInteraction::CreateInteraction(index_addrs, index_interaction);
377-
if (!status.ok()) {
378-
DINGO_LOG(ERROR) << Utils::FormatStatusError(status);
379-
return status;
391+
if (!index_addrs.empty()) {
392+
status = ServerInteraction::CreateInteraction(index_addrs, index_interaction);
393+
if (!status.ok()) {
394+
DINGO_LOG(ERROR) << Utils::FormatStatusError(status);
395+
return status;
396+
}
380397
}
381398

382399
std::shared_ptr<br::ServerInteraction> document_interaction;
383-
status = ServerInteraction::CreateInteraction(document_addrs, document_interaction);
384-
if (!status.ok()) {
385-
DINGO_LOG(ERROR) << Utils::FormatStatusError(status);
386-
return status;
400+
if (!document_addrs.empty()) {
401+
status = ServerInteraction::CreateInteraction(document_addrs, document_interaction);
402+
if (!status.ok()) {
403+
DINGO_LOG(ERROR) << Utils::FormatStatusError(status);
404+
return status;
405+
}
387406
}
388407

389408
backup_data_ =
@@ -1052,6 +1071,14 @@ butil::Status Backup::EnableBalanceToCoordinator(ServerInteractionPtr coordinato
10521071

10531072
butil::Status Backup::DisableSplitAndMergeToStoreAndIndex(ServerInteractionPtr store_interaction,
10541073
ServerInteractionPtr index_interaction) {
1074+
bool is_exist_store = (store_interaction != nullptr ? !store_interaction->IsEmpty() : false);
1075+
bool is_exist_index = (index_interaction != nullptr ? !index_interaction->IsEmpty() : false);
1076+
1077+
if (!is_exist_store && !is_exist_index) {
1078+
DINGO_LOG(INFO) << "Store and Index not exist, skip DisableSplitAndMergeToStoreAndIndex";
1079+
return butil::Status::OK();
1080+
}
1081+
10551082
dingodb::pb::store::ControlConfigRequest request;
10561083
dingodb::pb::store::ControlConfigResponse response;
10571084

@@ -1067,72 +1094,86 @@ butil::Status Backup::DisableSplitAndMergeToStoreAndIndex(ServerInteractionPtr s
10671094
config_auto_merge.set_value("false");
10681095
request.mutable_control_config_variable()->Add(std::move(config_auto_merge));
10691096

1070-
DINGO_LOG_IF(INFO, FLAGS_br_log_switch_backup_detail_detail) << request.DebugString();
1071-
1072-
butil::Status status = store_interaction->AllSendRequest("StoreService", "ControlConfig", request, response);
1073-
if (!status.ok()) {
1074-
DINGO_LOG(ERROR) << Utils::FormatStatusError(status);
1075-
return status;
1076-
}
1077-
1078-
if (response.error().errcode() != dingodb::pb::error::OK) {
1079-
DINGO_LOG(ERROR) << Utils::FormatResponseError(response);
1080-
return butil::Status(response.error().errcode(), response.error().errmsg());
1081-
}
1082-
1083-
for (const auto& config : response.control_config_variable()) {
1084-
if (config.is_error_occurred()) {
1085-
DINGO_LOG(ERROR) << "ControlConfig not support variable: " << config.name() << " skip.";
1086-
return butil::Status(dingodb::pb::error::EINTERNAL, "ControlConfig not support variable: %s skip.",
1087-
config.name().c_str());
1088-
}
1097+
// store exist
1098+
if (is_exist_store) {
1099+
DINGO_LOG_IF(INFO, FLAGS_br_log_switch_backup_detail_detail) << request.DebugString();
10891100

1090-
if (!config.is_already_set() && config.name() == "FLAGS_region_enable_auto_split") {
1091-
region_auto_split_enable_after_finish_ = true;
1101+
butil::Status status = store_interaction->AllSendRequest("StoreService", "ControlConfig", request, response);
1102+
if (!status.ok()) {
1103+
DINGO_LOG(ERROR) << Utils::FormatStatusError(status);
1104+
return status;
10921105
}
10931106

1094-
if (!config.is_already_set() && config.name() == "FLAGS_region_enable_auto_merge") {
1095-
region_auto_merge_enable_after_finish_ = true;
1107+
if (response.error().errcode() != dingodb::pb::error::OK) {
1108+
DINGO_LOG(ERROR) << Utils::FormatResponseError(response);
1109+
return butil::Status(response.error().errcode(), response.error().errmsg());
10961110
}
1097-
}
10981111

1099-
DINGO_LOG_IF(INFO, FLAGS_br_log_switch_backup_detail_detail) << response.DebugString();
1112+
for (const auto& config : response.control_config_variable()) {
1113+
if (config.is_error_occurred()) {
1114+
DINGO_LOG(ERROR) << "ControlConfig not support variable: " << config.name() << " skip.";
1115+
return butil::Status(dingodb::pb::error::EINTERNAL, "ControlConfig not support variable: %s skip.",
1116+
config.name().c_str());
1117+
}
11001118

1101-
DINGO_LOG_IF(INFO, FLAGS_br_log_switch_backup_detail_detail) << request.DebugString();
1119+
if (!config.is_already_set() && config.name() == "FLAGS_region_enable_auto_split") {
1120+
region_auto_split_enable_after_finish_ = true;
1121+
}
11021122

1103-
status = index_interaction->AllSendRequest("IndexService", "ControlConfig", request, response);
1104-
if (!status.ok()) {
1105-
DINGO_LOG(ERROR) << Utils::FormatStatusError(status);
1106-
return status;
1107-
}
1123+
if (!config.is_already_set() && config.name() == "FLAGS_region_enable_auto_merge") {
1124+
region_auto_merge_enable_after_finish_ = true;
1125+
}
1126+
}
11081127

1109-
if (response.error().errcode() != dingodb::pb::error::OK) {
1110-
DINGO_LOG(ERROR) << Utils::FormatResponseError(response);
1111-
return butil::Status(response.error().errcode(), response.error().errmsg());
1112-
}
1128+
DINGO_LOG_IF(INFO, FLAGS_br_log_switch_backup_detail_detail) << response.DebugString();
1129+
} // if (is_exist_store) {
11131130

1114-
DINGO_LOG_IF(INFO, FLAGS_br_log_switch_backup_detail_detail) << response.DebugString();
1131+
// index exist
1132+
if (is_exist_index) {
1133+
DINGO_LOG_IF(INFO, FLAGS_br_log_switch_backup_detail_detail) << request.DebugString();
11151134

1116-
for (const auto& config : response.control_config_variable()) {
1117-
if (config.is_error_occurred()) {
1118-
DINGO_LOG(ERROR) << "ControlConfig not support variable: " << config.name() << " skip.";
1119-
return butil::Status(dingodb::pb::error::EINTERNAL, "ControlConfig not support variable: %s skip.",
1120-
config.name().c_str());
1135+
butil::Status status = index_interaction->AllSendRequest("IndexService", "ControlConfig", request, response);
1136+
if (!status.ok()) {
1137+
DINGO_LOG(ERROR) << Utils::FormatStatusError(status);
1138+
return status;
11211139
}
11221140

1123-
if (!config.is_already_set() && config.name() == "FLAGS_region_enable_auto_split") {
1124-
region_auto_split_enable_after_finish_ = true;
1141+
if (response.error().errcode() != dingodb::pb::error::OK) {
1142+
DINGO_LOG(ERROR) << Utils::FormatResponseError(response);
1143+
return butil::Status(response.error().errcode(), response.error().errmsg());
11251144
}
11261145

1127-
if (!config.is_already_set() && config.name() == "FLAGS_region_enable_auto_merge") {
1128-
region_auto_merge_enable_after_finish_ = true;
1146+
DINGO_LOG_IF(INFO, FLAGS_br_log_switch_backup_detail_detail) << response.DebugString();
1147+
1148+
for (const auto& config : response.control_config_variable()) {
1149+
if (config.is_error_occurred()) {
1150+
DINGO_LOG(ERROR) << "ControlConfig not support variable: " << config.name() << " skip.";
1151+
return butil::Status(dingodb::pb::error::EINTERNAL, "ControlConfig not support variable: %s skip.",
1152+
config.name().c_str());
1153+
}
1154+
1155+
if (!config.is_already_set() && config.name() == "FLAGS_region_enable_auto_split") {
1156+
region_auto_split_enable_after_finish_ = true;
1157+
}
1158+
1159+
if (!config.is_already_set() && config.name() == "FLAGS_region_enable_auto_merge") {
1160+
region_auto_merge_enable_after_finish_ = true;
1161+
}
11291162
}
1130-
}
1163+
} // if (is_exist_index) {
11311164

11321165
return butil::Status::OK();
11331166
}
11341167
butil::Status Backup::EnableSplitAndMergeToStoreAndIndex(ServerInteractionPtr store_interaction,
11351168
ServerInteractionPtr index_interaction) const {
1169+
bool is_exist_store = (store_interaction != nullptr ? !store_interaction->IsEmpty() : false);
1170+
bool is_exist_index = (index_interaction != nullptr ? !index_interaction->IsEmpty() : false);
1171+
1172+
if (!is_exist_store && !is_exist_index) {
1173+
DINGO_LOG(INFO) << "Store and Index not exist, skip EnableSplitAndMergeToStoreAndIndex";
1174+
return butil::Status::OK();
1175+
}
1176+
11361177
dingodb::pb::store::ControlConfigRequest request;
11371178
dingodb::pb::store::ControlConfigResponse response;
11381179

@@ -1153,30 +1194,37 @@ butil::Status Backup::EnableSplitAndMergeToStoreAndIndex(ServerInteractionPtr st
11531194
if (!request.control_config_variable().empty()) {
11541195
request.mutable_request_info()->set_request_id(br::Helper::GetRandInt());
11551196

1156-
DINGO_LOG_IF(INFO, FLAGS_br_log_switch_backup_detail_detail) << request.DebugString();
1197+
if (is_exist_store) {
1198+
DINGO_LOG_IF(INFO, FLAGS_br_log_switch_backup_detail_detail) << request.DebugString();
11571199

1158-
butil::Status status = store_interaction->AllSendRequest("StoreService", "ControlConfig", request, response);
1159-
if (!status.ok()) {
1160-
DINGO_LOG(ERROR) << Utils::FormatStatusError(status);
1161-
return status;
1162-
}
1200+
butil::Status status = store_interaction->AllSendRequest("StoreService", "ControlConfig", request, response);
1201+
if (!status.ok()) {
1202+
DINGO_LOG(ERROR) << Utils::FormatStatusError(status);
1203+
return status;
1204+
}
11631205

1164-
if (response.error().errcode() != dingodb::pb::error::OK) {
1165-
DINGO_LOG(ERROR) << Utils::FormatResponseError(response);
1166-
return butil::Status(response.error().errcode(), response.error().errmsg());
1167-
}
1206+
if (response.error().errcode() != dingodb::pb::error::OK) {
1207+
DINGO_LOG(ERROR) << Utils::FormatResponseError(response);
1208+
return butil::Status(response.error().errcode(), response.error().errmsg());
1209+
}
1210+
DINGO_LOG_IF(INFO, FLAGS_br_log_switch_backup_detail_detail) << response.DebugString();
1211+
} // if (is_exist_store) {
11681212

1169-
status = index_interaction->AllSendRequest("IndexService", "ControlConfig", request, response);
1170-
if (!status.ok()) {
1171-
DINGO_LOG(ERROR) << Utils::FormatStatusError(status);
1172-
return status;
1173-
}
1174-
if (response.error().errcode() != dingodb::pb::error::OK) {
1175-
DINGO_LOG(ERROR) << Utils::FormatResponseError(response);
1176-
return butil::Status(response.error().errcode(), response.error().errmsg());
1177-
}
1213+
if (is_exist_index) {
1214+
DINGO_LOG_IF(INFO, FLAGS_br_log_switch_backup_detail_detail) << request.DebugString();
11781215

1179-
DINGO_LOG_IF(INFO, FLAGS_br_log_switch_backup_detail_detail) << response.DebugString();
1216+
butil::Status status = index_interaction->AllSendRequest("IndexService", "ControlConfig", request, response);
1217+
if (!status.ok()) {
1218+
DINGO_LOG(ERROR) << Utils::FormatStatusError(status);
1219+
return status;
1220+
}
1221+
if (response.error().errcode() != dingodb::pb::error::OK) {
1222+
DINGO_LOG(ERROR) << Utils::FormatResponseError(response);
1223+
return butil::Status(response.error().errcode(), response.error().errmsg());
1224+
}
1225+
1226+
DINGO_LOG_IF(INFO, FLAGS_br_log_switch_backup_detail_detail) << response.DebugString();
1227+
}
11801228
}
11811229
return butil::Status::OK();
11821230
}

0 commit comments

Comments
 (0)