| 4925 | } |
| 4926 | |
| 4927 | void TabletImpl::ExtractIndexData( |
| 4928 | RpcController* controller, |
| 4929 | const ::fedb::api::ExtractIndexDataRequest* request, |
| 4930 | ::fedb::api::GeneralResponse* response, Closure* done) { |
| 4931 | brpc::ClosureGuard done_guard(done); |
| 4932 | std::shared_ptr<::fedb::api::TaskInfo> task_ptr; |
| 4933 | if (request->has_task_info() && request->task_info().IsInitialized()) { |
| 4934 | if (AddOPTask(request->task_info(), |
| 4935 | ::fedb::api::TaskType::kExtractIndexData, |
| 4936 | task_ptr) < 0) { |
| 4937 | response->set_code(-1); |
| 4938 | response->set_msg("add task failed"); |
| 4939 | return; |
| 4940 | } |
| 4941 | } |
| 4942 | do { |
| 4943 | uint32_t tid = request->tid(); |
| 4944 | uint32_t pid = request->pid(); |
| 4945 | std::shared_ptr<Table> table; |
| 4946 | std::shared_ptr<Snapshot> snapshot; |
| 4947 | { |
| 4948 | std::lock_guard<SpinMutex> spin_lock(spin_mutex_); |
| 4949 | table = GetTableUnLock(tid, pid); |
| 4950 | if (!table) { |
| 4951 | PDLOG(WARNING, "table is not exist. tid %u pid %u", tid, pid); |
| 4952 | response->set_code(::fedb::base::ReturnCode::kTableIsNotExist); |
| 4953 | response->set_msg("table is not exist"); |
| 4954 | break; |
| 4955 | } |
| 4956 | if (table->GetTableStat() != ::fedb::storage::kNormal) { |
| 4957 | PDLOG(WARNING, |
| 4958 | "table state is %d, cannot extract index data. tid %u, " |
| 4959 | "pid %u", |
| 4960 | table->GetTableStat(), tid, pid); |
| 4961 | response->set_code( |
| 4962 | ::fedb::base::ReturnCode::kTableStatusIsNotKnormal); |
| 4963 | response->set_msg("table status is not kNormal"); |
| 4964 | break; |
| 4965 | } |
| 4966 | snapshot = GetSnapshotUnLock(tid, pid); |
| 4967 | if (!snapshot) { |
| 4968 | PDLOG(WARNING, "snapshot is not exist. tid %u pid %u", tid, |
| 4969 | pid); |
| 4970 | response->set_code( |
| 4971 | ::fedb::base::ReturnCode::kSnapshotIsNotExist); |
| 4972 | response->set_msg("table snapshot is not exist"); |
| 4973 | break; |
| 4974 | } |
| 4975 | } |
| 4976 | std::shared_ptr<::fedb::storage::MemTableSnapshot> memtable_snapshot = |
| 4977 | std::static_pointer_cast<::fedb::storage::MemTableSnapshot>( |
| 4978 | snapshot); |
| 4979 | task_pool_.AddTask(boost::bind(&TabletImpl::ExtractIndexDataInternal, |
| 4980 | this, table, memtable_snapshot, |
| 4981 | request->column_key(), request->idx(), |
| 4982 | request->partition_num(), task_ptr)); |
| 4983 | response->set_code(::fedb::base::ReturnCode::kOk); |
| 4984 | response->set_msg("ok"); |
no test coverage detected