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_++;
}
Beispiel #2
0
std::string ErrorResponse::error_message() const {
  std::ostringstream ss;
  ss << "'" << message().to_string() << "'"
     << " (0x" << std::hex << std::uppercase << std::setw(8) << std::setfill('0')
     << CASS_ERROR(CASS_ERROR_SOURCE_SERVER, code()) << ")";
  return ss.str();
}
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;
  }
}
Beispiel #4
0
CassError cass_error_result_code(const CassErrorResult* error_result) {
  return static_cast<CassError>(
        CASS_ERROR(CASS_ERROR_SOURCE_SERVER, error_result->code()));
}