Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Harkrishn Patro <[email protected]>
  • Loading branch information
hpatro committed Jan 31, 2025
1 parent 79cacdf commit 708be26
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -4397,7 +4397,8 @@ static clusterMsgSendBlock *createModuleMsgBlock(int64_t module_id, uint8_t type
*
* If link is NULL, then the message is broadcasted to the whole cluster. */
void clusterSendModule(clusterLink *link, uint64_t module_id, uint8_t type, const char *payload, uint32_t len) {
clusterMsgSendBlock *msgblock = NULL, *msgblock_light = NULL;
clusterMsgSendBlock *msgblock[CLUSTERMSG_HDR_NUM];
memset(msgblock, 0, sizeof(msgblock));
ClusterNodeIterator iter;

if (link) {
Expand All @@ -4409,21 +4410,18 @@ void clusterSendModule(clusterLink *link, uint64_t module_id, uint8_t type, cons
clusterNode *node;
while ((node = clusterNodeIterNext(&iter)) != NULL) {
if (node->flags & (CLUSTER_NODE_MYSELF | CLUSTER_NODE_HANDSHAKE)) continue;
if (nodeSupportsLightMsgHdrForModule(node)) {
if (msgblock_light == NULL) {
msgblock_light = createModuleMsgBlock(module_id, type, payload, len, 1);
}
clusterSendMessage(node->link, msgblock_light);
} else {
if (msgblock == NULL) {
msgblock = createModuleMsgBlock(module_id, type, payload, len, 0);
}
clusterSendMessage(node->link, msgblock);
int is_light = nodeSupportsLightMsgHdrForModule(node) ? CLUSTERMSG_HDR_LIGHT : CLUSTERMSG_HDR_NORMAL;
if (msgblock[is_light] == NULL) {
msgblock[is_light] = createModuleMsgBlock(module_id, type, payload, len, is_light);
}
clusterSendMessage(node->link, msgblock[is_light]);
}
clusterNodeIterReset(&iter);
if (msgblock != NULL) clusterMsgSendBlockDecrRefCount(msgblock);
if (msgblock_light != NULL) clusterMsgSendBlockDecrRefCount(msgblock_light);
for (int hdr_type = CLUSTERMSG_HDR_NORMAL; hdr_type < CLUSTERMSG_HDR_NUM; hdr_type++) {
if (msgblock[hdr_type]) {
clusterMsgSendBlockDecrRefCount(msgblock[hdr_type]);
}
}
}

/* This function gets a cluster node ID string as target, the same way the nodes
Expand Down
8 changes: 8 additions & 0 deletions src/cluster_legacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ typedef struct clusterNodeFailReport {
/* We check for the modifier bit to determine if the message is sent using light header.*/
#define IS_LIGHT_MESSAGE(type) ((type) & CLUSTERMSG_LIGHT)

/* Types of header supported over the cluster bus. */
typedef enum {
CLUSTERMSG_HDR_NORMAL = 0, /* This corresponds to `clusterMsg` struct. */
CLUSTERMSG_HDR_LIGHT, /* This corresponds to `clusterMsgLight` struct. */
CLUSTERMSG_HDR_NUM, /* Overall count of header type supported. */
} clusterMsgHdrType;


/* Initially we don't know our "name", but we'll find it once we connect
* to the first node, using the getsockname() function. Then we'll use this
* address for all the next messages. */
Expand Down

0 comments on commit 708be26

Please sign in to comment.