This repository has been archived by the owner on Jun 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(one-time backup): part-1 meta server handle rpc and init backup
- Loading branch information
1 parent
6528eb6
commit d03d910
Showing
8 changed files
with
246 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// 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 <dsn/dist/fmt_logging.h> | ||
|
||
#include "common/backup_utils.h" | ||
#include "server_state.h" | ||
|
||
namespace dsn { | ||
namespace replication { | ||
|
||
backup_engine::backup_engine(backup_service *service) | ||
: _backup_service(service), _block_service(nullptr) | ||
{ | ||
} | ||
|
||
backup_engine::~backup_engine() { _tracker.cancel_outstanding_tasks(); } | ||
|
||
error_code backup_engine::get_app_stat(int32_t app_id, std::shared_ptr<app_state> &app) | ||
{ | ||
zauto_read_lock l; | ||
_backup_service->get_state()->lock_read(l); | ||
app = _backup_service->get_state()->get_app(app_id); | ||
if (app == nullptr || app->status != app_status::AS_AVAILABLE) { | ||
derror_f("app {} is not available, couldn't do backup now.", app_id); | ||
return ERR_INVALID_STATE; | ||
} | ||
return ERR_OK; | ||
} | ||
|
||
error_code backup_engine::init_backup(int32_t app_id) | ||
{ | ||
std::shared_ptr<app_state> app; | ||
error_code err = get_app_stat(app_id, app); | ||
if (err != ERR_OK) { | ||
return err; | ||
} | ||
|
||
zauto_lock lock(_lock); | ||
_backup_status.clear(); | ||
for (int i = 0; i < app->partition_count; ++i) { | ||
_backup_status.emplace(i, backup_status::UNALIVE); | ||
} | ||
_cur_backup.app_id = app_id; | ||
_cur_backup.app_name = app->app_name; | ||
_cur_backup.backup_id = static_cast<int64_t>(dsn_now_ms()); | ||
_cur_backup.start_time_ms = _cur_backup.backup_id; | ||
return ERR_OK; | ||
} | ||
|
||
error_code backup_engine::set_block_service(const std::string &provider) | ||
{ | ||
_provider_type = provider; | ||
_block_service = _backup_service->get_meta_service() | ||
->get_block_service_manager() | ||
.get_or_create_block_filesystem(provider); | ||
if (_block_service == nullptr) { | ||
return ERR_INVALID_PARAMETERS; | ||
} | ||
return ERR_OK; | ||
} | ||
|
||
error_code backup_engine::run() { return ERR_OK; } | ||
|
||
bool backup_engine::is_backing_up() | ||
{ | ||
zauto_lock l(_lock); | ||
return _cur_backup.end_time_ms == 0 && !_cur_backup.is_backup_failed; | ||
} | ||
|
||
} // namespace replication | ||
} // namespace dsn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// 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 <dsn/cpp/json_helper.h> | ||
#include <dsn/dist/block_service.h> | ||
#include <dsn/tool-api/zlocks.h> | ||
|
||
namespace dsn { | ||
namespace replication { | ||
|
||
enum backup_status | ||
{ | ||
UNALIVE = 1, | ||
ALIVE = 2, | ||
COMPLETED = 3, | ||
FAILED = 4 | ||
}; | ||
|
||
struct app_backup_info | ||
{ | ||
int64_t backup_id; | ||
int64_t start_time_ms; | ||
int64_t end_time_ms; | ||
|
||
bool is_backup_failed; | ||
|
||
int32_t app_id; | ||
std::string app_name; | ||
|
||
app_backup_info() : backup_id(0), start_time_ms(0), end_time_ms(0), is_backup_failed(false) {} | ||
|
||
DEFINE_JSON_SERIALIZATION(backup_id, start_time_ms, end_time_ms, app_id, app_name) | ||
}; | ||
|
||
class app_state; | ||
class backup_service; | ||
|
||
class backup_engine | ||
{ | ||
public: | ||
backup_engine(backup_service *service); | ||
~backup_engine(); | ||
|
||
error_code init_backup(int32_t app_id); | ||
error_code set_block_service(const std::string &provider); | ||
|
||
error_code run(); | ||
|
||
int64_t get_current_backup_id() { return _cur_backup.backup_id; } | ||
int32_t get_backup_app_id() { return _cur_backup.app_id; } | ||
bool is_backing_up(); | ||
|
||
private: | ||
error_code get_app_stat(int32_t app_id, std::shared_ptr<app_state> &app); | ||
|
||
backup_service *_backup_service; | ||
dist::block_service::block_filesystem *_block_service; | ||
std::string _provider_type; | ||
dsn::task_tracker _tracker; | ||
|
||
// lock _cur_backup and _backup_status. | ||
dsn::zlock _lock; | ||
app_backup_info _cur_backup; | ||
// partition_id -> backup_status | ||
std::map<int32_t, backup_status> _backup_status; | ||
}; | ||
|
||
} // namespace replication | ||
} // namespace dsn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters