Exemplo n.º 1
0
func (self *Node) clean() {
	selfRemote := self.node.Remote()
	var cleaned int
	var pushed int
	if nextKey, existed := self.circularNext(self.node.GetPosition()); existed {
		if owners, isOwner := self.owners(nextKey); !isOwner {
			var sync *radix.Sync
			for index, owner := range owners {
				sync = radix.NewSync(self.tree, remoteHashTree{
					source:      selfRemote,
					destination: owner,
					node:        self,
				}).From(nextKey).To(owners[0].Pos)
				if index == len(owners)-2 {
					sync.Destroy()
				}
				sync.Run()
				cleaned = sync.DelCount()
				pushed = sync.PutCount()
				if cleaned != 0 || pushed != 0 {
					self.triggerCleanListeners(selfRemote, owner, cleaned, pushed)
				}
			}
		}
	}
}
Exemplo n.º 2
0
func (self *Node) sync() {
	var pulled int
	var pushed int
	selfRemote := self.node.Remote()
	nextSuccessor := self.node.GetSuccessor()
	for i := 0; i < self.node.Redundancy()-1; i++ {
		myPos := self.node.GetPosition()
		remoteHash := remoteHashTree{
			source:      selfRemote,
			destination: nextSuccessor,
			node:        self,
		}
		pushed = radix.NewSync(self.tree, remoteHash).From(self.node.GetPredecessor().Pos).To(myPos).Run().PutCount()
		pulled = radix.NewSync(remoteHash, self.tree).From(self.node.GetPredecessor().Pos).To(myPos).Run().PutCount()
		if pushed != 0 || pulled != 0 {
			self.triggerSyncListeners(selfRemote, nextSuccessor, pulled, pushed)
		}
		nextSuccessor = self.node.GetSuccessorForRemote(nextSuccessor)
	}
}