本文整理汇总了C++中ObServer::to_cstring方法的典型用法代码示例。如果您正苦于以下问题:C++ ObServer::to_cstring方法的具体用法?C++ ObServer::to_cstring怎么用?C++ ObServer::to_cstring使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObServer
的用法示例。
在下文中一共展示了ObServer::to_cstring方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: do_post_packet
/**
* post_packet is async version of send_packet. donot wait for response packet.
*/
int ObClientManager::do_post_packet(const ObServer& server, ObPacket* packet,
tbnet::IPacketHandler* handler, void* args) const
{
int rc = OB_SUCCESS;
if (NULL == packet)
{
rc = OB_INVALID_ARGUMENT;
}
else if (!inited_)
{
rc = OB_NOT_INIT;
TBSYS_LOG(ERROR, "cannot post packet, ClientManager not initialized.");
packet->free();
}
else
{
bool send_ok = connmgr_->sendPacket(server.get_ipv4_server_id(), packet, handler, args);
if (!send_ok)
{
rc = OB_PACKET_NOT_SENT;
TBSYS_LOG(WARN, "cannot post packet, maybe send queue is full or disconnect.dest_server:%s",
server.to_cstring());
packet->free();
}
}
return rc;
}
示例2: do_send_packet
/*
* send a packet to server %server and wait response packet
* @param server send to server
* @param packet send packet object, must be allocate on heap,
* if send_packet failed, packet will be free by send_packet.
* @param timeout max wait time interval
* @param [out] response response packet from remote server, allocated on heap,
* must be free by user who call the send_packet. response not NULL when return success.
* @return OB_SUCCESS on success or other on failure.
*/
int ObClientManager::do_send_packet(const ObServer & server,
ObPacket* packet, const int64_t timeout, ObPacket* &response) const
{
response = NULL;
int rc = OB_SUCCESS;
if (NULL == packet)
{
rc = OB_INVALID_ARGUMENT;
}
else if (!inited_)
{
rc = OB_NOT_INIT;
TBSYS_LOG(ERROR, "cannot send packet, ClientManager not initialized.");
packet->free();
packet = NULL;
}
else if (OB_SUCCESS != error_)
{
rc = error_;
packet->free();
TBSYS_LOG(ERROR, "prev_error=%d", error_);
}
common::WaitObject* wait_object = NULL;
if (OB_SUCCESS == rc)
{
wait_object = waitmgr_->create_wait_object();
if (NULL == wait_object)
{
TBSYS_LOG(ERROR, "cannot send packet, cannot create wait object");
rc = OB_ERROR;
}
}
if (OB_SUCCESS == rc)
{
if (timeout > max_request_timeout_)
{
max_request_timeout_ = timeout;
connmgr_->setDefaultQueueTimeout(0, static_cast<int32_t>(max_request_timeout_ / 1000));
}
// caution! wait_object set no free, it means response packet
// not be free by wait_object, must be handled by user who call send_packet.
// MODIFY: wait_object need free the response packet not handled.
// wait_object->set_no_free();
int packet_code = packet->get_packet_code();
bool send_ok = connmgr_->sendPacket(server.get_ipv4_server_id(), packet, NULL,
reinterpret_cast<void*>(wait_object->get_id()));
if (send_ok)
{
send_ok = wait_object->wait(timeout);
if (!send_ok)
{
TBSYS_LOG(ERROR, "wait packet(%d) response timeout, timeout=%ld, dest_server=%s",
packet_code, timeout, server.to_cstring());
rc = OB_RESPONSE_TIME_OUT;
}
else
{
response = dynamic_cast<ObPacket*>(wait_object->get_response());
// there's two situation on here.
// 1. connect remote server failed, ControlPacket(timeout) raise up.
// 2. timeout parameter of this function greater than default timeout
// of ConnectManager(5000ms), Packet timeout raise up.
// TODO, maybe need a new error code.
rc = (NULL != response) ? OB_SUCCESS : OB_RESPONSE_TIME_OUT;
}
}
else
{
packet->free();
rc = OB_PACKET_NOT_SENT;
TBSYS_LOG(WARN, "cannot send packet, maybe send queue is full or disconnect.");
}
// do not free the response packet.
waitmgr_->destroy_wait_object(wait_object);
wait_object = NULL;
if (OB_SUCCESS == rc && NULL != response)
{
rc = response->deserialize();
if (OB_SUCCESS != rc)
{
TBSYS_LOG(ERROR, "response packet deserialize failed.");
// cannot free response packet, allocate on thread specific memeory.
response = NULL;
}
}
//.........这里部分代码省略.........
示例3: table_exist_in_cs
int ObRootRpcStub::table_exist_in_cs(const ObServer &cs, const int64_t timeout_us,
const uint64_t table_id, bool &is_exist_in_cs)
{
int ret = OB_SUCCESS;
ObDataBuffer msgbuf;
if (NULL == client_mgr_)
{
TBSYS_LOG(ERROR, "client_mgr_=NULL");
ret = OB_ERROR;
}
if (OB_SUCCESS == ret)
{
if (OB_SUCCESS != (ret = get_thread_buffer_(msgbuf)))
{
TBSYS_LOG(ERROR, "failed to get thread buffer, err=%d", ret);
}
}
if (OB_SUCCESS == ret)
{
if (OB_SUCCESS != (ret = serialization::encode_vi64(msgbuf.get_data(), msgbuf.get_capacity(),
msgbuf.get_position(), table_id)))
{
TBSYS_LOG(WARN, "fail to encode table_id, table_id=%ld, ret=%d", table_id, ret);
}
}
if (OB_SUCCESS == ret)
{
if (OB_SUCCESS != (ret = client_mgr_->send_request(cs, OB_CS_CHECK_TABLET, DEFAULT_VERSION, timeout_us, msgbuf)))
{
TBSYS_LOG(WARN, "failed to send request, err=%d", ret);
}
}
ObResultCode result;
int64_t pos = 0;
if (OB_SUCCESS == ret)
{
if (OB_SUCCESS != (ret = result.deserialize(msgbuf.get_data(), msgbuf.get_position(), pos)))
{
TBSYS_LOG(ERROR, "failed to deserialize response, err=%d", ret);
}
}
if (OB_SUCCESS == ret)
{
if (OB_CS_TABLET_NOT_EXIST == result.result_code_)
{
ret = OB_SUCCESS;
is_exist_in_cs = false;
}
else if (OB_SUCCESS == result.result_code_)
{
is_exist_in_cs = true;
}
else
{
ret = result.result_code_;
TBSYS_LOG(WARN, "fail to check cs tablet. table_id=%lu, cs_addr=%s, err=%d",
table_id, cs.to_cstring(), ret);
}
}
return ret;
}
示例4: get_table_tablet
//.........这里部分代码省略.........
}
list.clear();
start_key = end_key;
}
else
{
cell->row_key_.deep_copy(end_key, allocator);
if ((cell->column_name_.compare("1_ms_port") == 0)
|| (cell->column_name_.compare("2_ms_port") == 0)
|| (cell->column_name_.compare("3_ms_port") == 0))
{
ret = cell->value_.get_int(port);
}
else if ((cell->column_name_.compare("1_ipv4") == 0)
|| (cell->column_name_.compare("2_ipv4") == 0)
|| (cell->column_name_.compare("3_ipv4") == 0))
{
ret = cell->value_.get_int(ip);
}
else if ((cell->column_name_.compare("1_tablet_version") == 0)
|| (cell->column_name_.compare("2_tablet_version") == 0)
|| (cell->column_name_.compare("3_tablet_version") == 0))
{
ret = cell->value_.get_int(version);
if (OB_SUCCESS == ret)
{
if (0 == port || port == 0)
{
TBSYS_LOG(WARN, "%s", "check port or ip failed");
}
else
{
server.set_ipv4_addr(int32_t(ip), int32_t(port));
ObTabletLocation addr(version, server);
if (OB_SUCCESS != (ret = list.add(addr)))
{
TBSYS_LOG(ERROR, "add addr failed:server[%d], port[%d], ret[%d]",
server.get_ipv4(), server.get_port(), ret);
}
else
{
TBSYS_LOG(DEBUG, "add addr succ:server[%s], version:%ld", server.to_cstring(), version);
}
}
ip = port = version = 0;
}
}
if (ret != OB_SUCCESS)
{
TBSYS_LOG(ERROR, "check get value failed:ret[%d]", ret);
break;
}
}
}
// for the last row
if ((OB_SUCCESS == ret) && (start_key != end_key))
{
TaskInfo task;
task.set_table_id(table_id);
task.set_table_name(table_name);
ret = init_new_task(name, start_key, end_key, scan_param, task);
if (ret != OB_SUCCESS)
{
TBSYS_LOG(ERROR, "init new task failed:ret[%d]", ret);
}
else
{
ret = insert_new_task(list, task);
if (ret != OB_SUCCESS)
{
TBSYS_LOG(ERROR, "insert new task failed:ret[%d]", ret);
}
++count;
}
if (OB_SUCCESS == ret)
{
// copy all the end key objs to row_key
for (int64_t i = 0; i < end_key.length(); ++i)
{
const_cast<ObObj *> (row_key.ptr())[i] = end_key.ptr()[i];
row_key.assign(const_cast<ObObj *> (row_key.ptr()), end_key.length());
}
// modify last row key for next get root table
if (!end_key.is_max_row())
{
const_cast<ObObj *>(row_key.ptr())[end_key.length()].set_max_value();
row_key.assign(const_cast<ObObj *> (row_key.ptr()), end_key.length() + 1);
}
}
}
list.clear();
}
}
}
return ret;
}
示例5: scan
int ObMergerRpcStub::scan(
const int64_t timeout, const ObServer & server,
const ObScanParam & scan_param, ObScanner & scanner) const
{
int ret = OB_SUCCESS;
ObDataBuffer data_buff;
int64_t start_time = tbsys::CTimeUtil::getTime();
ret = get_rpc_buffer(data_buff);
// step 1. serialize ObScanParam to the data_buff
if (OB_SUCCESS == ret)
{
ret = scan_param.serialize(data_buff.get_data(), data_buff.get_capacity(),
data_buff.get_position());
if (OB_SUCCESS != ret)
{
TBSYS_LOG(WARN, "serialize scan param failed:ret[%d]", ret);
}
}
// step 2. send request for scan data
if (OB_SUCCESS == ret)
{
ret = rpc_frame_->send_request(server, OB_SCAN_REQUEST, DEFAULT_VERSION,
timeout, data_buff);
if (ret != OB_SUCCESS)
{
TBSYS_LOG(WARN, "send scan request to server failed:ret[%d], timeout=%ld",
ret, timeout);
}
}
// step 3. deserialize the response result
int64_t pos = 0;
if (OB_SUCCESS == ret)
{
ObResultCode result_code;
ret = result_code.deserialize(data_buff.get_data(), data_buff.get_position(), pos);
if (OB_SUCCESS != ret)
{
TBSYS_LOG(WARN, "deserialize result failed:pos[%ld], ret[%d]", pos, ret);
}
else
{
ret = result_code.result_code_;
}
}
// step 4. deserialize the scanner
if (OB_SUCCESS == ret)
{
ret = scanner.deserialize(data_buff.get_data(), data_buff.get_position(), pos);
if (OB_SUCCESS != ret)
{
TBSYS_LOG(WARN, "deserialize scanner from buff failed:pos[%ld], ret[%d]", pos, ret);
}
}
// write debug log
const int32_t MAX_SERVER_ADDR_SIZE = 128;
char server_addr[MAX_SERVER_ADDR_SIZE];
server.to_string(server_addr, MAX_SERVER_ADDR_SIZE);
bool is_fullfilled = false;
int64_t fullfilled_item_num = 0;
scanner.get_is_req_fullfilled(is_fullfilled,fullfilled_item_num);
if (OB_SUCCESS == ret)
{
TBSYS_LOG(DEBUG, "scan data succ from server:addr[%s]", server_addr);
}
else
{
TBSYS_LOG(WARN, "scan data failed from server:addr[%s], "
"version_range=%s, ret[%d]",
server_addr, range2str(scan_param.get_version_range()), ret);
}
int64_t consume_time = tbsys::CTimeUtil::getTime() - start_time;
if ((double)consume_time > (double)timeout * 0.8)
{
TBSYS_LOG(WARN, "slow ups scan, ups_addr=%s, timeout=%ld, consume=%ld",
server.to_cstring(), timeout, consume_time);
}
return ret;
}
示例6: fetch_schema
int ObMergerRpcStub::fetch_schema(
const int64_t timeout, const ObServer & root_server,
const int64_t version, ObSchemaManagerV2 & schema) const
{
int ret = OB_SUCCESS;
ObDataBuffer data_buff;
ret = get_rpc_buffer(data_buff);
// step 1. serialize timestamp to data_buff
if (OB_SUCCESS == ret)
{
ret = serialization::encode_vi64(data_buff.get_data(),
data_buff.get_capacity(), data_buff.get_position(), version);
if (OB_SUCCESS != ret)
{
TBSYS_LOG(WARN, "serialize timestamp failed:version[%ld], ret[%d]",
version, ret);
}
}
// step 2. send request for fetch new schema
if (OB_SUCCESS == ret)
{
ret = rpc_frame_->send_request(root_server, OB_FETCH_SCHEMA, DEFAULT_VERSION,
timeout, data_buff);
if (ret != OB_SUCCESS)
{
TBSYS_LOG(WARN, "send request to root server[%s] for fetch schema failed:"
"version[%ld], ret[%d]", root_server.to_cstring(), version, ret);
}
}
// step 3. deserialize the response code
int64_t pos = 0;
if (OB_SUCCESS == ret)
{
ObResultCode result_code;
ret = result_code.deserialize(data_buff.get_data(), data_buff.get_position(), pos);
if (OB_SUCCESS != ret)
{
TBSYS_LOG(WARN, "deserialize result_code failed:pos[%ld], ret[%d]", pos, ret);
}
else
{
ret = result_code.result_code_;
}
}
// step 4. deserialize the table schema
if (OB_SUCCESS == ret)
{
ret = schema.deserialize(data_buff.get_data(), data_buff.get_position(), pos);
if (OB_SUCCESS != ret)
{
TBSYS_LOG(WARN, "deserialize schema from buff failed:"
"version[%ld], pos[%ld], ret[%d]", version, pos, ret);
}
else
{
TBSYS_LOG(DEBUG, "fetch schema succ:version[%ld]", schema.get_version());
//schema.print_info();
}
}
return ret;
}