imay commented on a change in pull request #450: Add EsScanNode URL: https://github.com/apache/incubator-doris/pull/450#discussion_r244676358
########## File path: be/src/exec/es_scan_node.cpp ########## @@ -128,66 +136,59 @@ Status EsScanNode::open(RuntimeState* state) { params.__set_predicates(predicates); TExtOpenResult result; - // check es host - if (es_scan_range.es_hosts.empty()) { - std::stringstream ss; - ss << "es fail to open: hosts empty"; - LOG(ERROR) << ss.str(); - return Status(ss.str()); - } - - // choose an es node, local is better - TNetworkAddress es_host_selected = es_scan_range.es_hosts[0]; - int selected_idx = 0; - for (int j = 0; j < es_scan_range.es_hosts.size(); j++) { - TNetworkAddress& es_host = es_scan_range.es_hosts[j]; - if (es_host.hostname == BackendOptions::get_localhost()) { - es_host_selected = es_host; - selected_idx = j; - break; - } - } - - // if shard not found, try other nodes - Status status = open_es(es_host_selected, result, params); - if (status.code() == TStatusCode::ES_SHARD_NOT_FOUND) { - for (int j = 0; j < es_scan_range.es_hosts.size(); j++) { - if (j == selected_idx) continue; - es_host_selected = es_scan_range.es_hosts[j]; - status = open_es(es_host_selected, result, params); - if (status.code() == TStatusCode::ES_SHARD_NOT_FOUND) { + // choose an es node, local is the first choice + std::string localhost = BackendOptions::get_localhost(); + bool is_success = false; + for (int j = 0; j < 2; ++j) { + for (auto& es_host : es_scan_range.es_hosts) { + if ((j == 0 && es_host.hostname != localhost) + || (j == 1 && es_host.hostname == localhost)) { continue; } else { Review comment: there is no need to have a `else` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@doris.apache.org For additional commands, e-mail: dev-h...@doris.apache.org