pub struct VirtualNode<T: Node> { /* private fields */ }Expand description
Virtual node wrapper for consistent hashing
A virtual node represents one of multiple replicas of a physical node on the hash ring. By creating multiple virtual nodes for each physical node, the key distribution becomes more uniform.
§Type Parameters
T- The type of the physical node, must implementNodetrait
§Example
use rocketmq_common::common::consistenthash::Node;
use rocketmq_common::common::consistenthash::VirtualNode;
struct ServerNode {
address: String,
}
impl Node for ServerNode {
fn get_key(&self) -> &str {
&self.address
}
}
let physical = ServerNode {
address: "192.168.1.1:8080".to_string(),
};
let virtual_node = VirtualNode::new(physical, 0);
assert_eq!(virtual_node.get_key(), "192.168.1.1:8080-0");
assert_eq!(virtual_node.replica_index(), 0);Implementations§
Source§impl<T: Node> VirtualNode<T>
impl<T: Node> VirtualNode<T>
Sourcepub fn is_virtual_node_of(&self, physical_node: &T) -> bool
pub fn is_virtual_node_of(&self, physical_node: &T) -> bool
Sourcepub fn physical_node(&self) -> &T
pub fn physical_node(&self) -> &T
Sourcepub fn replica_index(&self) -> i32
pub fn replica_index(&self) -> i32
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for VirtualNode<T>where
T: Freeze,
impl<T> RefUnwindSafe for VirtualNode<T>where
T: RefUnwindSafe,
impl<T> Send for VirtualNode<T>where
T: Send,
impl<T> Sync for VirtualNode<T>where
T: Sync,
impl<T> Unpin for VirtualNode<T>where
T: Unpin,
impl<T> UnsafeUnpin for VirtualNode<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for VirtualNode<T>where
T: UnwindSafe,
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