| 394 | } |
| 395 | |
| 396 | void TabletNodeImpl::LoadTablet(const LoadTabletRequest* request, LoadTabletResponse* response) { |
| 397 | response->set_sequence_id(request->sequence_id()); |
| 398 | std::string sid = GetSessionId(); |
| 399 | if (!request->has_session_id() || (sid.size() == 0) || |
| 400 | request->session_id().compare(0, sid.size(), sid) != 0) { |
| 401 | LOG(WARNING) << "load session id not match: tablet " << request->path() << ", session_id " |
| 402 | << request->session_id() << ", ts_id " << sid; |
| 403 | response->set_status(kIllegalAccess); |
| 404 | return; |
| 405 | } |
| 406 | if (request->schema().locality_groups_size() < 1) { |
| 407 | LOG(WARNING) << "No localitygroups in schema: " << request->tablet_name(); |
| 408 | response->set_status(kIllegalAccess); |
| 409 | return; |
| 410 | } |
| 411 | |
| 412 | const std::string& key_start = request->key_range().key_start(); |
| 413 | const std::string& key_end = request->key_range().key_end(); |
| 414 | const TableSchema& schema = request->schema(); |
| 415 | int64_t create_time = request->create_time(); |
| 416 | uint64_t version = request->version(); |
| 417 | |
| 418 | std::vector<uint64_t> parent_tablets; |
| 419 | for (int i = 0; i < request->parent_tablets_size(); ++i) { |
| 420 | CHECK(i < 2) << "parent_tablets should less than 2: " << i; |
| 421 | parent_tablets.push_back(request->parent_tablets(i)); |
| 422 | } |
| 423 | std::set<std::string> ignore_err_lgs; |
| 424 | for (int i = 0; i < request->ignore_err_lgs_size(); ++i) { |
| 425 | VLOG(10) << "oops lg:" << request->ignore_err_lgs(i); |
| 426 | ignore_err_lgs.insert(request->ignore_err_lgs(i)); |
| 427 | } |
| 428 | |
| 429 | io::TabletIO* tablet_io = NULL; |
| 430 | StatusCode status = kTabletNodeOk; |
| 431 | if (!tablet_manager_->AddTablet(request->tablet_name(), request->path(), key_start, key_end, |
| 432 | create_time, version, &tablet_io, &status)) { |
| 433 | io::TabletIO::TabletStatus tablet_status = tablet_io->GetStatus(); |
| 434 | if (tablet_status == io::TabletIO::TabletStatus::kOnLoad || |
| 435 | tablet_status == io::TabletIO::TabletStatus::kReady) { |
| 436 | VLOG(6) << "ignore this load tablet request, tablet: " << request->path() << " [" |
| 437 | << DebugString(key_start) << ", " << DebugString(key_end) |
| 438 | << "], status: " << StatusCodeToString((StatusCode)tablet_status); |
| 439 | } else { |
| 440 | LOG(ERROR) << "fail to add tablet: " << request->path() << " [" << DebugString(key_start) |
| 441 | << ", " << DebugString(key_end) |
| 442 | << "], status: " << StatusCodeToString((StatusCode)tablet_status); |
| 443 | } |
| 444 | response->set_status((StatusCode)tablet_status); |
| 445 | tablet_io->DecRef(); |
| 446 | } else { |
| 447 | LOG(INFO) << "start load tablet, id: " << request->sequence_id() << ", sessionid " |
| 448 | << request->session_id() << ", ts_id " << sid << ", table: " << request->tablet_name() |
| 449 | << ", range: [" << DebugString(key_start) << ", " << DebugString(key_end) |
| 450 | << "], path: " << request->path() << ", ctimestamp(us): " << create_time |
| 451 | << ", version: " << version << ", parent: " |
| 452 | << (request->parent_tablets_size() > 0 ? request->parent_tablets(0) : 0) |
| 453 | << ", schema: " << request->schema().ShortDebugString(); |