Skip to content

Commit

Permalink
feat(backup): 1. remove pervious implementation (#1956)
Browse files Browse the repository at this point in the history
This pr removes some previous backup implementation, because the enhancement code
is strongly different with the current one. Besides, this pr also disable related unit tests
and function tests.
  • Loading branch information
ninsmiracle authored Apr 10, 2024
1 parent 38fa72e commit 3a9a3c4
Show file tree
Hide file tree
Showing 35 changed files with 85 additions and 7,059 deletions.
1,773 changes: 9 additions & 1,764 deletions src/meta/meta_backup_service.cpp

Large diffs are not rendered by default.

405 changes: 10 additions & 395 deletions src/meta/meta_backup_service.h

Large diffs are not rendered by default.

53 changes: 2 additions & 51 deletions src/meta/meta_http_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <unordered_map>
#include <utility>

#include "backup_types.h"
#include "bulk_load_types.h"
#include "common//duplication_common.h"
#include "common/bulk_load_common.h"
Expand All @@ -39,9 +38,7 @@
#include "duplication_types.h"
#include "http/http_status_code.h"
#include "meta/duplication/meta_duplication_service.h"
#include "meta/meta_backup_service.h"
#include "meta/meta_bulk_load_service.h"
#include "meta/meta_rpc_types.h"
#include "meta/meta_service.h"
#include "meta_admin_types.h"
#include "meta_http_service.h"
Expand Down Expand Up @@ -553,54 +550,8 @@ std::string set_to_string(const std::set<int32_t> &s)
return out.str();
}

void meta_http_service::query_backup_policy_handler(const http_request &req, http_response &resp)
{
if (!redirect_if_not_primary(req, resp))
return;

if (_service->_backup_handler == nullptr) {
resp.body = "cold_backup_disabled";
resp.status_code = http_status_code::kNotFound;
return;
}
auto request = std::make_unique<configuration_query_backup_policy_request>();
std::vector<std::string> policy_names;
for (const auto &p : req.query_args) {
if (p.first == "name") {
policy_names.push_back(p.second);
} else {
resp.body = "Invalid parameter";
resp.status_code = http_status_code::kBadRequest;
return;
}
}
request->policy_names = std::move(policy_names);
query_backup_policy_rpc http_to_rpc(std::move(request), LPC_DEFAULT_CALLBACK);
_service->_backup_handler->query_backup_policy(http_to_rpc);
auto rpc_return = http_to_rpc.response();

dsn::utils::table_printer tp_query_backup_policy;
tp_query_backup_policy.add_title("name");
tp_query_backup_policy.add_column("backup_provider_type");
tp_query_backup_policy.add_column("backup_interval");
tp_query_backup_policy.add_column("app_ids");
tp_query_backup_policy.add_column("start_time");
tp_query_backup_policy.add_column("status");
tp_query_backup_policy.add_column("backup_history_count");
for (const auto &cur_policy : rpc_return.policys) {
tp_query_backup_policy.add_row(cur_policy.policy_name);
tp_query_backup_policy.append_data(cur_policy.backup_provider_type);
tp_query_backup_policy.append_data(cur_policy.backup_interval_seconds);
tp_query_backup_policy.append_data(set_to_string(cur_policy.app_ids));
tp_query_backup_policy.append_data(cur_policy.start_time);
tp_query_backup_policy.append_data(cur_policy.is_disable ? "disabled" : "enabled");
tp_query_backup_policy.append_data(cur_policy.backup_history_count_to_keep);
}
std::ostringstream out;
tp_query_backup_policy.output(out, dsn::utils::table_printer::output_format::kJsonCompact);
resp.body = out.str();
resp.status_code = http_status_code::kOk;
}
// TODO(heyuchen): implement it
void meta_http_service::query_backup_policy_handler(const http_request &req, http_response &resp) {}

void meta_http_service::query_duplication_handler(const http_request &req, http_response &resp)
{
Expand Down
84 changes: 11 additions & 73 deletions src/meta/meta_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,7 @@ error_code meta_service::start()
_backup_handler = std::make_shared<backup_service>(
this,
utils::filesystem::concat_path_unix_style(_cluster_root, "backup"),
FLAGS_cold_backup_root,
[](backup_service *bs) { return std::make_shared<policy_context>(bs); });
FLAGS_cold_backup_root);
}

