Пример #1
0
func (cs *ClusterService) RemoteContactMaster(msg *comm.Message) {
	myNode := cs.cluster.MyNode
	log.Debug("%d: Got a ContactMaster request: %s", myNode.Id, msg)

	if cs.state == state_online {
		masters := cs.cluster.Rings.GetRing(cs.masterRing).ResolveToken(master_token)

		// make sure I'm the master, and online
		if myNode.Status == cluster.Status_Online && masters.IsFirst(myNode) {
			node := cluster.NewEmptyNode()
			err := node.Unserialize(msg.Message)
			if err != nil {
				cs.comm.RespondError(msg, os.NewError("Couldn't unmarshal node data"))
				log.Error("Couldn't unmarshal node data: %s", err)
				return
			}

			node.Status = cluster.Status_Online
			cs.cluster.MergeNode(node, true)

			// TODO: Send the cluster back to the node
			resp := cs.comm.NewMsgMessage(cs.serviceId)
			cs.comm.RespondSource(msg, resp)
			//log.Fatal("BLABLA", node.Id)

			// TODO: LOCK SO THAT WE DON'T MAKE IT ONLINE TWICE

			// TODO: Accept the node
			// TODO: Check its rings
			// TODO: Broadcast the change
		} else {
			cs.comm.RedirectFirst(masters, msg)
		}
	}
}
Пример #2
0
func (dm *clusterMutation) Unserialize(reader typedio.Reader) {
	dm.version, _ = reader.ReadInt64()
	nbNodes, _ := reader.ReadUint16()
	dm.nodes = make([]*cluster.Node, nbNodes)

	var i uint16
	for i = 0; i < nbNodes; i++ {
		node := cluster.NewEmptyNode()
		node.Unserialize(reader)
		dm.nodes[i] = node
	}
}
Пример #3
0
func (cs *ClusterService) loadCluster() {
	cs.clusterMutex.Lock()

	// Load data
	log.Debug("cls: Loading cluster data...")
	stat, err := os.Stat(cs.clsDataPath)
	if err == nil && stat.IsRegular() {
		file, err := os.Open(cs.clsDataPath)
		if err == nil {
			typedFile := typedio.NewReader(file)

			cs.clusterVersion, _ = typedFile.ReadInt64() // cluster version
			cs.diskVerson = cs.clusterVersion

			nbNodes, _ := typedFile.ReadUint16() // nodes count
			var i uint16
			for i = 0; i < nbNodes; i++ {
				node := cluster.NewEmptyNode()
				node.Unserialize(typedFile)

				node.Status = cluster.Status_Offline

				cs.cluster.MergeNode(node, false) // merge node, doesn't notify
			}

		} else {
			log.Error("cls: Error while opening data file", err)
		}
	}

	// replay commit log
	log.Info("cls: Replaying commit log...")
	cs.commitlog.Replay()

	// TODO: Load cluster data

	cs.clusterMutex.Unlock()
}