Struct AccessorInfo

Source
pub struct AccessorInfo { /* private fields */ }
Expand description

Info for the accessor. Users can use this struct to retrieve information about the underlying backend.

This struct is intentionally not implemented with Clone to ensure that all accesses within the same operator, access layers, and services use the same instance of AccessorInfo. This is especially important for HttpClient and Executor.

§Panic Safety

All methods provided by AccessorInfo will safely handle lock poisoning scenarios. If the inner RwLock is poisoned (which happens when another thread panicked while holding the write lock), this method will gracefully continue execution.

  • For read operations, the method will return the current state.
  • For write operations, the method will do nothing.

§Maintain Notes

We are using std::sync::RwLock to provide thread-safe access to the inner data.

I have performed the bench across different arc-swap alike crates:

test arcswap                    ... bench:          14.85 ns/iter (+/- 0.33)
test arcswap_full               ... bench:         128.27 ns/iter (+/- 4.30)
test baseline                   ... bench:          11.33 ns/iter (+/- 0.76)
test mutex_4                    ... bench:         296.73 ns/iter (+/- 49.96)
test mutex_unconteded           ... bench:          13.26 ns/iter (+/- 0.56)
test rwlock_fast_4              ... bench:         201.60 ns/iter (+/- 7.47)
test rwlock_fast_uncontended    ... bench:          12.77 ns/iter (+/- 0.37)
test rwlock_parking_4           ... bench:         232.02 ns/iter (+/- 11.14)
test rwlock_parking_uncontended ... bench:          13.18 ns/iter (+/- 0.39)
test rwlock_std_4               ... bench:         219.56 ns/iter (+/- 5.56)
test rwlock_std_uncontended     ... bench:          13.55 ns/iter (+/- 0.33)

The results show that as long as there aren’t too many uncontended accesses, RwLock is the best choice, allowing for fast access and the ability to modify partial data without cloning everything.

And it’s true: we only update and modify the internal data in a few instances, such as when building an operator or applying new layers.

Implementations§

Source§

impl AccessorInfo

Source

pub fn scheme(&self) -> Scheme

Scheme of backend.

§Panic Safety

This method safely handles lock poisoning scenarios. If the inner RwLock is poisoned, this method will gracefully continue execution by simply returning the current scheme.

Source

pub fn set_scheme(&self, scheme: Scheme) -> &Self

Set Scheme for backend.

§Panic Safety

This method safely handles lock poisoning scenarios. If the inner RwLock is poisoned, this method will gracefully continue execution by simply skipping the update operation rather than propagating the panic.

Source

pub fn root(&self) -> Arc<str>

Root of backend, will be in format like /path/to/dir/

§Panic Safety

This method safely handles lock poisoning scenarios. If the inner RwLock is poisoned, this method will gracefully continue execution by simply returning the current root.

Source

pub fn set_root(&self, root: &str) -> &Self

Set root for backend.

Note: input root must be normalized.

§Panic Safety

This method safely handles lock poisoning scenarios. If the inner RwLock is poisoned, this method will gracefully continue execution by simply skipping the update operation rather than propagating the panic.

Source

pub fn name(&self) -> Arc<str>

Name of backend, could be empty if underlying backend doesn’t have namespace concept.

For example:

  • s3 => bucket name
  • azblob => container name
  • azdfs => filesystem name
  • azfile => share name
§Panic Safety

This method safely handles lock poisoning scenarios. If the inner RwLock is poisoned, this method will gracefully continue execution by simply returning the current scheme.

Source

pub fn set_name(&self, name: &str) -> &Self

Set name of this backend.

§Panic Safety

This method safely handles lock poisoning scenarios. If the inner RwLock is poisoned, this method will gracefully continue execution by simply skipping the update operation rather than propagating the panic.

Source

pub fn native_capability(&self) -> Capability

Get backend’s native capabilities.

§Panic Safety

This method safely handles lock poisoning scenarios. If the inner RwLock is poisoned, this method will gracefully continue execution by simply returning the current native capability.

Source

pub fn set_native_capability(&self, capability: Capability) -> &Self

Set native capabilities for service.

§NOTES

Set native capability will also flush the full capability. The only way to change full_capability is via update_full_capability.

§Panic Safety

This method safely handles lock poisoning scenarios. If the inner RwLock is poisoned, this method will gracefully continue execution by simply skipping the update operation rather than propagating the panic.

Source

pub fn full_capability(&self) -> Capability

Get service’s full capabilities.

§Panic Safety

This method safely handles lock poisoning scenarios. If the inner RwLock is poisoned, this method will gracefully continue execution by simply returning the current native capability.

Source

pub fn update_full_capability( &self, f: impl FnOnce(Capability) -> Capability, ) -> &Self

Update service’s full capabilities.

§Panic Safety

This method safely handles lock poisoning scenarios. If the inner RwLock is poisoned, this method will gracefully continue execution by simply skipping the update operation rather than propagating the panic.

Source

pub fn http_client(&self) -> HttpClient

Get http client from the context.

§Panic Safety

This method safely handles lock poisoning scenarios. If the inner RwLock is poisoned, this method will gracefully continue execution by simply returning the current http client.

Source

pub fn update_http_client( &self, f: impl FnOnce(HttpClient) -> HttpClient, ) -> &Self

Update http client for the context.

§Note

Requests must be forwarded to the old HTTP client after the update. Otherwise, features such as retry, tracing, and metrics may not function properly.

§Panic Safety

This method safely handles lock poisoning scenarios. If the inner RwLock is poisoned, this method will gracefully continue execution by simply skipping the update operation.

Source

pub fn executor(&self) -> Executor

Get executor from the context.

§Panic Safety

This method safely handles lock poisoning scenarios. If the inner RwLock is poisoned, this method will gracefully continue execution by simply returning the current executor.

Source

pub fn update_executor(&self, f: impl FnOnce(Executor) -> Executor) -> &Self

Update executor for the context.

§Note

Tasks must be forwarded to the old executor after the update. Otherwise, features such as retry, timeout, and metrics may not function properly.

§Panic Safety

This method safely handles lock poisoning scenarios. If the inner RwLock is poisoned, this method will gracefully continue execution by simply skipping the update operation.

Trait Implementations§

Source§

impl Debug for AccessorInfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AccessorInfo

Source§

fn default() -> AccessorInfo

Returns the “default value” for a type. Read more
Source§

impl Hash for AccessorInfo

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for AccessorInfo

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for AccessorInfo

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ServiceExt for T

Source§

fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>
where Self: Sized,

Apply a transformation to the response body. Read more
Source§

fn decompression(self) -> Decompression<Self>
where Self: Sized,

Decompress response bodies. Read more
Source§

fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using HTTP status codes. Read more
Source§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using gRPC headers. Read more
Source§

fn follow_redirects(self) -> FollowRedirect<Self>
where Self: Sized,

Follow redirect resposes using the Standard policy. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> MaybeSend for T
where T: Send,