Esempio n. 1
0
// try to add a replica, return success or not
func (self *Block) AddReplica(loc proc.ServerLocation) bool {
	index := self.findIndex(loc)
	if index != -1 {
		// not add but return true
		return true
	}
	if len(self.block.Locations) >= config.ReplicaCount() {
		// will not add
		return false
	}
	self.block.Locations = append(self.block.Locations, loc)
	return true
}
Esempio n. 2
0
// compute the location for a new block
func (self *SlaveManager) NewBlockReplica() []proc.ServerLocation {
	h := &SlaveHeap{}
	heap.Init(h)
	for _, slave := range self.slaves {
		heap.Push(h, slave)
	}
	var locations []proc.ServerLocation
	for h.Len() > 0 && len(locations) < config.ReplicaCount() {
		slave := heap.Pop(h).(*Slave)
		if slave.IsAlive(time.Now()) {
			locations = append(locations, slave.Location())
		}
	}
	return locations
}