int ObMergerRequest::create_rpc_event(ObMergerRpcEvent ** event)
{
  int ret = OB_SUCCESS;
  /// ObMergerRpcEvent * rpc = new(std::nothrow) ObMergerRpcEvent;
  ObMergerRpcEvent * rpc = reinterpret_cast<ObMergerRpcEvent *>(ob_malloc(sizeof(ObMergerRpcEvent),
        ObModIds::OB_MS_RPC_EVENT));
  if (NULL == rpc)
  {
    ret = OB_ERROR;
    TBSYS_LOG(WARN, "check rpc event allocate failed:rpc[%p]", rpc);
  }
  else
  {
    new (rpc) ObMergerRpcEvent;
    TBSYS_LOG(DEBUG, "create rpc event succ:request[%lu], event[%lu], ptr[%p]",
        request_id_, rpc->get_event_id(), rpc);
    ret = rpc->init(request_id_, this);
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(WARN, "init rpc event failed:request[%lu], event[%lu], ptr[%p], ret[%d]",
          request_id_, rpc->get_event_id(), rpc, ret);
      destroy_rpc_event(rpc);
    }
    else
    {
      *event = rpc;
    }
  }
  return ret;
}
Beispiel #2
0
    virtual int scan(const int64_t timeout, const ObServer & server,
        const ObScanParam & scan_param, ObMergerRpcEvent & result) const
    {
      UNUSED(timeout);
      UNUSED(server);
      UNUSED(scan_param);
      result.set_result_code(OB_SUCCESS);
      ObScanner &scanner = result.get_result();
      
      ObScannerLoader loader;
      loader.load(filename, scanner_section_names[file_idx]);

      file_idx = (++file_idx % 6);
      loader.get_decoded_scanner(scanner);

      TBSYS_LOG(INFO, "+==============DUMP===============+");
      scanner.dump();
      TBSYS_LOG(INFO, "+=============END DUMP============+");

      if(!rpc_events_list_.push_back(&result))
      {
        TBSYS_LOG(ERROR, "fail to save rpc result");
      }
      else
      {
        TBSYS_LOG(INFO, "currently totally %ld results saved....", rpc_events_list_.get_array_index());
        TBSYS_LOG(INFO, "a RPC result save to rpc_event_list_");
      }
      return OB_SUCCESS;
    }
