當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Node.IsMaster方法代碼示例

本文整理匯總了Golang中github.com/ksarch-saas/cc/topo.Node.IsMaster方法的典型用法代碼示例。如果您正苦於以下問題:Golang Node.IsMaster方法的具體用法?Golang Node.IsMaster怎麽用?Golang Node.IsMaster使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/ksarch-saas/cc/topo.Node的用法示例。


在下文中一共展示了Node.IsMaster方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: toReadable

func toReadable(node *topo.Node, state string) *RNode {
	if node == nil {
		return nil
	}

	var id string
	if context.Display == "simple" {
		id = node.Id[:6]
	} else {
		id = node.Id
	}
	n := &RNode{
		State:    state,
		Id:       id,
		ParentId: node.ParentId,
		Tag:      node.Tag,
		Role:     "S",
		Fail:     "OK",
		Mode:     "--",
		Addr:     fmt.Sprintf("%s:%d", node.Ip, node.Port),
		Keys:     node.SummaryInfo.Keys,
		Link:     node.SummaryInfo.MasterLinkStatus,
		QPS:      node.SummaryInfo.InstantaneousOpsPerSec,
	}

	if node.Role == "master" {
		n.Role = "M"
	}
	if node.Fail {
		n.Fail = "Fail"
	}
	if node.Readable && node.Writable {
		n.Mode = "rw"
	}
	if node.Readable && !node.Writable {
		n.Mode = "r-"
	}
	if !node.Readable && node.Writable {
		n.Mode = "-w"
	}
	if node.IsMaster() {
		n.Link = "-"
	}
	n.UsedMemory = fmt.Sprintf("%0.2fG", float64(node.SummaryInfo.UsedMemory)/1024.0/1024.0/1024.0)
	n.NetIn = fmt.Sprintf("%.2fKbps", node.SummaryInfo.InstantaneousInputKbps)
	n.NetOut = fmt.Sprintf("%.2fKbps", node.SummaryInfo.InstantaneousOutputKbps)
	n.Repl = fmt.Sprintf("%d", node.ReplOffset)
	return n
}
開發者ID:ksarch-saas,項目名稱:cc,代碼行數:49,代碼來源:nodes.go

示例2: initClusterTopo

func (self *Inspector) initClusterTopo(seed *topo.Node) (*topo.Cluster, error) {
	resp, err := redis.ClusterNodesInRegion(seed.Addr(), self.LocalRegion)
	if err != nil && strings.HasPrefix(err.Error(), "ERR Wrong CLUSTER subcommand or number of arguments") {
		//server version do not support 'cluster nodes extra [region]'
		resp, err = redis.ClusterNodes(seed.Addr())
	}
	if err != nil {
		return nil, err
	}

	cluster := topo.NewCluster(self.LocalRegion)

	var summary topo.SummaryInfo
	var nodeidx *topo.Node
	var cnt int

	lines := strings.Split(resp, "\n")
	cnt = 0
	for _, line := range lines {
		if strings.HasPrefix(line, "# ") {
			summary.ReadLine(line)
			continue
		}
		line = strings.TrimSpace(line)
		if line == "" {
			continue
		}
		node, myself, err := self.buildNode(line)
		if err == ErrNodeInHandShake || err == ErrNodeNoAddr {
			continue
		}
		// Fix 'cluster nodes extra' & 'cluster nodes extra region' compatiable
		if node.Region != self.LocalRegion {
			continue
		}
		if err != nil {
			return nil, err
		}
		if node.Ip == "127.0.0.1" {
			node.Ip = seed.Ip
		}
		// 遇到myself,讀取該節點的ClusterInfo
		if myself {
			info, err := redis.FetchClusterInfo(node.Addr())
			if err != nil {
				return nil, err
			}
			node.ClusterInfo = info
			node.SummaryInfo = summary
		}
		cluster.AddNode(node)
		nodeidx = node
		cnt++
	}
	if cnt == 1 {
		if nodeidx.IsMaster() && len(nodeidx.Ranges) == 0 {
			glog.Infof("Node %s is free node", nodeidx.Addr())
			nodeidx.SetFree(true)
		}
	}

	return cluster, nil
}
開發者ID:ksarch-saas,項目名稱:cc,代碼行數:63,代碼來源:inspector.go


注:本文中的github.com/ksarch-saas/cc/topo.Node.IsMaster方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。