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;
}
// 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;
}
Example #3
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;
}