コード例 #1
0
ファイル: raftnode.go プロジェクト: samkit993/cs733
func NewMockRN(state State, srvr *mock.MockServer, logFileName string, hbTimeout int, timeout int) (*RaftNode, error) {
	//TODO Add code for recovery
	registerStructs()

	_mainLog, err := log.Open(logFileName)
	if err != nil {
		return nil, err
	}

	_stateLog, err := log.Open(logFileName + "_state")
	if err != nil {
		return nil, err
	}

	_mainLog.RegisterSampleEntry([]byte{})
	_stateLog.RegisterSampleEntry(StateInfo{})

	_sm, alarm := NewSm(state, srvr.Pid(), srvr.Peers(), hbTimeout, timeout)

	rn := RaftNode{appendCh: make(chan Event, 1000), commitCh: make(chan *CommitInfo, 1000), processQuitCh: make(chan bool), isOn: true, sm: _sm, server: srvr, mainLog: _mainLog, stateLog: _stateLog}
	rn.timer = time.NewTimer(time.Millisecond * time.Duration(alarm.duration))

	go rn.handleEvent()
	return &rn, err
}
コード例 #2
0
ファイル: fsnode.go プロジェクト: samkit993/cs733
func NewMockFsNode(state State, srvr *mock.MockServer, logFileName string, hbTimeout int, timeout int, _pubaddr string) (*FsNode, error) {
	//TODO Add code for recovery
	registerStructs()

	_mainLog, err := log.Open(logFileName)
	if err != nil {
		return nil, err
	}

	_stateLog, err := log.Open(logFileName + "_state")
	if err != nil {
		return nil, err
	}

	_mainLog.RegisterSampleEntry([]byte{})
	_stateLog.RegisterSampleEntry(StateInfo{})

	_sm, alarm := NewSm(state, srvr.Pid(), srvr.Peers(), hbTimeout, timeout)

	fsn := FsNode{appendCh: make(chan Event, 1000), commitCh: make(chan *CommitInfo, 1000), processQuitCh: make(chan bool), frontEndQuitCh: make(chan bool, 1), backEndQuitCh: make(chan bool, 1), isOn: true, sm: _sm, server: srvr, mainLog: _mainLog, stateLog: _stateLog, dict: make(map[string]*FileStruct, 1000), pubaddr: _pubaddr, connMap: make(map[int64]*net.Conn)}
	fsn.timer = time.NewTimer(time.Millisecond * time.Duration(alarm.duration))

	addr, err := net.ResolveTCPAddr("tcp4", fsn.pubaddr)
	printErr(err)

	fsn.socket, err = net.ListenTCP("tcp", addr)
	printErr(err)

	go fsn.frontEndMain()
	go fsn.backEndMain()
	go fsn.handleEvent()
	return &fsn, err
}