hycdong commented on code in PR #1128: URL: https://github.com/apache/incubator-pegasus/pull/1128#discussion_r952351942
########## src/rdsn/src/replica/backup/replica_backup_manager.cpp: ########## @@ -15,21 +15,182 @@ // specific language governing permissions and limitations // under the License. -#include "replica_backup_manager.h" -#include "replica/replica.h" - #include <dsn/dist/fmt_logging.h> -#include <dsn/utility/filesystem.h> -#include <dsn/dist/replication/replication_app_base.h> +#include <dsn/utility/fail_point.h> + +#include "replica_backup_manager.h" namespace dsn { namespace replication { // TODO(heyuchen): implement it -replica_backup_manager::replica_backup_manager(replica *r) : replica_base(r), _replica(r) {} +replica_backup_manager::replica_backup_manager(replica *r) + : replica_base(r), _replica(r), _stub(r->get_replica_stub()) +{ +} replica_backup_manager::~replica_backup_manager() {} +// ThreadPool: THREAD_POOL_REPLICATION +void replica_backup_manager::on_backup(const backup_request &request, + /*out*/ backup_response &response) +{ + // TODO(heyuchen): add other status + + if (request.status == backup_status::CHECKPOINTING) { + try_to_checkpoint(request.backup_id, response); + return; + } +} + +// ThreadPool: THREAD_POOL_REPLICATION +void replica_backup_manager::try_to_checkpoint(const int64_t &backup_id, + /*out*/ backup_response &response) +{ + switch (_status) { + case backup_status::UNINITIALIZED: + start_checkpointing(backup_id, response); + break; + case backup_status::CHECKPOINTING: + case backup_status::CHECKPOINTED: + report_checkpointing(response); + break; + default: + response.err = ERR_INVALID_STATE; + derror_replica("invalid local status({}) while request status = {}", + enum_to_string(_status), + enum_to_string(backup_status::CHECKPOINTING)); + break; + } +} + +// ThreadPool: THREAD_POOL_REPLICATION +void replica_backup_manager::start_checkpointing(int64_t backup_id, + /*out*/ backup_response &response) +{ + FAIL_POINT_INJECT_F("replica_backup_start_checkpointing", [&](dsn::string_view) { + _status = backup_status::CHECKPOINTING; + response.err = ERR_OK; + }); + + ddebug_replica("start to checkpoint, backup_id = {}", backup_id); + zauto_write_lock l(_lock); Review Comment: I think it's okay in this pr, this needs to add a read lock, but it will add lock in `on_backup` function, will be added in future pr. -- 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. To unsubscribe, e-mail: dev-unsubscr...@pegasus.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@pegasus.apache.org For additional commands, e-mail: dev-h...@pegasus.apache.org