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

Function RM_GetClusterNodeInfo

src/module.cpp:6350–6385  ·  view source on GitHub ↗

Populate the specified info for the node having as ID the specified 'id', * then returns REDISMODULE_OK. Otherwise if the node ID does not exist from * the POV of this local node, REDISMODULE_ERR is returned. * * The arguments `ip`, `master_id`, `port` and `flags` can be NULL in case we don't * need to populate back certain info. If an `ip` and `master_id` (only populated * if the instance i

Source from the content-addressed store, hash-verified

6348 * * REDISMODULE_NODE_NOFAILOVER: The slave is configured to never failover
6349 */
6350int RM_GetClusterNodeInfo(RedisModuleCtx *ctx, const char *id, char *ip, char *master_id, int *port, int *flags) {
6351 UNUSED(ctx);
6352
6353 clusterNode *node = clusterLookupNode(id);
6354 if (node == NULL ||
6355 node->flags & (CLUSTER_NODE_NOADDR|CLUSTER_NODE_HANDSHAKE))
6356 {
6357 return REDISMODULE_ERR;
6358 }
6359
6360 if (ip) strncpy(ip,node->ip,NET_IP_STR_LEN);
6361
6362 if (master_id) {
6363 /* If the information is not available, the function will set the
6364 * field to zero bytes, so that when the field can't be populated the
6365 * function kinda remains predictable. */
6366 if (node->flags & CLUSTER_NODE_SLAVE && node->slaveof)
6367 memcpy(master_id,node->slaveof->name,REDISMODULE_NODE_ID_LEN);
6368 else
6369 memset(master_id,0,REDISMODULE_NODE_ID_LEN);
6370 }
6371 if (port) *port = node->port;
6372
6373 /* As usually we have to remap flags for modules, in order to ensure
6374 * we can provide binary compatibility. */
6375 if (flags) {
6376 *flags = 0;
6377 if (node->flags & CLUSTER_NODE_MYSELF) *flags |= REDISMODULE_NODE_MYSELF;
6378 if (node->flags & CLUSTER_NODE_MASTER) *flags |= REDISMODULE_NODE_MASTER;
6379 if (node->flags & CLUSTER_NODE_SLAVE) *flags |= REDISMODULE_NODE_SLAVE;
6380 if (node->flags & CLUSTER_NODE_PFAIL) *flags |= REDISMODULE_NODE_PFAIL;
6381 if (node->flags & CLUSTER_NODE_FAIL) *flags |= REDISMODULE_NODE_FAIL;
6382 if (node->flags & CLUSTER_NODE_NOFAILOVER) *flags |= REDISMODULE_NODE_NOFAILOVER;
6383 }
6384 return REDISMODULE_OK;
6385}
6386
6387/* Set Redis Cluster flags in order to change the normal behavior of
6388 * Redis Cluster, especially with the goal of disabling certain functions.

Callers

nothing calls this directly

Calls 1

clusterLookupNodeFunction · 0.85

Tested by

no test coverage detected