Exemplo n.º 1
0
// NewAllocator creates and initialises a new Allocator
func NewAllocator(config Config) *Allocator {
	var participant paxos.Participant
	var alloc *Allocator
	var onUpdate ring.OnUpdate

	if config.IsObserver {
		participant = paxos.NewObserver()
	} else {
		participant = paxos.NewNode(config.OurName, config.OurUID, 0)
	}

	if config.Tracker != nil {
		onUpdate = func(prev []address.Range, curr []address.Range, local bool) {
			if err := config.Tracker.HandleUpdate(prev, curr, local); err != nil {
				alloc.errorf("HandleUpdate failed: %s", err)
			}
		}
	}

	alloc = &Allocator{
		ourName:     config.OurName,
		seed:        config.Seed,
		universe:    config.Universe,
		ring:        ring.New(config.Universe.Range().Start, config.Universe.Range().End, config.OurName, onUpdate),
		owned:       make(map[string]ownedData),
		db:          config.Db,
		paxos:       participant,
		nicknames:   map[mesh.PeerName]string{config.OurName: config.OurNickname},
		isKnownPeer: config.IsKnownPeer,
		quorum:      config.Quorum,
		dead:        make(map[string]time.Time),
		now:         time.Now,
	}
	return alloc
}
Exemplo n.º 2
0
// NewAllocator creates and initialises a new Allocator
func NewAllocator(ourName router.PeerName, ourUID router.PeerUID, ourNickname string, universe address.Range, quorum uint) *Allocator {
	return &Allocator{
		ourName:   ourName,
		universe:  universe,
		ring:      ring.New(universe.Start, address.Add(universe.Start, universe.Size()), ourName),
		owned:     make(map[string][]address.Address),
		paxos:     paxos.NewNode(ourName, ourUID, quorum),
		nicknames: map[router.PeerName]string{ourName: ourNickname},
		now:       time.Now,
	}
}
Exemplo n.º 3
0
// NewAllocator creates and initialises a new Allocator
func NewAllocator(ourName mesh.PeerName, ourUID mesh.PeerUID, ourNickname string, universe address.Range, quorum uint, isKnownPeer func(name mesh.PeerName) bool) *Allocator {
	return &Allocator{
		ourName:     ourName,
		universe:    universe,
		ring:        ring.New(universe.Start, universe.End, ourName),
		owned:       make(map[string][]address.Address),
		paxos:       paxos.NewNode(ourName, ourUID, quorum),
		nicknames:   map[mesh.PeerName]string{ourName: ourNickname},
		isKnownPeer: isKnownPeer,
		now:         time.Now,
	}
}