Skip to content

Commit cf99230

Browse files
chaoyliimay
authored andcommitted
Close #19 fix machine hostname is resolved to loopback address (#34)
1 parent 71f06ae commit cf99230

37 files changed

Lines changed: 359 additions & 241 deletions

‎be/src/agent/task_worker_pool.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "olap/utils.h"
3939
#include "common/resource_tls.h"
4040
#include "agent/cgroups_mgr.h"
41+
#include "service/backend_options.h"
4142

4243
using std::deque;
4344
using std::list;
@@ -69,7 +70,7 @@ TaskWorkerPool::TaskWorkerPool(
6970
_agent_utils = new AgentUtils();
7071
_master_client = new MasterServerClient(_master_info, &_master_service_client_cache);
7172
_command_executor = new CommandExecutor();
72-
_backend.__set_host(_agent_utils->get_local_ip());
73+
_backend.__set_host(BackendOptions::get_localhost());
7374
_backend.__set_be_port(config::be_port);
7475
_backend.__set_http_port(config::webserver_port);
7576
}

‎be/src/agent/utils.cpp‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -260,25 +260,6 @@ AgentStatus AgentUtils::rsync_from_remote(
260260
return PALO_SUCCESS;
261261
}
262262

263-
char* AgentUtils::get_local_ip() {
264-
char hname[128];
265-
gethostname(hname, sizeof(hname));
266-
267-
// Let's hope this is not broken in the glibc we're using
268-
struct hostent hent;
269-
struct hostent *he = 0;
270-
char hbuf[2048];
271-
int err = 0;
272-
if (gethostbyname_r(hname, &hent, hbuf, sizeof(hbuf), &he, &err) != 0
273-
|| he == 0) {
274-
LOG(ERROR) << "gethostbyname : " << hname << ", "
275-
<< "error: " << err;
276-
return NULL;
277-
}
278-
279-
return inet_ntoa(*(struct in_addr*)(he->h_addr_list[0]));
280-
}
281-
282263
std::string AgentUtils::print_agent_status(AgentStatus status) {
283264
switch (status) {
284265
case PALO_SUCCESS:

‎be/src/agent/utils.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,6 @@ class AgentUtils {
126126
const uint32_t transport_speed_limit_kbps,
127127
const uint32_t timeout_second);
128128

129-
// Get ip of local service
130-
virtual char* get_local_ip();
131-
132129
// Print AgentStatus as string
133130
virtual std::string print_agent_status(AgentStatus status);
134131

‎be/src/exec/analytic_eval_node.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "exprs/agg_fn_evaluator.h"
2424
#include "exprs/anyval_util.h"
2525

26-
#include "runtime/buffered_tuple_stream.hpp"
26+
#include "runtime/buffered_tuple_stream.h"
2727
#include "runtime/descriptors.h"
2828
#include "runtime/row_batch.h"
2929
#include "runtime/runtime_state.h"

‎be/src/exec/olap_scanner.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "olap_scan_node.h"
2222
#include "olap_utils.h"
2323
#include "olap/olap_reader.h"
24+
#include "service/backend_options.h"
2425
#include "runtime/descriptors.h"
2526
#include "runtime/runtime_state.h"
2627
#include "runtime/mem_pool.h"
@@ -135,8 +136,7 @@ Status OlapScanner::open() {
135136
fetch_request.__set_aggregation(_aggregation);
136137

137138
if (!_reader->init(fetch_request, &_vec_conjunct_ctxs, _profile).ok()) {
138-
std::string local_ip;
139-
get_local_ip(&local_ip);
139+
std::string local_ip = BackendOptions::get_localhost();
140140
std::stringstream ss;
141141
if (MemTracker::limit_exceeded(*_runtime_state->mem_trackers())) {
142142
ss << "Memory limit exceeded. Tablet: " << fetch_request.tablet_id << ". host: " << local_ip;

‎be/src/http/action/mini_load.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "http/http_channel.h"
4040
#include "http/http_parser.h"
4141
#include "olap/file_helper.h"
42+
#include "service/backend_options.h"
4243
#include "util/url_coding.h"
4344
#include "util/file_utils.h"
4445
#include "runtime/exec_env.h"
@@ -328,7 +329,7 @@ Status MiniLoadAction::load(
328329
}
329330
req.__set_properties(params);
330331
req.files.push_back(file_path);
331-
req.backend.__set_hostname(*_exec_env->local_ip());
332+
req.backend.__set_hostname(BackendOptions::get_localhost());
332333
req.backend.__set_port(config::be_port);
333334

334335
struct timeval tv;

‎be/src/runtime/CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ set(LIBRARY_OUTPUT_PATH "${BUILD_DIR}/src/runtime")
2727
set(EXECUTABLE_OUTPUT_PATH "${BUILD_DIR}/src/runtime")
2828

2929
add_library(Runtime STATIC
30-
broker_mgr.cpp
30+
broker_mgr.cpp
3131
buffered_block_mgr.cpp
3232
buffered_tuple_stream.cpp
3333
buffered_tuple_stream_ir.cpp

‎be/src/runtime/broker_mgr.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "common/config.h"
2121
#include "gen_cpp/PaloBrokerService_types.h"
2222
#include "gen_cpp/TPaloBrokerService.h"
23+
#include "service/backend_options.h"
2324
#include "runtime/exec_env.h"
2425
#include "runtime/client_cache.h"
2526
#include "util/thrift_util.h"
@@ -37,7 +38,7 @@ BrokerMgr::~BrokerMgr() {
3738

3839
void BrokerMgr::init() {
3940
std::stringstream ss;
40-
ss << *_exec_env->local_ip() << ":" << config::be_port;
41+
ss << BackendOptions::get_localhost() << ":" << config::be_port;
4142
_client_id = ss.str();
4243
}
4344

‎be/src/runtime/buffered_tuple_stream.cpp‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,4 +439,56 @@ int BufferedTupleStream::compute_row_size(TupleRow* row) const {
439439

440440
return size;
441441
}
442+
443+
inline uint8_t* BufferedTupleStream::allocate_row(int size) {
444+
DCHECK(!_closed);
445+
446+
if (UNLIKELY(_write_block == NULL || _write_block->bytes_remaining() < size)) {
447+
bool got_block = false;
448+
_status = new_block_for_write(size, &got_block);
449+
450+
if (!_status.ok() || !got_block) {
451+
return NULL;
452+
}
453+
}
454+
455+
DCHECK(_write_block != NULL);
456+
// DCHECK(_write_block->is_pinned());
457+
DCHECK_GE(_write_block->bytes_remaining(), size);
458+
++_num_rows;
459+
_write_block->add_row();
460+
return _write_block->allocate<uint8_t>(size);
461+
}
462+
463+
inline void BufferedTupleStream::get_tuple_row(const RowIdx& idx, TupleRow* row) const {
464+
DCHECK(!_closed);
465+
//DCHECK(is_pinned());
466+
DCHECK(!_delete_on_read);
467+
DCHECK_EQ(_blocks.size(), _block_start_idx.size());
468+
DCHECK_LT(idx.block(), _blocks.size());
469+
470+
uint8_t* data = _block_start_idx[idx.block()] + idx.offset();
471+
472+
if (_nullable_tuple) {
473+
// Stitch together the tuples from the block and the NULL ones.
474+
const int tuples_per_row = _desc.tuple_descriptors().size();
475+
uint32_t tuple_idx = idx.idx() * tuples_per_row;
476+
477+
for (int i = 0; i < tuples_per_row; ++i) {
478+
const uint8_t* null_word = _block_start_idx[idx.block()] + (tuple_idx >> 3);
479+
const uint32_t null_pos = tuple_idx & 7;
480+
const bool is_not_null = ((*null_word & (1 << (7 - null_pos))) == 0);
481+
row->set_tuple(i, reinterpret_cast<Tuple*>(
482+
reinterpret_cast<uint64_t>(data) * is_not_null));
483+
data += _desc.tuple_descriptors()[i]->byte_size() * is_not_null;
484+
++tuple_idx;
485+
}
486+
} else {
487+
for (int i = 0; i < _desc.tuple_descriptors().size(); ++i) {
488+
row->set_tuple(i, reinterpret_cast<Tuple*>(data));
489+
data += _desc.tuple_descriptors()[i]->byte_size();
490+
}
491+
}
492+
}
493+
442494
}

‎be/src/runtime/buffered_tuple_stream.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,23 @@ class BufferedTupleStream {
412412
int compute_num_null_indicator_bytes(int block_size) const;
413413
};
414414

415+
inline bool BufferedTupleStream::add_row(TupleRow* row, uint8_t** dst) {
416+
DCHECK(!_closed);
417+
418+
if (LIKELY(deep_copy(row, dst))) {
419+
return true;
420+
}
421+
422+
bool got_block = false;
423+
_status = new_block_for_write(compute_row_size(row), &got_block);
424+
425+
if (!_status.ok() || !got_block) {
426+
return false;
427+
}
428+
429+
return deep_copy(row, dst);
430+
}
431+
415432
}
416433

417434
#endif

0 commit comments

Comments
 (0)