int MockMergeServer::ms_scan(const int64_t start_time,const int32_t version,const int32_t channel_id,tbnet::Connection* connection,common::ObDataBuffer& in_buffer,common::ObDataBuffer& out_buffer,const int64_t timeout_us)
{
  ObResultCode rc;
  rc.result_code_ = OB_SUCCESS;
  int ret = OB_SUCCESS;
  const int32_t MS_SCAN_VERSION = 1;
  ret = rc.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());
  if (OB_SUCCESS == ret)
  {
    ObScanner result_scanner;
    ObCellInfo cell;
    cell.table_name_.assign((char*)"table1", 6);
    //TODO
    char rowkey[30 * 1024];
    cell.row_key_.assign(rowkey, 30 * 1024);
    cell.column_name_.assign((char*)"column1", 7);
    cell.value_.set_int(0xff);
    ret = result_scanner.add_cell(cell);
    result_scanner.set_is_req_fullfilled(true, 1);
    if (OB_SUCCESS == ret)
    {
      ret = result_scanner.serialize(out_buffer.get_data(),out_buffer.get_capacity(), out_buffer.get_position());
    }
    if (OB_SUCCESS == ret)
    {
      ret = this->send_response(OB_SCAN_RESPONSE, MS_SCAN_VERSION, out_buffer, connection, channel_id, 0);
    }

  }
  return ret;
}
int ObCommitLogReceiver::end_receiving_log(const int32_t version, tbnet::Connection* conn, const int32_t channel_id, common::ObDataBuffer& out_buff)
{
  int ret = OB_SUCCESS;

  ret = log_writer_->flush_log();
  if (OB_SUCCESS != ret)
  {
    TBSYS_LOG(ERROR, "ObLogWriter flush_log error, ret=%d", ret);
  }
  else
  {
    ObResultCode result_msg;
    result_msg.result_code_ = ret;
    ret = result_msg.serialize(out_buff.get_data(), out_buff.get_capacity(), out_buff.get_position());
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "ObResultCode serialize error, ret=%d", ret);
    }
    else
    {
      ret = base_server_->send_response(OB_SEND_LOG_RES, version, out_buff, conn, channel_id);
      if (OB_SUCCESS != ret)
      {
        TBSYS_LOG(WARN, "send_response error, ret=%d", ret);
      }
    }

  }

  return ret;
}
Exemple #3
0
    int TaskOutputFile::handle_rk_null(common::ObDataBuffer &buffer, ObCellInfo *cell, 
                                       TableConf::ColumnIterator &col_itr, bool add_delima) const
    {
      int ret = OB_SUCCESS;

      while (col_itr != conf_->column_end())// && cell->column_name_.compare(*col_itr))
      {
        if (!conf_->is_rowkey(*col_itr) && !conf_->is_null_column(*(col_itr)))
        {
          break;
        }

        if (add_delima)
        {
          ret = append_delima(buffer, delima_);
          if (ret != OB_SUCCESS)
          {
            TBSYS_LOG(ERROR, "apped delima failed");
            break;
          }
        }

        if (conf_->is_rowkey(*col_itr))
        {
          ret = conf_->append_rowkey_item(cell->row_key_, *col_itr, buffer);
          if (ret != OB_SUCCESS)
          {
            TBSYS_LOG(ERROR, "can't encode rowkey");
            break;
          }
        }
#if DUMP_DEBUG
        else if (conf_->is_null_column(*col_itr))
        {
          buffer.get_data()[buffer.get_position()++] = ' ';
        }
#endif
        if (!add_delima && col_itr + 1 != conf_->column_end()) /* add delima at tail */
        {
          ret = append_delima(buffer, delima_);
          if (ret != OB_SUCCESS)
          {
            TBSYS_LOG(ERROR, "apped delima failed");
            break;
          }
        }

        col_itr++;
      }

      return ret;
    }
