use crate::regions::Region;
use crate::routing::partition_key_range::PartitionKeyRange;
use crate::PartitionKey;
use azure_core::http::RawResponse;
use std::collections::HashMap;
use url::Url;
#[allow(dead_code)]
#[derive(Clone, Debug, PartialEq, Eq, Default)]
pub(crate) struct RequestContext {
pub force_refresh_address_cache: bool,
pub original_request_consistency_level: Option<String>, pub quorum_selected_lsn: i64,
pub global_committed_selected_lsn: i64,
pub store_response: Option<RawResponse>,
pub perform_local_refresh_on_gone_exception: bool,
pub effective_partition_key: Option<PartitionKey>,
pub resolved_partition_key_range: Option<PartitionKeyRange>,
pub session_token: Option<String>,
pub performed_background_address_refresh: bool,
pub resolved_collection_rid: Option<String>,
pub region_name: Option<Region>,
pub local_region_request: bool,
pub is_retry: bool,
pub is_partition_failover_retry: bool,
pub failed_endpoints: HashMap<Url, bool>,
pub use_preferred_locations: Option<bool>,
pub location_index_to_route: Option<usize>,
pub location_endpoint_to_route: Option<Url>,
}
#[allow(dead_code)]
impl RequestContext {
pub fn add_to_failed_endpoints(
&mut self,
_store_exception: &str, target_uri: Url,
) {
self.failed_endpoints.insert(target_uri, true);
}
pub fn route_to_location_index(
&mut self,
location_index: usize,
use_preferred_locations: bool,
) {
self.location_index_to_route = Some(location_index);
self.use_preferred_locations = Some(use_preferred_locations);
self.location_endpoint_to_route = None;
}
pub fn route_to_location_endpoint(&mut self, location_endpoint: Url) {
self.location_endpoint_to_route = Some(location_endpoint);
self.location_index_to_route = None;
self.use_preferred_locations = None;
}
pub fn clear_route_to_location(&mut self) {
self.location_index_to_route = None;
self.location_endpoint_to_route = None;
self.use_preferred_locations = None;
}
}