| 2957 | } |
| 2958 | |
| 2959 | void TabletImpl::LoadTable(RpcController* controller, |
| 2960 | const ::fedb::api::LoadTableRequest* request, |
| 2961 | ::fedb::api::GeneralResponse* response, |
| 2962 | Closure* done) { |
| 2963 | brpc::ClosureGuard done_guard(done); |
| 2964 | std::shared_ptr<::fedb::api::TaskInfo> task_ptr; |
| 2965 | if (request->has_task_info() && request->task_info().IsInitialized()) { |
| 2966 | if (AddOPTask(request->task_info(), ::fedb::api::TaskType::kLoadTable, |
| 2967 | task_ptr) < 0) { |
| 2968 | response->set_code(-1); |
| 2969 | response->set_msg("add task failed"); |
| 2970 | return; |
| 2971 | } |
| 2972 | } |
| 2973 | do { |
| 2974 | ::fedb::api::TableMeta table_meta; |
| 2975 | table_meta.CopyFrom(request->table_meta()); |
| 2976 | uint32_t tid = table_meta.tid(); |
| 2977 | uint32_t pid = table_meta.pid(); |
| 2978 | std::string msg; |
| 2979 | if (CheckTableMeta(&table_meta, msg) != 0) { |
| 2980 | response->set_code( |
| 2981 | ::fedb::base::ReturnCode::kTableMetaIsIllegal); |
| 2982 | response->set_msg(msg); |
| 2983 | PDLOG(WARNING, "CheckTableMeta failed. tid %u, pid %u", tid, |
| 2984 | pid); |
| 2985 | break; |
| 2986 | } |
| 2987 | std::string root_path; |
| 2988 | bool ok = |
| 2989 | ChooseDBRootPath(tid, pid, root_path); |
| 2990 | if (!ok) { |
| 2991 | response->set_code(::fedb::base::ReturnCode::kFailToGetDbRootPath); |
| 2992 | response->set_msg("fail to get table db root path"); |
| 2993 | PDLOG(WARNING, "table db path is not found. tid %u, pid %u", tid, |
| 2994 | pid); |
| 2995 | break; |
| 2996 | } |
| 2997 | |
| 2998 | std::string db_path = |
| 2999 | root_path + "/" + std::to_string(tid) + "_" + std::to_string(pid); |
| 3000 | if (!::fedb::base::IsExists(db_path)) { |
| 3001 | PDLOG(WARNING, |
| 3002 | "table db path is not exist. tid %u, pid %u, path %s", tid, |
| 3003 | pid, db_path.c_str()); |
| 3004 | response->set_code( |
| 3005 | ::fedb::base::ReturnCode::kTableDbPathIsNotExist); |
| 3006 | response->set_msg("table db path is not exist"); |
| 3007 | break; |
| 3008 | } |
| 3009 | |
| 3010 | std::shared_ptr<Table> table = GetTable(tid, pid); |
| 3011 | if (table) { |
| 3012 | PDLOG(WARNING, "table with tid[%u] and pid[%u] exists", tid, pid); |
| 3013 | response->set_code(::fedb::base::ReturnCode::kTableAlreadyExists); |
| 3014 | response->set_msg("table already exists"); |
| 3015 | break; |
| 3016 | } |