MCPcopy Create free account
hub / github.com/4paradigm/OpenMLDB / PauseSnapshot

Method PauseSnapshot

src/tablet/tablet_impl.cc:2845–2899  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2843}
2844
2845void TabletImpl::PauseSnapshot(RpcController* controller,
2846 const ::fedb::api::GeneralRequest* request,
2847 ::fedb::api::GeneralResponse* response,
2848 Closure* done) {
2849 brpc::ClosureGuard done_guard(done);
2850 std::shared_ptr<::fedb::api::TaskInfo> task_ptr;
2851 if (request->has_task_info() && request->task_info().IsInitialized()) {
2852 if (AddOPTask(request->task_info(),
2853 ::fedb::api::TaskType::kPauseSnapshot, task_ptr) < 0) {
2854 response->set_code(-1);
2855 response->set_msg("add task failed");
2856 return;
2857 }
2858 }
2859 do {
2860 {
2861 std::lock_guard<SpinMutex> spin_lock(spin_mutex_);
2862 std::shared_ptr<Table> table =
2863 GetTableUnLock(request->tid(), request->pid());
2864 if (!table) {
2865 PDLOG(WARNING, "table is not exist. tid %u, pid %u",
2866 request->tid(), request->pid());
2867 response->set_code(::fedb::base::ReturnCode::kTableIsNotExist);
2868 response->set_msg("table is not exist");
2869 break;
2870 }
2871 if (table->GetTableStat() == ::fedb::storage::kSnapshotPaused) {
2872 PDLOG(INFO,
2873 "table status is kSnapshotPaused, need not pause. "
2874 "tid[%u] pid[%u]",
2875 request->tid(), request->pid());
2876 } else if (table->GetTableStat() != ::fedb::storage::kNormal) {
2877 PDLOG(WARNING,
2878 "table status is [%u], cann't pause. tid[%u] pid[%u]",
2879 table->GetTableStat(), request->tid(), request->pid());
2880 response->set_code(
2881 ::fedb::base::ReturnCode::kTableStatusIsNotKnormal);
2882 response->set_msg("table status is not kNormal");
2883 break;
2884 } else {
2885 table->SetTableStat(::fedb::storage::kSnapshotPaused);
2886 PDLOG(INFO, "table status has set[%u]. tid[%u] pid[%u]",
2887 table->GetTableStat(), request->tid(), request->pid());
2888 }
2889 }
2890 if (task_ptr) {
2891 std::lock_guard<std::mutex> lock(mu_);
2892 task_ptr->set_status(::fedb::api::TaskStatus::kDone);
2893 }
2894 response->set_code(::fedb::base::ReturnCode::kOk);
2895 response->set_msg("ok");
2896 return;
2897 } while (0);
2898 SetTaskStatus(task_ptr, ::fedb::api::TaskStatus::kFailed);
2899}
2900
2901void TabletImpl::RecoverSnapshot(RpcController* controller,
2902 const ::fedb::api::GeneralRequest* request,

Callers 1

TEST_FFunction · 0.45

Calls 2

GetTableStatMethod · 0.80
SetTableStatMethod · 0.80

Tested by 1

TEST_FFunction · 0.36