_bulk_load_svc = std::make_unique<bulk_load_service>(
Expand Down Expand Up @@ -902,59 +901,14 @@ void meta_service::on_start_restore(dsn::message_ex *req)
LPC_RESTORE_BACKGROUND, nullptr, std::bind(&server_state::restore_app, _state.get(), req));
}

void meta_service::on_add_backup_policy(dsn::message_ex *req)
{
configuration_add_backup_policy_response response;
if (!check_status_and_authz_with_reply(req, response)) {
return;
}
// TODO(heyuchen): implement it
void meta_service::on_add_backup_policy(dsn::message_ex *req) {}

if (_backup_handler == nullptr) {
LOG_ERROR("meta doesn't enable backup service");
response.err = ERR_SERVICE_NOT_ACTIVE;
reply(req, response);
} else {
req->add_ref();
tasking::enqueue(LPC_DEFAULT_CALLBACK,
nullptr,
std::bind(&backup_service::add_backup_policy, _backup_handler.get(), req));
}
}
// TODO(heyuchen): implement it
void meta_service::on_query_backup_policy(query_backup_policy_rpc policy_rpc) {}

void meta_service::on_query_backup_policy(query_backup_policy_rpc policy_rpc)
{
if (!check_status_and_authz(policy_rpc)) {
return;
}

auto &response = policy_rpc.response();
if (_backup_handler == nullptr) {
LOG_ERROR("meta doesn't enable backup service");
response.err = ERR_SERVICE_NOT_ACTIVE;
} else {
tasking::enqueue(
LPC_DEFAULT_CALLBACK,
nullptr,
std::bind(&backup_service::query_backup_policy, _backup_handler.get(), policy_rpc));
}
}

void meta_service::on_modify_backup_policy(configuration_modify_backup_policy_rpc rpc)
{
if (!check_status_and_authz(rpc)) {
return;
}

if (_backup_handler == nullptr) {
LOG_ERROR("meta doesn't enable backup service");
rpc.response().err = ERR_SERVICE_NOT_ACTIVE;
} else {
tasking::enqueue(
LPC_DEFAULT_CALLBACK,
nullptr,
std::bind(&backup_service::modify_backup_policy, _backup_handler.get(), rpc));
}
}
// TODO(heyuchen): implement it
void meta_service::on_modify_backup_policy(configuration_modify_backup_policy_rpc rpc) {}

void meta_service::on_report_restore_status(configuration_report_restore_status_rpc rpc)
{
Expand Down Expand Up @@ -1256,27 +1210,11 @@ void meta_service::on_clear_bulk_load(clear_bulk_load_rpc rpc)
server_state::sStateHash);
}

void meta_service::on_start_backup_app(start_backup_app_rpc rpc)
{
CHECK_APP_ID_STATUS_AND_AUTHZ(rpc.request().app_id);
if (_backup_handler == nullptr) {
LOG_ERROR("meta doesn't enable backup service");
rpc.response().err = ERR_SERVICE_NOT_ACTIVE;
return;
}
_backup_handler->start_backup_app(std::move(rpc));
}
// TODO(heyuchen): implement it
void meta_service::on_start_backup_app(start_backup_app_rpc rpc) {}

void meta_service::on_query_backup_status(query_backup_status_rpc rpc)
{
CHECK_APP_ID_STATUS_AND_AUTHZ(rpc.request().app_id);
if (_backup_handler == nullptr) {
LOG_ERROR("meta doesn't enable backup service");
rpc.response().err = ERR_SERVICE_NOT_ACTIVE;
return;
}
_backup_handler->query_backup_status(std::move(rpc));
}
// TODO(heyuchen): implement it
void meta_service::on_query_backup_status(query_backup_status_rpc rpc) {}

size_t meta_service::get_alive_node_count() const
{
Expand Down
9 changes: 5 additions & 4 deletions src/meta/meta_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,12 @@ class meta_service : public serverlet<meta_service>
bool check_freeze() const;

private:
friend class backup_engine_test;
friend class backup_service_test;
// TODO(heyuchen): update it
// friend class backup_engine_test;
// friend class backup_service_test;
friend class bulk_load_service_test;
friend class meta_backup_service_test;
friend class meta_backup_test_base;
// friend class meta_backup_service_test;
// friend class meta_backup_test_base;
friend class meta_duplication_service;
friend class meta_http_service;
friend class meta_http_service_test;
Expand Down
Loading

0 comments on commit 3a9a3c4

Please sign in to comment.