Exemplo n.º 1
0
func NewReplica(id int, peerAddrList []string, thrifty bool, exec bool, dreply bool) *Replica {
	r := &Replica{
		len(peerAddrList),
		int32(id),
		peerAddrList,
		make([]net.Conn, len(peerAddrList)),
		make([]*bufio.Reader, len(peerAddrList)),
		make([]*bufio.Writer, len(peerAddrList)),
		make([]*sync.Mutex, len(peerAddrList)),
		make([]bool, len(peerAddrList)),
		nil,
		state.InitState(),
		make(chan *Propose, CHAN_BUFFER_SIZE),
		make(chan *Beacon, CHAN_BUFFER_SIZE),
		false,
		thrifty,
		exec,
		dreply,
		false,
		false,
		nil,
		make([]int32, len(peerAddrList)),
		nil,
		make(chan fastrpc.Serializable, 1000),
		make(chan fastrpc.Serializable, 1000),
		0,
		0,
		make(chan fastrpc.Serializable, 1000),
		make(chan fastrpc.Serializable, 1000),
		0,
		0,
		make(map[state.Key]bool, 10000),
		make(map[uint8]*RPCPair),
		genericsmrproto.GENERIC_SMR_BEACON_REPLY + 1,
		make([]float64, len(peerAddrList)),
		make(chan bool, 100),
		make([]int64, len(peerAddrList))}

	var err error

	if r.StableStore, err = os.Create(fmt.Sprintf("stable-store-replica%d", r.Id)); err != nil {
		log.Fatal(err)
	}

	for i := 0; i < r.N; i++ {
		r.PreferredPeerOrder[i] = int32((int(r.Id) + 1 + i) % r.N)
		r.Ewma[i] = 0.0
		r.PeerWLocks[i] = new(sync.Mutex)
		r.LastReplyReceivedTimestamp[i] = 0 //time.Now().UnixNano()
	}

	r.qleasePromiseRPC = r.RegisterRPC(new(qleaseproto.Promise), r.QLPromiseChan)
	r.qleasePromiseReplyRPC = r.RegisterRPC(new(qleaseproto.PromiseReply), r.QLPromiseReplyChan)
	r.qleaseGuardRPC = r.RegisterRPC(new(qleaseproto.Guard), r.QLGuardChan)
	r.qleaseGuardReplyRPC = r.RegisterRPC(new(qleaseproto.GuardReply), r.QLGuardReplyChan)

	return r
}
Exemplo n.º 2
0
func NewReplica(id int, peerAddrList []string, thrifty bool, exec bool, dreply bool) *Replica {
	r := &Replica{
		len(peerAddrList),
		int32(id),
		peerAddrList,
		make([]net.Conn, len(peerAddrList)),
		make([]*bufio.Reader, len(peerAddrList)),
		make([]*bufio.Writer, len(peerAddrList)),
		make([]bool, len(peerAddrList)),
		nil,
		state.InitState(),
		make(chan *Propose, CHAN_BUFFER_SIZE),
		make(chan *Beacon, CHAN_BUFFER_SIZE),
		false,
		thrifty,
		exec,
		dreply,
		false,
		false,
		nil,
		make([]int32, len(peerAddrList)),
		make(map[uint8]*RPCPair),
		genericsmrproto.GENERIC_SMR_BEACON_REPLY + 1,
		make([]float64, len(peerAddrList)),
		make(chan bool, 100)}

	var err error

	if r.StableStore, err = os.Create(fmt.Sprintf("stable-store-replica%d", r.Id)); err != nil {
		log.Fatal(err)
	}

	for i := 0; i < r.N; i++ {
		r.PreferredPeerOrder[i] = int32((int(r.Id) + 1 + i) % r.N)
		r.Ewma[i] = 0.0
	}

	return r
}