Ejemplo n.º 1
0
func (conn *Connection) actorLoop(head *cc.ChanCellHead) {
	var (
		err          error
		stateChanged bool
		oldState     connectionStateMachineComponent
		queryChan    <-chan connectionMsg
		queryCell    *cc.ChanCell
	)
	chanFun := func(cell *cc.ChanCell) { queryChan, queryCell = conn.queryChan, cell }
	head.WithCell(chanFun)
	terminate := false
	for !terminate {
		stateChanged = oldState != conn.currentState
		if stateChanged {
			oldState = conn.currentState
			terminate, err = conn.currentState.start()
		} else {
			if msg, ok := <-queryChan; ok {
				terminate, err = conn.handleMsg(msg)
			} else {
				head.Next(queryCell, chanFun)
			}
		}
		terminate = terminate || err != nil
	}
	conn.cellTail.Terminate()
	conn.handleShutdown(err)
	log.Println("Connection terminated")
}
Ejemplo n.º 2
0
func (conn *Connection) actorLoop(head *cc.ChanCellHead) {
	conn.topology = conn.connectionManager.AddTopologySubscriber(eng.ConnectionSubscriber, conn)
	defer conn.connectionManager.RemoveTopologySubscriberAsync(eng.ConnectionSubscriber, conn)

	var (
		err       error
		oldState  connectionStateMachineComponent
		queryChan <-chan connectionMsg
		queryCell *cc.ChanCell
	)
	chanFun := func(cell *cc.ChanCell) { queryChan, queryCell = conn.queryChan, cell }
	head.WithCell(chanFun)
	terminate := false
	for !terminate {
		if oldState != conn.currentState {
			oldState = conn.currentState
			terminate, err = conn.currentState.start()
		} else if msg, ok := <-queryChan; ok {
			terminate, err = conn.handleMsg(msg)
		} else {
			head.Next(queryCell, chanFun)
		}
		terminate = terminate || err != nil
	}
	conn.cellTail.Terminate()
	conn.handleShutdown(err)
	log.Println("Connection terminated")
}
Ejemplo n.º 3
0
func (l *Listener) actorLoop(head *cc.ChanCellHead) {
	connectionCount := uint32(0)
	var (
		err       error
		queryChan <-chan listenerMsg
		queryCell *cc.ChanCell
	)
	chanFun := func(cell *cc.ChanCell) { queryChan, queryCell = l.queryChan, cell }
	head.WithCell(chanFun)
	terminate := false
	for !terminate {
		if msg, ok := <-queryChan; ok {
			switch msgT := msg.(type) {
			case *listenerMsgShutdown:
				terminate = true
			case listenerAcceptError:
				err = msgT
			case *listenerConnMsg:
				connectionCount++
				NewConnectionFromTCPConn((*net.TCPConn)(msgT), l.connectionManager, connectionCount)
			}
			terminate = terminate || err != nil
		} else {
			head.Next(queryCell, chanFun)
		}
	}
	if err != nil {
		log.Println("Listen error:", err)
	}
	l.cellTail.Terminate()
	l.listener.Close()
}
Ejemplo n.º 4
0
func (exe *Executor) loop(head *cc.ChanCellHead) {
	terminate := false
	var (
		queryChan <-chan executorQuery
		queryCell *cc.ChanCell
	)
	chanFun := func(cell *cc.ChanCell) { queryChan, queryCell = exe.queryChan, cell }
	head.WithCell(chanFun)
	for !terminate {
		if msg, ok := <-queryChan; ok {
			switch query := msg.(type) {
			case shutdownQuery:
				terminate = true
			case applyQuery:
				query()
			default:
				log.Printf("Fatal to Executor: Received unexpected message: %#v", query)
				terminate = true
			}
		} else {
			head.Next(queryCell, chanFun)
		}
	}
	exe.cellTail.Terminate()
}
Ejemplo n.º 5
0
func (reader *mdbReader) actorLoop(readerHead *cc.ChanCellHead) {
	runtime.LockOSThread()
	var (
		err        error
		readerChan <-chan mdbQuery
		readerCell *cc.ChanCell
	)
	chanFun := func(cell *cc.ChanCell) { readerChan, readerCell = reader.server.readerChan, cell }
	readerHead.WithCell(chanFun)
	terminate := false
	for !terminate {
		if query, ok := <-readerChan; ok {
			switch msg := query.(type) {
			case *readonlyTransactionFuture:
				err = reader.handleRunTxn(msg)
			case *queryInternalShutdown:
				((*sync.WaitGroup)(msg)).Done()
				terminate = true
			default:
				err = UnexpectedMessage
			}
		} else {
			readerHead.Next(readerCell, chanFun)
		}
		terminate = terminate || err != nil
	}
	if err != nil {
		log.Println(err)
	}
}
Ejemplo n.º 6
0
func (cm *ConnectionManager) actorLoop(head *cc.ChanCellHead) {
	var (
		err       error
		queryChan <-chan connectionManagerMsg
		queryCell *cc.ChanCell
	)
	chanFun := func(cell *cc.ChanCell) { queryChan, queryCell = cm.queryChan, cell }
	head.WithCell(chanFun)
	terminate := false
	var shutdownChan chan struct{}
	for !terminate {
		if msg, ok := <-queryChan; ok {
			switch msgT := msg.(type) {
			case connectionManagerMsgShutdown:
				shutdownChan = msgT
				terminate = true
			case *connectionManagerMsgSetDesired:
				cm.setDesiredServers(msgT)
			case *connectionManagerMsgServerEstablished:
				cm.serverEstablished((*Connection)(msgT))
			case *connectionManagerMsgServerLost:
				cm.serverLost((*Connection)(msgT))
			case connectionManagerMsgSenderStart:
				cm.startSender(msgT.Sender)
			case connectionManagerMsgSenderFinished:
				cm.removeSender(msgT.Sender, msgT.resultChan)
			case *connectionManagerMsgSetTopology:
				cm.updateTopology((*server.Topology)(msgT))
			case *connectionManagerMsgGetTopology:
				cm.getTopology(msgT)
			case *connectionManagerMsgClientEstablished:
				cm.clientEstablished(msgT)
			case *connectionManagerMsgStatus:
				cm.status((*server.StatusConsumer)(msgT))
			}
			terminate = terminate || err != nil
		} else {
			head.Next(queryCell, chanFun)
		}
	}
	if err != nil {
		log.Println("ConnectionManager error:", err)
	}
	cm.cellTail.Terminate()
	for _, conn := range cm.servers {
		conn.Shutdown(true)
	}
	if shutdownChan != nil {
		close(shutdownChan)
	}
}
Ejemplo n.º 7
0
func (lc *LocalConnection) actorLoop(head *cc.ChanCellHead) {
	topology := lc.connectionManager.AddTopologySubscriber(eng.ConnectionSubscriber, lc)
	defer lc.connectionManager.RemoveTopologySubscriberAsync(eng.ConnectionSubscriber, lc)
	servers := lc.connectionManager.ClientEstablished(0, lc)
	defer lc.connectionManager.ClientLost(0, lc)
	lc.submitter.TopologyChanged(topology)
	lc.submitter.ServerConnectionsChanged(servers)
	var (
		err       error
		queryChan <-chan localConnectionMsg
		queryCell *cc.ChanCell
	)
	chanFun := func(cell *cc.ChanCell) { queryChan, queryCell = lc.queryChan, cell }
	head.WithCell(chanFun)
	terminate := false
	for !terminate {
		if msg, ok := <-queryChan; ok {
			switch msgT := msg.(type) {
			case localConnectionMsgShutdown:
				terminate = true
			case *localConnectionMsgTopologyChanged:
				lc.submitter.TopologyChanged(msgT.topology)
				msgT.maybeClose()
			case *localConnectionMsgRunTxn:
				lc.runTransaction(msgT)
			case *localConnectionMsgRunClientTxn:
				lc.runClientTransaction(msgT)
			case localConnectionMsgOutcomeReceived:
				lc.submitter.SubmissionOutcomeReceived(msgT.sender, msgT.txnId, msgT.outcome)
			case localConnectionMsgServerConnectionsChanged:
				lc.submitter.ServerConnectionsChanged((map[common.RMId]paxos.Connection)(msgT))
			case localConnectionMsgStatus:
				lc.status(msgT.StatusConsumer)
			default:
				err = fmt.Errorf("Fatal to LocalConnection: Received unexpected message: %#v", msgT)
			}
			terminate = terminate || err != nil
		} else {
			head.Next(queryCell, chanFun)
		}
	}
	if err != nil {
		log.Println("LocalConnection error:", err)
	}
	lc.submitter.Shutdown()
	lc.cellTail.Terminate()
}
Ejemplo n.º 8
0
func (lc *LocalConnection) actorLoop(head *cc.ChanCellHead) {
	lc.connectionManager.AddSender(lc)
	var (
		err       error
		queryChan <-chan localConnectionMsg
		queryCell *cc.ChanCell
	)
	chanFun := func(cell *cc.ChanCell) { queryChan, queryCell = lc.queryChan, cell }
	head.WithCell(chanFun)
	terminate := false
	for !terminate {
		if msg, ok := <-queryChan; ok {
			switch msgT := msg.(type) {
			case *localConnectionMsgShutdown:
				terminate = true
			case *localConnectionMsgTopologyChange:
				lc.submitter.TopologyChange(msgT.topology, msgT.servers)
			case *localConnectionMsgRunTxn:
				lc.runTransaction(msgT)
			case *localConnectionMsgRunClientTxn:
				lc.runClientTransaction(msgT)
			case localConnectionMsgOutcomeReceived:
				msgT(lc)
			case localConnectionMsgDisableHashCodes:
				lc.submitter.TopologyChange(nil, msgT)
			case *localConnectionMsgStatus:
				lc.status((*server.StatusConsumer)(msgT))
			}
			terminate = terminate || err != nil
		} else {
			head.Next(queryCell, chanFun)
		}
	}
	if err != nil {
		log.Println("LocalConnection error:", err)
	}
	lc.connectionManager.RemoveSenderAsync(lc)
	lc.submitter.Shutdown()
	lc.cellTail.Terminate()
}
Ejemplo n.º 9
0
func (exe *Executor) loop(head *cc.ChanCellHead) {
	terminate := false
	var (
		queryChan <-chan executorQuery
		queryCell *cc.ChanCell
	)
	chanFun := func(cell *cc.ChanCell) { queryChan, queryCell = exe.queryChan, cell }
	head.WithCell(chanFun)
	for !terminate {
		if msg, ok := <-queryChan; ok {
			switch query := msg.(type) {
			case *shutdownQuery:
				terminate = true
			case applyQuery:
				query()
			}
		} else {
			head.Next(queryCell, chanFun)
		}
	}
	exe.cellTail.Terminate()
}
Ejemplo n.º 10
0
func (server *MDBServer) actorLoop(writerHead *cc.ChanCellHead) {
	var (
		err        error
		writerChan <-chan mdbQuery
		writerCell *cc.ChanCell
	)
	chanFun := func(cell *cc.ChanCell) { writerChan, writerCell = server.writerChan, cell }
	writerHead.WithCell(chanFun)
	terminate := false
	for !terminate {
		if server.txn == nil {
			if query, ok := <-writerChan; ok {
				terminate, err = server.handleQuery(query)
			} else {
				writerHead.Next(writerCell, chanFun)
			}
		} else {
			select {
			case query, ok := <-writerChan:
				if ok {
					terminate, err = server.handleQuery(query)
				} else {
					writerHead.Next(writerCell, chanFun)
				}
			case <-server.ticker.C:
				err = server.commitTxns()
			default:
				err = server.commitTxns()
			}
		}
		terminate = terminate || err != nil
	}
	if err != nil {
		log.Println(err)
	}
	if err = server.commitTxns(); err != nil {
		log.Println(err)
	}
	server.writerCellTail.Terminate()
	server.handleShutdown()
	server.readerCellTail.Terminate()
}
Ejemplo n.º 11
0
func (cm *ConnectionManager) actorLoop(head *cc.ChanCellHead) {
	var (
		err       error
		queryChan <-chan connectionManagerMsg
		queryCell *cc.ChanCell
	)
	chanFun := func(cell *cc.ChanCell) { queryChan, queryCell = cm.queryChan, cell }
	head.WithCell(chanFun)
	terminate := false
	var shutdownChan chan struct{}
	for !terminate {
		if msg, ok := <-queryChan; ok {
			switch msgT := msg.(type) {
			case connectionManagerMsgShutdown:
				shutdownChan = msgT
				terminate = true
			case connectionManagerMsgSetDesired:
				cm.setDesiredServers(msgT)
			case *connectionManagerMsgServerEstablished:
				cm.serverEstablished(msgT)
			case connectionManagerMsgServerLost:
				cm.serverLost(msgT)
			case *connectionManagerMsgClientEstablished:
				cm.clientEstablished(msgT)
			case connectionManagerMsgSetTopology:
				cm.setTopology(msgT.topology, msgT.callbacks)
			case connectionManagerMsgServerConnAddSubscriber:
				cm.serverConnSubscribers.AddSubscriber(msgT.ServerConnectionSubscriber)
			case connectionManagerMsgServerConnRemoveSubscriber:
				cm.serverConnSubscribers.RemoveSubscriber(msgT.ServerConnectionSubscriber)
			case *connectionManagerMsgTopologyAddSubscriber:
				msgT.topology = cm.topology
				close(msgT.resultChan)
				cm.topologySubscribers.AddSubscriber(msgT.subType, msgT.TopologySubscriber)
			case connectionManagerMsgTopologyRemoveSubscriber:
				cm.topologySubscribers.RemoveSubscriber(msgT.subType, msgT.TopologySubscriber)
			case connectionManagerMsgRequestConfigChange:
				cm.Transmogrifier.RequestConfigurationChange(msgT.config)
			case connectionManagerMsgStatus:
				cm.status(msgT.StatusConsumer)
			default:
				err = fmt.Errorf("Fatal to ConnectionManager: Received unexpected message: %#v", msgT)
			}
			terminate = terminate || err != nil
		} else {
			head.Next(queryCell, chanFun)
		}
	}
	if err != nil {
		panic(err)
	}
	cm.cellTail.Terminate()
	for _, cd := range cm.servers {
		cd.Shutdown(paxos.Sync)
	}
	cm.RLock()
	for _, cc := range cm.connCountToClient {
		cc.Shutdown(paxos.Sync)
	}
	cm.RUnlock()
	if shutdownChan != nil {
		close(shutdownChan)
	}
}