pub struct BackendSelector { /* private fields */ }Expand description
Selects backend servers using round-robin with load tracking
§Thread Safety
This struct is designed for concurrent access across multiple threads. The round-robin counter and pending counts use atomic operations for lock-free performance.
§Load Balancing
- Strategy: Round-robin rotation through available backends
- Tracking: Atomic counters track pending commands per backend
- Monitoring: Load statistics available via
backend_load()
§Examples
let mut selector = BackendSelector::new();
selector.add_backend(
BackendId::from_index(0),
"backend-1".to_string(),
provider,
);
// Route commands
let backend = selector.route_command_sync(ClientId::new(), "LIST")?;Implementations§
Source§impl BackendSelector
impl BackendSelector
Sourcepub fn add_backend(
&mut self,
backend_id: BackendId,
name: String,
provider: DeadpoolConnectionProvider,
)
pub fn add_backend( &mut self, backend_id: BackendId, name: String, provider: DeadpoolConnectionProvider, )
Add a backend server to the router
Sourcepub fn route_command_sync(
&self,
_client_id: ClientId,
_command: &str,
) -> Result<BackendId>
pub fn route_command_sync( &self, _client_id: ClientId, _command: &str, ) -> Result<BackendId>
Select a backend for the given command using round-robin Returns the backend ID to use for this command
Sourcepub fn complete_command_sync(&self, backend_id: BackendId)
pub fn complete_command_sync(&self, backend_id: BackendId)
Mark a command as complete, decrementing the pending count
Sourcepub fn get_backend_provider(
&self,
backend_id: BackendId,
) -> Option<&DeadpoolConnectionProvider>
pub fn get_backend_provider( &self, backend_id: BackendId, ) -> Option<&DeadpoolConnectionProvider>
Get the connection provider for a backend
Sourcepub fn backend_count(&self) -> usize
pub fn backend_count(&self) -> usize
Get the number of backends
Sourcepub fn backend_load(&self, backend_id: BackendId) -> Option<usize>
pub fn backend_load(&self, backend_id: BackendId) -> Option<usize>
Get backend load (pending requests) for monitoring
Trait Implementations§
Source§impl Debug for BackendSelector
impl Debug for BackendSelector
Auto Trait Implementations§
impl !Freeze for BackendSelector
impl !RefUnwindSafe for BackendSelector
impl Send for BackendSelector
impl Sync for BackendSelector
impl Unpin for BackendSelector
impl !UnwindSafe for BackendSelector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more