MCPcopy Create free account
hub / github.com/apache/kvrocks-controller / GetClusterInfo

Method GetClusterInfo

store/cluster_node.go:176–208  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

174}
175
176func (n *ClusterNode) GetClusterInfo(ctx context.Context) (*ClusterInfo, error) {
177 infoStr, err := n.GetClient().ClusterInfo(ctx).Result()
178 if err != nil {
179 return nil, err
180 }
181
182 clusterInfo := &ClusterInfo{CurrentEpoch: -1}
183 lines := strings.Split(infoStr, "\r\n")
184 for _, line := range lines {
185 fields := strings.Split(line, ":")
186 if len(fields) != 2 {
187 continue
188 }
189 fields[1] = strings.TrimSpace(fields[1])
190 switch strings.ToLower(strings.TrimSpace(fields[0])) {
191 case "cluster_current_epoch":
192 clusterInfo.CurrentEpoch, err = strconv.ParseInt(fields[1], 10, 64)
193 if err != nil {
194 return nil, err
195 }
196 case "migrating_slot", "migrating_slot(s)":
197 // TODO(@git-hulk): handle multiple migrating slots
198 slotRange, err := ParseSlotRange(fields[1])
199 if err != nil {
200 return nil, err
201 }
202 clusterInfo.MigratingSlot = FromSlotRange(*slotRange)
203 case "migrating_state":
204 clusterInfo.MigratingState = fields[1]
205 }
206 }
207 return clusterInfo, nil
208}
209
210func (n *ClusterNode) GetClusterNodeInfo(ctx context.Context) (*ClusterNodeInfo, error) {
211 infoStr, err := n.GetClient().Info(ctx).Result()

Callers 2

CheckClusterModeMethod · 0.95
TestClusterNodeFunction · 0.95

Calls 3

GetClientMethod · 0.95
ParseSlotRangeFunction · 0.85
FromSlotRangeFunction · 0.85

Tested by 1

TestClusterNodeFunction · 0.76