int ObMergerRequest::remove_invalid_event_in_finish_queue(const int64_t timeout)
{
  int ret = OB_SUCCESS;
  int64_t remainder = timeout;
  int64_t size = finish_queue_.size();
  bool is_valid = false;
  ObMergerRpcEvent * event = NULL;
  while (remainder > 0 && size > 0)
  {
    if (OB_SUCCESS == (ret = finish_queue_.pop(remainder, (void *&)event)))
    {
      if (NULL != event && OB_SUCCESS == event->get_result_code()
          && event->get_session_id() >  ObCommonRpcEvent::INVALID_SESSION_ID)
      {
        terminate_remote_session(event->get_server(), event->get_session_id());
        TBSYS_LOG(INFO,"end finished but not process session [client:%ld, session_id:%lu, event_id:%ld]",
            event->get_client_id(), event->get_session_id(), event->get_event_id());
      }
      remove_wait_queue(event, is_valid);
      destroy_rpc_event(event);
    }
    else
    {
      TBSYS_LOG(WARN, "pop result from finish queue failed:request[%lu], event[%p], ret[%d]",
          request_id_, event, ret);
    }
    size = finish_queue_.size();
  }
  return ret;
}
int ObMergerGetRequest::get_session_next(const int64_t sub_req_idx,
  ObMergerRpcEvent & prev_rpc, const int64_t timeout_us)
{
  int err = OB_SUCCESS;
  ObMergerRpcEvent *rpc_event = NULL;
  if ((OB_SUCCESS == err) && (OB_SUCCESS != (err = ObMergerRequest::create(&rpc_event))))
  {
    TBSYS_LOG(WARN,"fail to create ObMergerRpcEvent [err:%d]", err);
  }
  if (OB_SUCCESS == err)
  {
    if (OB_SUCCESS != (err = get_rpc()->get_session_next(timeout_us,prev_rpc.get_server(),
            prev_rpc.get_session_id(), prev_rpc.get_req_type(), *rpc_event)))
    {
      TBSYS_LOG(WARN,"fail to send request to server [request_id:%lu,err:%d]", get_request_id(),err);
    }
    else
    {
      sub_requests_[sub_req_idx].set_last_rpc_event(*rpc_event, prev_rpc.get_session_id());
      sub_requests_[sub_req_idx].set_last_svr_ipv4(prev_rpc.get_server().get_ipv4());
      TBSYS_LOG(INFO, "session next [request_id:%lu,prev_rpc:%lu,cur_rpc:%lu]", get_request_id(),
        prev_rpc.get_event_id(), rpc_event->get_event_id());
    }
  }
  return err;
}
// by the tbnet thread so lightweight
int ObMergerRequest::signal(ObMergerRpcEvent & event)
{
  // only push to the finish_queue not check request id or in wait queue
  int ret = OB_SUCCESS;
  if (request_id_ != event.get_client_id())
  {
    TBSYS_LOG(INFO , "the event we do not expect from server, "
        "event[%ld], client[%ld], current client[%ld], session id[%ld], rcode[%d]",
        event.get_event_id(), event.get_client_id(), request_id_,
        event.get_session_id(), event.get_result_code());
    ret = OB_INVALID_ERROR;
  }
  else
  {
    ret = finish_queue_.push(&event);
  }

  if (ret != OB_SUCCESS)
  {
    if (OB_INVALID_ERROR != ret)
    {
      TBSYS_LOG(ERROR, "push to finish queue failed:client[%lu], event[%lu], "
          "request[%lu], finish_size[%ld], ret[%d]", event.get_client_id(), event.get_event_id(),
          request_id_, finish_queue_.size(), ret);
    }
    else if (OB_INVALID_ERROR == ret && OB_SUCCESS == event.get_result_code()
        && event.get_session_id() >  ObCommonRpcEvent::INVALID_SESSION_ID)
    {
      terminate_remote_session(event.get_server(), event.get_session_id());
      TBSYS_LOG(INFO,"end unexpect session [client:%ld, session_id:%lu]",
          event.get_client_id(), event.get_session_id());
    }
    bool is_valid = false;
    remove_wait_queue(&event, is_valid);
    destroy_rpc_event(&event);
  }
  else
  {
    TBSYS_LOG(DEBUG, "push to finish queue succ:client[%lu], event[%lu], request[%lu]",
        event.get_client_id(), event.get_event_id(), request_id_);
  }
  return ret;
}
Beispiel #6
0
int ObGetRequestEvent::setup_new_request(const bool retry, const ObGetParam & get_param)
{
  int ret = OB_SUCCESS;
  ObMergerRpcEvent * event = NULL;
  // step 1. create new rpc event and add to the waiting queue
  if (false == check_inner_stat())
  {
    ret = OB_INNER_STAT_ERROR;
    TBSYS_LOG(WARN, "check inner stat failed");
  }
  else
  {
    ret = ObMergerRequestEvent::create(&event);
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "add new rpc event failed:request[%lu], ret[%d]", get_request_id(), ret);
    }
  }
  
  // TODO check retry with other cs
  UNUSED(retry);
  ObMergerTabletLocationList list;
  // step 3. select the right cs for request
  if ((OB_SUCCESS == ret)) // && (false == retry))
  {
    ret = get_cache_proxy()->get_tablet_location(get_param[0]->table_id_, get_param[0]->row_key_, list);
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(WARN, "get tablet location failed:client[%lu], event[%lu], request[%lu], ret[%d]",
          event->get_client_id(), event->get_event_id(), get_request_id(), ret);
    }
  }
  
  // step 4. send reqeust for get
  if (OB_SUCCESS == ret)
  {
    // TODO access list[0]
    event->set_server(list[0].server_.chunkserver_);
    ret = get_rpc()->get(get_timeout(), list[0].server_.chunkserver_, get_param, *event);
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "check async rpc stub failed:client[%lu], event[%lu], request[%lu], ret[%d]",
        event->get_client_id(), event->get_event_id(), get_request_id(), ret);
    }
    else
    {
      TBSYS_LOG(DEBUG, "send get param to server succ:client[%lu], event[%lu], request[%lu], "
          "get_cell[%ld]", event->get_client_id(), event->get_event_id(), get_request_id(),
          get_param.get_cell_size());
    }
  }
  
  /// if not send succ
  if ((event != NULL) && (ret != OB_SUCCESS))
  {
    uint64_t client_id = event->get_client_id();
    uint64_t event_id = event->get_event_id();
    int err = ObMergerRequestEvent::destroy(event);
    if (err != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "destroy the event failed when rpc send failed:client[%lu], event[%lu], "
          "request[%lu], ret[%d], err[%d]", client_id, event_id, get_request_id(), ret, err);
    }
    else
    {
      TBSYS_LOG(INFO, "destroy directly succ:client[%lu], event[%lu], request[%lu], ret[%d]",
          client_id, event_id, get_request_id(), ret);
    }
  }
  return ret;
}
Beispiel #7
0
int ObGetRequestEvent::check_request_finish(ObMergerRpcEvent & event, bool & finish)
{
  finish = false;
  bool retry = false;
  int ret = OB_SUCCESS;
  ObGetParam new_param;
  int32_t result_code = OB_SUCCESS;
  ObScanner & result = event.get_result(result_code);
  int64_t timeout = 0;
  const ObGetParam * org_param = dynamic_cast<const ObGetParam *>(get_request_param(timeout));
  if (NULL == org_param)
  {
    ret = OB_INPUT_PARAM_ERROR;
    TBSYS_LOG(WARN, "check result code error:result[%d], request[%lu], event[%lu], param[%p]",
        event.get_result_code(), get_request_id(), event.get_event_id(), org_param);
  }
  else if (result_code != OB_SUCCESS)
  {
    // TODO retry next server or delete the cache item and terminate if retry too many times
    retry = true;
    result.clear();
    // set fullfill to true item count = 0 for next get new param
    result.set_is_req_fullfilled(true, 0);
    TBSYS_LOG(INFO, "check result code failed:result[%d], request[%lu], event[%lu]",
        event.get_result_code(), get_request_id(), event.get_event_id());
  }
  else
  {
    // right now no duplicated rpc event and all is in-sequence return
    // add to result list for iterator
    ret = result_list_.push_back(&event);
    if (ret != OB_SUCCESS)
    {
      result.clear();
      result.set_is_req_fullfilled(true, 0);
      TBSYS_LOG(ERROR, "push the result failed:request[%lu], event[%lu], ret[%d]",
          get_request_id(), event.get_event_id(), ret);
    }
    else
    {
      FILL_TRACE_LOG("got one result from cs finished_sub_get_count[%d]", result_list_.size());
    }
  }
  
  // update the returned item count and construct the new param if not finish all
  ret = get_next_param(*org_param, result, returned_item_count_, finish, &new_param);
  if (ret != OB_SUCCESS)
  {
    TBSYS_LOG(ERROR, "get next param failed:request[%lu], event[%lu], ret[%d]", 
        get_request_id(), event.get_event_id(), ret);
  }
  
  if ((false == finish) && (OB_SUCCESS == ret))
  {
    ret = setup_new_request(retry, new_param);
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(WARN, "setup new request failed:request[%lu], event[%lu], ret[%d]", 
          get_request_id(), event.get_event_id(), ret);
    }
  }
  return ret;
}