| 2445 | } |
| 2446 | |
| 2447 | void MasterImpl::QueryTabletNodeCallback(std::string addr, QueryRequest *req, QueryResponse *res, |
| 2448 | bool failed, int error_code) { |
| 2449 | std::unique_ptr<QueryRequest> request{req}; |
| 2450 | std::unique_ptr<QueryResponse> response{res}; |
| 2451 | bool in_safemode = IsInSafeMode(); |
| 2452 | int64_t query_callback_start = get_micros(); |
| 2453 | const int64_t fuzzy_time = FLAGS_tera_master_query_tabletnode_period * 1000; |
| 2454 | TabletNodePtr node; |
| 2455 | if (!tabletnode_manager_->FindTabletNode(addr, &node)) { |
| 2456 | LOG(WARNING) << "fail to query: server down, id: " << request->sequence_id() |
| 2457 | << ", server: " << addr; |
| 2458 | } else if (failed || response->status() != kTabletNodeOk) { |
| 2459 | LOG_IF(WARNING, failed) << "fail to query: " << sofa::pbrpc::RpcErrorCodeToString(error_code) |
| 2460 | << ", id: " << request->sequence_id() << ", server: " << addr; |
| 2461 | LOG_IF(WARNING, !failed) << "fail to query: " << StatusCodeToString(response->status()) |
| 2462 | << ", id: " << request->sequence_id() << ", server: " << addr; |
| 2463 | int32_t fail_count = node->IncQueryFailCount(); |
| 2464 | if (fail_count >= FLAGS_tera_master_kick_tabletnode_query_fail_times) { |
| 2465 | LOG(ERROR) << kSms << "fail to query " << addr << " for " << fail_count << " times"; |
| 2466 | TryKickTabletNode(addr); |
| 2467 | } |
| 2468 | } else { |
| 2469 | // update tablet meta |
| 2470 | uint32_t meta_num = response->tabletmeta_list().meta_size(); |
| 2471 | std::map<tabletnode::TabletRange, int> tablet_map; |
| 2472 | for (uint32_t i = 0; i < meta_num; i++) { |
| 2473 | const TabletMeta &meta = response->tabletmeta_list().meta(i); |
| 2474 | const TabletCounter &counter = response->tabletmeta_list().counter(i); |
| 2475 | const std::string &table_name = meta.table_name(); |
| 2476 | const std::string &key_start = meta.key_range().key_start(); |
| 2477 | const std::string &key_end = meta.key_range().key_end(); |
| 2478 | int64_t create_time = meta.create_time(); |
| 2479 | uint64_t version = meta.version(); |
| 2480 | |
| 2481 | TablePtr table; |
| 2482 | if (!tablet_manager_->FindTable(table_name, &table)) { |
| 2483 | LOG(WARNING) << "[query] table not exist, tablet: " << meta.path() << " [" |
| 2484 | << DebugString(key_start) << ", " << DebugString(key_end) << "] @ " |
| 2485 | << meta.server_addr() << " status: " << meta.status(); |
| 2486 | continue; |
| 2487 | } |
| 2488 | |
| 2489 | if (create_time > 0 && create_time < table->CreateTime()) { |
| 2490 | LOG(WARNING) << "[query] stale tablet of newly create table, tablet: " << meta.path(); |
| 2491 | continue; |
| 2492 | } |
| 2493 | |
| 2494 | std::vector<TabletPtr> tablets; |
| 2495 | if (!table->FindOverlappedTablets(key_start, key_end, &tablets)) { |
| 2496 | LOG(WARNING) << "[query] key range hole find for table: " << table_name |
| 2497 | << ", hole tablet: " << meta.path() << ", keyrange: [" << key_start << ", " |
| 2498 | << key_end << "]"; |
| 2499 | continue; |
| 2500 | } |
| 2501 | |
| 2502 | if (tablets.size() > 1) { |
| 2503 | bool splitted_tablet = true; |
| 2504 | for (uint32_t j = 0; j < tablets.size(); ++j) { |
nothing calls this directly
no test coverage detected