int ObRootServerRpcStub::get_frame_buffer(common::ObDataBuffer & data_buffer) const
{
  int ret = OB_SUCCESS;
  if (!check_inner_stat())
  {
    TBSYS_LOG(ERROR, "check inner stat failed.");
    ret = OB_ERROR;
  }

  common::ThreadSpecificBuffer::Buffer* rpc_buffer = get_thread_buffer();
  if (OB_SUCCESS == ret)
  {
    if (NULL == rpc_buffer)
    {
      TBSYS_LOG(ERROR, "get thread rpc buff failed:buffer[%p].", rpc_buffer);
      ret = OB_ERROR;
    }
    else
    {
      rpc_buffer->reset();
      data_buffer.set_data(rpc_buffer->current(), rpc_buffer->remain());
    }
  }
  return ret;
}
int ObCommitLogReceiver::receive_log(const int32_t version, common::ObDataBuffer& in_buff,
    tbnet::Connection* conn, const uint32_t channel_id, common::ObDataBuffer& out_buff)
{
  int ret = OB_SUCCESS;

  if (!log_writer_->get_is_log_start())
  {
    ret = start_log(in_buff);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "start log_writer error, ret=%d", ret);
    }
  }

  if (OB_SUCCESS == ret)
  {
    uint64_t log_id;
    uint64_t log_seq;

    ret = write_data(in_buff.get_data() + in_buff.get_position(), in_buff.get_limit() - in_buff.get_position(), log_id, log_seq);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "decomposite log entry error, ret=%d", ret);
    }
  }

  if (OB_SUCCESS == ret)
  {
    ret = end_receiving_log(version, conn, channel_id, out_buff);
    if (OB_SUCCESS != ret)
    {
      TBSYS_LOG(ERROR, "flush log error, ret=%d", ret);
    }
  }

  if (OB_SUCCESS != ret)
  {
    TBSYS_LOG(WARN, "ret=%d", ret);
  }

  return ret;
}
Exemple #6
0
int ObMonitor::get_rpc_buffer(common::ObDataBuffer &data_buffer)const                        
{ 
  int err = OB_SUCCESS;
  common::ThreadSpecificBuffer::Buffer* rpc_buffer = rpc_buffer_.get_buffer();            
  if(NULL == rpc_buffer)
  { 
    TBSYS_LOG(ERROR, "get thread rpc buff fail.buffer[%p]", rpc_buffer);                  
    err = OB_INNER_STAT_ERROR;                                                            
  }                                                                                       
  else
  { 
    rpc_buffer->reset();                                                                  
    data_buffer.set_data(rpc_buffer->current(), rpc_buffer->remain());                    
  }                                                                                       
  return err;                                                                             
}
Exemple #7
0
int ObRootRpcStub::get_thread_buffer_(common::ObDataBuffer& data_buffer)
{
  int ret = OB_SUCCESS;
  if (NULL == thread_buffer_)
  {
    TBSYS_LOG(ERROR, "thread_buffer_ = NULL");
    ret = OB_ERROR;
  }
  else
  {
    common::ThreadSpecificBuffer::Buffer* buff = thread_buffer_->get_buffer();
    if (NULL == buff)
    {
      TBSYS_LOG(ERROR, "thread_buffer_ = NULL");
      ret = OB_ERROR;
    }
    else
    {
      buff->reset();
      data_buffer.set_data(buff->current(), buff->remain());
    }
  }
  return ret;
}
Exemple #8
0
int ObMonitor::slave_failure(const int32_t version, common::ObDataBuffer& in_buff, tbnet::Connection* conn,
    const uint32_t channel_id, common::ObDataBuffer& out_buff)
{
  int err = OB_SUCCESS;
  ObResultCode result_msg;
  result_msg.result_code_ = OB_SUCCESS;
  if(MY_VERSION != version)
  {
    TBSYS_LOG(WARN, "version not equal. version=%d, MY_VERSION=%ld", version, MY_VERSION);
    result_msg.result_code_ = OB_ERROR_FUNC_VERSION;
  }

  //step1: deserialize the slave node, app_name, instance_name
  ObServer slave_node;
  if(OB_SUCCESS == err && result_msg.result_code_ == OB_SUCCESS)
  {
    err = slave_node.deserialize(in_buff.get_data(), in_buff.get_capacity(), in_buff.get_position());
    if(OB_SUCCESS != err)
    {
      TBSYS_LOG(WARN, "fail to deserialize slave node.err=%d", err);
    }
  }

  char app_name[OB_MAX_APP_NAME_LENGTH];
  char instance_name[OB_MAX_INSTANCE_NAME_LENGTH];

  int64_t len = 0; 
  if(OB_SUCCESS == err && result_msg.result_code_ == OB_SUCCESS)                                               
  { 
    serialization::decode_vstr(in_buff.get_data(), in_buff.get_capacity(), in_buff.get_position(),             
        app_name, OB_MAX_APP_NAME_LENGTH, &len);                                                              
    if(-1 == len)                                                                                              
    { 
      err = OB_ERROR;                                                                                          
    }                                                                                                          
  }                                                                                                            

  len = 0;
  if(OB_SUCCESS == err && result_msg.result_code_ == OB_SUCCESS)                                               
  { 
    serialization::decode_vstr(in_buff.get_data(), in_buff.get_capacity(), in_buff.get_position(),                
        instance_name, OB_MAX_INSTANCE_NAME_LENGTH, &len);                                                     
    if(-1 == len)                                                                                              
    { 
      err = OB_ERROR;                                                                                          
    }                                                                                                          
  }                 

  //step2: do the process
  if(OB_SUCCESS == err && result_msg.result_code_ == OB_SUCCESS)
  {
    result_msg.result_code_ = slave_failure_(slave_node, app_name, instance_name);
    if(OB_SUCCESS != result_msg.result_code_)
    {
      TBSYS_LOG(WARN, "fail to process slave failure, err=%d", result_msg.result_code_);
    }
  }

  //step3: serialize the resultcode
  if(OB_SUCCESS == err)
  {
    err = result_msg.serialize(out_buff.get_data(), out_buff.get_capacity(), out_buff.get_position());
    if(OB_SUCCESS != err)
    {
      TBSYS_LOG(WARN, "fail to serialize the result code .err=%d", err);
    }
  }

  //step4: send response
  if(OB_SUCCESS == err)
  {
    err = base_server_->send_response(OB_MMS_SLAVE_FAILURE_RESPONSE, MY_VERSION, out_buff, conn, channel_id);
    if(err != OB_SUCCESS)
    {
      TBSYS_LOG(WARN, "fail to send_response, err=%d", err);
    }
  }  
  return err;
}
Exemple #9
0
int ObMonitor::node_register(const int32_t version, common::ObDataBuffer& in_buff, tbnet::Connection* conn,
    const uint32_t channel_id, common::ObDataBuffer& out_buff)
{
  int err = OB_SUCCESS;
  ObResultCode result_msg;
  result_msg.result_code_ = OB_SUCCESS;
  if(MY_VERSION != version)
  {
    TBSYS_LOG(WARN, "version not equal. version=%d, MY_VERSION=%ld", version, MY_VERSION);
    result_msg.result_code_ = OB_ERROR_FUNC_VERSION;
  }

  //step1: deserialize the node and app_name instance_name
  ObServerExt node;
  char app_name[OB_MAX_APP_NAME_LENGTH];
  char instance_name[OB_MAX_INSTANCE_NAME_LENGTH];

  if(OB_SUCCESS == err && result_msg.result_code_ == OB_SUCCESS)
  {
    err = node.deserialize(in_buff.get_data(), in_buff.get_capacity(), in_buff.get_position());
    if(OB_SUCCESS != err)
    {
      TBSYS_LOG(WARN, "fail to deserialize node server. err = %d", err);
    } 
  }

  int64_t len = 0;
  if(OB_SUCCESS == err && result_msg.result_code_ == OB_SUCCESS)
  {
    serialization::decode_vstr(in_buff.get_data(), in_buff.get_capacity(), in_buff.get_position(),
        app_name, OB_MAX_APP_NAME_LENGTH, &len);
    if(-1 == len)
    {
      err = OB_ERROR;
    }
  }

  len = 0;
  if(OB_SUCCESS == err && result_msg.result_code_ == OB_SUCCESS)
  {
    serialization::decode_vstr(in_buff.get_data(), in_buff.get_capacity(), in_buff.get_position(),
        instance_name, OB_MAX_INSTANCE_NAME_LENGTH, &len);
    if(-1 == len)
    {
      err = OB_ERROR;
    } 
  }

  MMS_Status status = UNKNOWN;
  bool is_master = false;
  //step2: set the node status
  if(OB_SUCCESS == err && result_msg.result_code_ == OB_SUCCESS)
  {
    result_msg.result_code_ = node_register_(node, app_name, instance_name, status);
    if(result_msg.result_code_ != OB_SUCCESS)
    {
      TBSYS_LOG(WARN, "fail to register node. err = %d", result_msg.result_code_);
    }
    else if(status == MASTER_ACTIVE)
    {
      is_master = true;
    }
    else
    {
      is_master = false;
    }
  }

  //step3: handleNodeRegister 
  if(OB_SUCCESS == err && result_msg.result_code_ == OB_SUCCESS)                                               
  { 
    if(node_register_handler_ != NULL)                                                                         
    { 
      result_msg.result_code_ = node_register_handler_->handleNodeRegister(node, app_name, instance_name, is_master);              
    }
    else                                                                                                       
    { 
      TBSYS_LOG(ERROR, "have not set node_register_handler_");                                                 
      result_msg.result_code_ = OB_INNER_STAT_ERROR;                                                                               
    }
    if(result_msg.result_code_ != OB_SUCCESS)
    {
      TBSYS_LOG(WARN, "fail to handleNodeRegister. err=%d", result_msg.result_code_);
    }
  }

  //step4: serialize result_code
  if(OB_SUCCESS == err)
  {
    err = result_msg.serialize(out_buff.get_data(), out_buff.get_capacity(), out_buff.get_position());
    if(OB_SUCCESS != err)
    {
      TBSYS_LOG(WARN, "fail to serialize result_msg,err=%d", err);
    }
  }

  //step5: serialize status 
  if(OB_SUCCESS == err && result_msg.result_code_ == OB_SUCCESS)
  {
    err = serialization::encode_vi32(out_buff.get_data(), out_buff.get_capacity(), out_buff.get_position(), status);
    if(OB_SUCCESS != err)
    {
      TBSYS_LOG(WARN, "fail to serialize status, err =%d", err);
    }
  }

  //setp6: send response
  if(OB_SUCCESS == err)
  {
    err = base_server_->send_response(OB_MMS_NODE_REGISTER_RESPONSE, MY_VERSION, out_buff, conn, channel_id);
    if(OB_SUCCESS != err)
    {
      TBSYS_LOG(WARN, "fail to send response. err=%d", err);
    }
  }
  return err;
}
Exemple #10
0
int ObFileService::handle_send_file_request(
    const int32_t version,
    const int32_t channel_id,
    easy_request_t* request,
    common::ObDataBuffer& in_buffer,
    common::ObDataBuffer& out_buffer)
{
    int ret = OB_SUCCESS;
    bool inc_concurrency_count_flag = false;
    int32_t response_cid = channel_id;
    int64_t session_id = queue_thread_->generate_session_id();
    const char* src_ip;

    //FILL_TRACE_LOG("handle_send_file_request");
    if (!inited_)
    {
        ret = OB_NOT_INIT;
        TBSYS_LOG(ERROR, "ob file client is not inited yet.");
    }

    if (OB_SUCCESS == ret && NULL == request)
    {
        ret = OB_INVALID_ARGUMENT;
        TBSYS_LOG(WARN, "Connection param in receive_file_loop should not be null");
    }

    if (request != NULL && request->ms != NULL && request->ms->c != NULL)
    {
        src_ip  = get_peer_ip(request);
    }
    else
    {
        src_ip = "";
        TBSYS_LOG(WARN, "can't get src ip for send_file_request");
    }

    if (DEFAULT_VERSION != version)
    {
        ret = OB_ERROR_FUNC_VERSION;
        TBSYS_LOG(ERROR, "Can'd handle send_file_request in different version:"
                  "Server version:%d, Packet version:%d", DEFAULT_VERSION, version);
        // send back error message
        ObResultCode rc;
        rc.result_code_ = OB_ERROR_FUNC_VERSION;
        int err = OB_SUCCESS;
        out_buffer.get_position() = 0;
        err = rc.serialize(out_buffer.get_data(), out_buffer.get_capacity(),
                           out_buffer.get_position());
        if (OB_SUCCESS != err)
        {
            TBSYS_LOG(WARN, "Encode result code failed:ret=[%d]", err);
        }
        else
        {
            err = server_->send_response(OB_SEND_FILE_REQUEST_RESPONSE,
                                         DEFAULT_VERSION, out_buffer, request, response_cid, session_id);
            if (OB_SUCCESS != err)
            {
                TBSYS_LOG(WARN, "Send error message for OB_SEND_FILE_REQUEST failed:"
                          "ret[%d]", err);
            }
        }
    }

    if (OB_SUCCESS == ret)
    {
        ret = inc_concurrency_count();
        if(OB_SUCCESS == ret)
        {
            inc_concurrency_count_flag = true;
        }
        else
        {
            // send back error message
            ObResultCode rc;
            int err = OB_SUCCESS;
            rc.result_code_ = ret;
            out_buffer.get_position() = 0;
            err = rc.serialize(out_buffer.get_data(), out_buffer.get_capacity(),
                               out_buffer.get_position());
            if (OB_SUCCESS != err)
            {
                TBSYS_LOG(WARN, "Encode result code failed:ret=[%d]", err);
            }
            else
            {
                err = server_->send_response(OB_SEND_FILE_REQUEST_RESPONSE,
                                             DEFAULT_VERSION, out_buffer, request, response_cid, session_id);
                if (OB_SUCCESS != err)
                {
                    TBSYS_LOG(WARN, "Send error message for OB_SEND_FILE_REQUEST failed:"
                              "ret[%d]", err);
                }
            }
        }
    }

    // handle...
    ObFileAppender file_appender;
    int64_t file_size;
    ObString file_path;
    ObString tmp_file_path;
    char file_path_buf[OB_MAX_FILE_NAME_LENGTH];
    char tmp_file_path_buf[OB_MAX_FILE_NAME_LENGTH];
    int64_t t1 = tbsys::CTimeUtil::getTime();

    file_path.assign_buffer(file_path_buf, sizeof(file_path_buf));
    tmp_file_path.assign_buffer(tmp_file_path_buf, sizeof(tmp_file_path_buf));

    if (OB_SUCCESS == ret)
    {
        ret = receive_file_pre(file_appender, file_size, file_path, tmp_file_path,
                               request, in_buffer, out_buffer, response_cid, session_id);
        if (OB_SUCCESS != ret)
        {
            TBSYS_LOG(ERROR, "Prepare for receive_file failed: ret=[%d]", ret);
        }
    }

    if (OB_SUCCESS == ret)
    {
        ret = receive_file_loop(file_path, tmp_file_path, file_size,
                                file_appender, request, out_buffer,
                                response_cid, session_id);
        if (OB_SUCCESS != ret)
        {
            TBSYS_LOG(ERROR, "Reveive_file_loop failed:ret=[%d]", ret);
        }
    }

    int64_t duration = tbsys::CTimeUtil::getTime() - t1;
    if (OB_SUCCESS == ret && duration == 0)
    {
        TBSYS_LOG(ERROR, "duration of recieve time should not be zero");
        ret = OB_ERR_UNEXPECTED;
    }

    if (OB_SUCCESS == ret)
    {
        TBSYS_LOG(INFO, "Recieve file from server[%s] to file_path[%.*s] "
                  "tmp_file_path[%.*s] filesize[%ld] time[%ld]us speed[%ld]KB/s",
                  src_ip, file_path.length(), file_path.ptr(),
                  tmp_file_path.length(), tmp_file_path.ptr(),
                  file_size, duration, file_size*1000000/1024/duration);
    }
    else
    {
        TBSYS_LOG(ERROR, "Recieve file from server[%s] to file_path[%.*s] "
                  "tmp_file_path[%.*s] failed, filesize[%ld] cost time[%ld]:ret[%d]",
                  src_ip, file_path.length(), file_path.ptr(),
                  tmp_file_path.length(), tmp_file_path.ptr(),
                  file_size, duration, ret);
    }

    if (inc_concurrency_count_flag)
    {
        dec_concurrency_count();
    }

    int tmp_ret = queue_thread_->destroy_session(session_id);
    if (OB_SUCCESS == ret && OB_SUCCESS != tmp_ret)
    {
        ret = tmp_ret;
    }

    //PRINT_TRACE_LOG();
    return ret;
}