MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / clusterGenNodeDescription

Function clusterGenNodeDescription

src/cluster.cpp:4229–4303  ·  view source on GitHub ↗

Generate a csv-alike representation of the specified cluster node. * See clusterGenNodesDescription() top comment for more information. * * The function returns the string representation as an SDS string. */

Source from the content-addressed store, hash-verified

4227 *
4228 * The function returns the string representation as an SDS string. */
4229sds clusterGenNodeDescription(clusterNode *node, int use_pport) {
4230 int j, start;
4231 sds ci;
4232 int port = use_pport && node->pport ? node->pport : node->port;
4233
4234 /* Node coordinates */
4235 ci = sdscatlen(sdsempty(),node->name,CLUSTER_NAMELEN);
4236 ci = sdscatfmt(ci," %s:%i@%i ",
4237 node->ip,
4238 port,
4239 node->cport);
4240
4241 /* Flags */
4242 ci = representClusterNodeFlags(ci, node->flags);
4243
4244 /* Slave of... or just "-" */
4245 ci = sdscatlen(ci," ",1);
4246 if (node->slaveof)
4247 ci = sdscatlen(ci,node->slaveof->name,CLUSTER_NAMELEN);
4248 else
4249 ci = sdscatlen(ci,"-",1);
4250
4251 unsigned long long nodeEpoch = node->configEpoch;
4252 if (nodeIsSlave(node) && node->slaveof) {
4253 nodeEpoch = node->slaveof->configEpoch;
4254 }
4255 /* Latency from the POV of this node, config epoch, link status */
4256 ci = sdscatfmt(ci," %I %I %U %s",
4257 (long long) node->ping_sent,
4258 (long long) node->pong_received,
4259 nodeEpoch,
4260 (node->link || node->flags & CLUSTER_NODE_MYSELF) ?
4261 "connected" : "disconnected");
4262
4263 /* Slots served by this instance. If we already have slots info,
4264 * append it diretly, otherwise, generate slots only if it has. */
4265 if (node->slots_info) {
4266 ci = sdscatsds(ci, node->slots_info);
4267 } else if (node->numslots > 0) {
4268 start = -1;
4269 for (j = 0; j < CLUSTER_SLOTS; j++) {
4270 int bit;
4271
4272 if ((bit = clusterNodeGetSlotBit(node,j)) != 0) {
4273 if (start == -1) start = j;
4274 }
4275 if (start != -1 && (!bit || j == CLUSTER_SLOTS-1)) {
4276 if (bit && j == CLUSTER_SLOTS-1) j++;
4277
4278 if (start == j-1) {
4279 ci = sdscatfmt(ci," %i",start);
4280 } else {
4281 ci = sdscatfmt(ci," %i-%i",start,j-1);
4282 }
4283 start = -1;
4284 }
4285 }
4286 }

Callers 2

clusterCommandFunction · 0.85

Calls 7

sdscatlenFunction · 0.85
sdsemptyFunction · 0.85
sdscatfmtFunction · 0.85
sdscatsdsFunction · 0.85
clusterNodeGetSlotBitFunction · 0.85
sdscatprintfFunction · 0.85

Tested by

no test coverage detected