コード例 #1
0
void RequestHandler::on_error_response(ResponseMessage* response) {
  ErrorResponse* error =
      static_cast<ErrorResponse*>(response->response_body().get());


  switch(error->code()) {
    case CQL_ERROR_UNPREPARED:
      on_error_unprepared(error);
      break;

    case CQL_ERROR_READ_TIMEOUT:
      handle_retry_decision(response,
                            retry_policy_->on_read_timeout(error->consistency(),
                                                           error->received(),
                                                           error->required(),
                                                           error->data_present() > 0,
                                                           num_retries_));
      break;

    case CQL_ERROR_WRITE_TIMEOUT:
      handle_retry_decision(response,
                            retry_policy_->on_write_timeout(error->consistency(),
                                                            error->received(),
                                                            error->required(),
                                                            error->write_type(),
                                                            num_retries_));
      break;

    case CQL_ERROR_UNAVAILABLE:
      handle_retry_decision(response,
                            retry_policy_->on_unavailable(error->consistency(),
                                                          error->required(),
                                                          error->received(),
                                                          num_retries_));
      break;

    default:
      set_error(static_cast<CassError>(CASS_ERROR(
                                         CASS_ERROR_SOURCE_SERVER, error->code())),
                error->message().to_string());
      break;
  }
}
コード例 #2
0
void RequestHandler::handle_retry_decision(ResponseMessage* response,
                                           const RetryPolicy::RetryDecision& decision) {
  ErrorResponse* error =
      static_cast<ErrorResponse*>(response->response_body().get());

  switch(decision.type()) {
    case RetryPolicy::RetryDecision::RETURN_ERROR:
      set_error_with_error_response(response->response_body(),
                                    static_cast<CassError>(CASS_ERROR(
                                                             CASS_ERROR_SOURCE_SERVER, error->code())),
                                    error->message().to_string());
      break;

    case RetryPolicy::RetryDecision::RETRY:
      set_consistency(decision.retry_consistency());
      if (!decision.retry_current_host()) {
        next_host();
      }
      if (state() == REQUEST_STATE_DONE) {
        retry();
      } else {
        set_state(REQUEST_STATE_RETRY_WRITE_OUTSTANDING);
      }
      break;

    case RetryPolicy::RetryDecision::IGNORE:
      set_response(SharedRefPtr<Response>(new ResultResponse()));
      break;
  }
  num_retries_++;
}