Struct rings_node::prelude::PeerRing
source · pub struct PeerRing {
pub did: Did,
pub finger: Arc<Mutex<FingerTable>, Global>,
pub successor_seq: SuccessorSeq,
pub predecessor: Arc<Mutex<Option<Did>>, Global>,
pub storage: Arc<KvStorage, Global>,
pub cache: Arc<MemStorage<Did, VirtualNode>, Global>,
}
Expand description
PeerRing is used to help a node interact with other nodes. All nodes in rings network form a clockwise ring in the order of Did. This struct takes its name from that. PeerRing implemented Chord algorithm. PeerRing implemented ChordStorage protocol.
Fields§
§did: Did
The did of current node.
finger: Arc<Mutex<FingerTable>, Global>
FingerTable help node to find successor quickly.
successor_seq: SuccessorSeq
The next node on the ring. The SuccessorSeq may contain multiple node dids for fault tolerance. The min did should be same as the first element in finger table.
predecessor: Arc<Mutex<Option<Did>>, Global>
The did of previous node on the ring.
storage: Arc<KvStorage, Global>
Local storage for ChordStorage.
cache: Arc<MemStorage<Did, VirtualNode>, Global>
Local cache for ChordStorage.
Implementations§
source§impl PeerRing
impl PeerRing
sourcepub fn new_with_storage(did: Did, succ_max: u8, storage: KvStorage) -> PeerRing
pub fn new_with_storage(did: Did, succ_max: u8, storage: KvStorage) -> PeerRing
Same as new with config, but with a given storage.
sourcepub fn lock_successor(&self) -> Result<SuccessorSeq, Error>
👎Deprecated
pub fn lock_successor(&self) -> Result<SuccessorSeq, Error>
Return successor sequence. This function is deprecated, please use [chord.successors] instead.
sourcepub fn successors(&self) -> SuccessorSeq
pub fn successors(&self) -> SuccessorSeq
Return successor sequence
sourcepub fn lock_finger(&self) -> Result<MutexGuard<'_, FingerTable>, Error>
pub fn lock_finger(&self) -> Result<MutexGuard<'_, FingerTable>, Error>
Lock and return MutexGuard of finger table.
sourcepub fn lock_predecessor(&self) -> Result<MutexGuard<'_, Option<Did>>, Error>
pub fn lock_predecessor(&self) -> Result<MutexGuard<'_, Option<Did>>, Error>
Lock and return MutexGuard of predecessor.
Trait Implementations§
source§impl Chord<PeerRingAction> for PeerRing
impl Chord<PeerRingAction> for PeerRing
source§fn join(&self, did: Did) -> Result<PeerRingAction, Error>
fn join(&self, did: Did) -> Result<PeerRingAction, Error>
Join a ring containing a node identified by did
.
This method is usually invoked to maintain successor sequence and finger table
after connect to another node.
This method will return a RemoteAction::FindSuccessorForConnect to the caller.
The caller will send it to the node identified by did
, and let the node find
the successor of current node and make current node connect to that successor.
source§fn find_successor(&self, did: Did) -> Result<PeerRingAction, Error>
fn find_successor(&self, did: Did) -> Result<PeerRingAction, Error>
Find the successor of a Did. May return a remote action for the successor is recorded in another node.
source§fn notify(&self, did: Did) -> Result<Option<Did>, Error>
fn notify(&self, did: Did) -> Result<Option<Did>, Error>
Handle notification from a node that thinks it is the predecessor of current node.
The did
in parameters is the Did of that node.
If that node is closer to current node or current node has no predecessor, set it to the did.
This method will return that did if it is set to the predecessor.
source§fn fix_fingers(&self) -> Result<PeerRingAction, Error>
fn fix_fingers(&self) -> Result<PeerRingAction, Error>
Fix finger table by finding the successor for each finger. According to the paper, this method should be called periodically. According to the paper, only one finger should be fixed at a time.
source§impl<const REDUNDANT: u16> ChordStorage<PeerRingAction, REDUNDANT> for PeerRing
impl<const REDUNDANT: u16> ChordStorage<PeerRingAction, REDUNDANT> for PeerRing
source§fn vnode_lookup<'life0, 'async_trait>(
&'life0 self,
vid: Did
) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
PeerRing: 'async_trait,
fn vnode_lookup<'life0, 'async_trait>( &'life0 self, vid: Did ) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, PeerRing: 'async_trait,
Look up a VirtualNode by its Did.
Always finds resource by finger table, ignoring the local cache.
If the vid
is between current node and its successor, its resource should be
stored in current node.
source§fn vnode_operate<'life0, 'async_trait>(
&'life0 self,
op: VNodeOperation
) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
PeerRing: 'async_trait,
fn vnode_operate<'life0, 'async_trait>( &'life0 self, op: VNodeOperation ) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, PeerRing: 'async_trait,
Handle VNodeOperation if the target vnode between current node and the successor of current node, otherwise find the responsible node and return as Action.
source§impl ChordStorageCache<PeerRingAction> for PeerRing
impl ChordStorageCache<PeerRingAction> for PeerRing
source§fn local_cache_set(&self, vnode: VirtualNode)
fn local_cache_set(&self, vnode: VirtualNode)
Cache fetched vnode
locally.
source§fn local_cache_get(&self, vid: Did) -> Option<VirtualNode>
fn local_cache_get(&self, vid: Did) -> Option<VirtualNode>
Get vnode from local cache.
source§impl ChordStorageSync<PeerRingAction> for PeerRing
impl ChordStorageSync<PeerRingAction> for PeerRing
source§fn sync_vnode_with_successor<'life0, 'async_trait>(
&'life0 self,
new_successor: Did
) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
PeerRing: 'async_trait,
fn sync_vnode_with_successor<'life0, 'async_trait>( &'life0 self, new_successor: Did ) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, PeerRing: 'async_trait,
When the successor of a node is updated, it needs to check if there are
VirtualNode
s that are no longer between current node and new_successor
,
and sync them to the new successor.
source§impl CorrectChord<PeerRingAction> for PeerRing
impl CorrectChord<PeerRingAction> for PeerRing
source§fn update_successor<'life0, 'async_trait>(
&'life0 self,
did: impl LiveDid + 'async_trait
) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
PeerRing: 'async_trait,
fn update_successor<'life0, 'async_trait>( &'life0 self, did: impl LiveDid + 'async_trait ) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, PeerRing: 'async_trait,
When Chord have a new successor, ask the new successor for successor list
source§fn join_then_sync<'life0, 'async_trait>(
&'life0 self,
did: impl LiveDid + 'async_trait
) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
PeerRing: 'async_trait,
fn join_then_sync<'life0, 'async_trait>( &'life0 self, did: impl LiveDid + 'async_trait ) -> Pin<Box<dyn Future<Output = Result<PeerRingAction, Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, PeerRing: 'async_trait,
Join Operation in the paper. Zave’s work differs from the original Chord paper in that it requires a newly joined node to synchronize its successors from remote nodes.
source§fn rectify(&self, pred: Did) -> Result<(), Error>
fn rectify(&self, pred: Did) -> Result<(), Error>
TODO: Please check this function and make sure it is correct. TODO: Please comment this with clear description. Rectify Operation in the paper.
source§fn pre_stabilize(&self) -> Result<PeerRingAction, Error>
fn pre_stabilize(&self) -> Result<PeerRingAction, Error>
Pre-Stabilize Operation: Before stabilizing, the node should query its first successor for TopoInfo. If there are no successors, return PeerRingAction::None.
source§fn stabilize(&self, info: TopoInfo) -> Result<PeerRingAction, Error>
fn stabilize(&self, info: TopoInfo) -> Result<PeerRingAction, Error>
Stabilize Operation: Perform stabilization for the successor list.
source§fn topo_info(&self) -> Result<TopoInfo, Error>
fn topo_info(&self) -> Result<TopoInfo, Error>
A function to provide topological information about the chord.