Repository: valkey-io/valkey
File: src/cluster_legacy.h (C/C++)

Code before:
#define CLUSTER_CANT_FAILOVER_WAITING_DELAY 2
#define CLUSTER_CANT_FAILOVER_EXPIRED 3
#define CLUSTER_CANT_FAILOVER_WAITING_VOTES 4
#define CLUSTER_CANT_FAILOVER_RELOG_PERIOD 1 /* seconds. */

/* clusterState todo_before_sleep flags. */
#define CLUSTER_TODO_HANDLE_FAILOVER (1 << 0)
#define CLUSTER_TODO_UPDATE_STATE (1 << 1)
#define CLUSTER_TODO_SAVE_CONFIG (1 << 2)
#define CLUSTER_TODO_FSYNC_CONFIG (1 << 3)
#define CLUSTER_TODO_HANDLE_MANUALFAILOVER (1 << 4)
#define CLUSTER_TODO_BROADCAST_ALL (1 << 5)

/* clusterLink encapsulates everything needed to talk with a remote node. */
typedef struct clusterLink {
    mstime_t ctime;                        /* Link creation time */
    connection *conn;                      /* Connection to remote node */
    list *send_msg_queue;                  /* List of messages to be sent */
    size_t head_msg_send_offset;           /* Number of bytes already sent of message at head of queue */
    unsigned long long send_msg_queue_mem; /* Memory in bytes used by message queue */
    char *rcvbuf;                          /* Packet reception buffer */
    size_t rcvbuf_len;                     /* Used size of rcvbuf */
    size_t rcvbuf_alloc;                   /* Allocated size of rcvbuf */
    clusterNode *node;                     /* Node related to this link. Initialized to NULL when unknown */
    int inbound;                           /* 1 if this link is an inbound link accepted from the related node */
    int support_extension;                 /* 1 if this link is support extension. */
} clusterLink;

/* Cluster node flags and macros. */
#define CLUSTER_NODE_PRIMARY (1 << 0)                      /* The node is a primary */
#define CLUSTER_NODE_REPLICA (1 << 1)                      /* The node is a replica */
#define CLUSTER_NODE_PFAIL (1 << 2)                        /* Failure? Need acknowledge */
#define CLUSTER_NODE_FAIL (1 << 3)                         /* The node is believed to be malfunctioning */
#define CLUSTER_NODE_MYSELF (1 << 4)                       /* This node is myself */
#define CLUSTER_NODE_HANDSHAKE (1 << 5)                    /* We have still to exchange the first ping */
#define CLUSTER_NODE_NOADDR (1 << 6)                       /* We don't know the address of this node */
#define CLUSTER_NODE_MEET (1 << 7)                         /* Send a MEET message to this node */
#define CLUSTER_NODE_MIGRATE_TO (1 << 8)                   /* Primary eligible for replica migration. */
#define CLUSTER_NODE_NOFAILOVER (1 << 9)                   /* Replica will not try to failover. */
#define CLUSTER_NODE_LIGHT_HDR_PUBLISH_SUPPORTED (1 << 11) /* This node supports light message header for publish type. */
#define CLUSTER_NODE_LIGHT_HDR_MODULE_SUPPORTED (1 << 12)  /* This node supports light message header for module type. */
#define CLUSTER_NODE_NULL_NAME                                                                                         \
    "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
    "\000\000\000\000\000\000\000\000\000\000\000\000"

#define nodeIsPrimary(n) ((n)->flags & CLUSTER_NODE_PRIMARY)
#define nodeIsReplica(n) ((n)->flags & CLUSTER_NODE_REPLICA)
#define nodeInHandshake(n) ((n)->flags & CLUSTER_NODE_HANDSHAKE)
#define nodeInMeetState(n) ((n)->flags & CLUSTER_NODE_MEET)
#define nodeHasAddr(n) (!((n)->flags & CLUSTER_NODE_NOADDR))
#define nodeTimedOut(n) ((n)->flags & CLUSTER_NODE_PFAIL)

Review comment (suggestion):
```suggestion
    int support_extension;                 /* 1 if this link supports passing extensions. */

Code after:
#define CLUSTER_CANT_FAILOVER_WAITING_DELAY 2
#define CLUSTER_CANT_FAILOVER_EXPIRED 3
#define CLUSTER_CANT_FAILOVER_WAITING_VOTES 4
#define CLUSTER_CANT_FAILOVER_RELOG_PERIOD 1 /* seconds. */

/* clusterState todo_before_sleep flags. */
#define CLUSTER_TODO_HANDLE_FAILOVER (1 << 0)
#define CLUSTER_TODO_UPDATE_STATE (1 << 1)
#define CLUSTER_TODO_SAVE_CONFIG (1 << 2)
#define CLUSTER_TODO_FSYNC_CONFIG (1 << 3)
#define CLUSTER_TODO_HANDLE_MANUALFAILOVER (1 << 4)
#define CLUSTER_TODO_BROADCAST_ALL (1 << 5)

/* clusterLink encapsulates everything needed to talk with a remote node. */
typedef struct clusterLink {
    mstime_t ctime;                        /* Link creation time */
    connection *conn;                      /* Connection to remote node */
    list *send_msg_queue;                  /* List of messages to be sent */
    size_t head_msg_send_offset;           /* Number of bytes already sent of message at head of queue */
    unsigned long long send_msg_queue_mem; /* Memory in bytes used by message queue */
    char *rcvbuf;                          /* Packet reception buffer */
    size_t rcvbuf_len;                     /* Used size of rcvbuf */
    size_t rcvbuf_alloc;                   /* Allocated size of rcvbuf */
    clusterNode *node;                     /* Node related to this link. Initialized to NULL when unknown */
    int inbound;                           /* 1 if this link is an inbound link accepted from the related node */
} clusterLink;

/* Cluster node flags and macros. */
#define CLUSTER_NODE_PRIMARY (1 << 0)                      /* The node is a primary */
#define CLUSTER_NODE_REPLICA (1 << 1)                      /* The node is a replica */
#define CLUSTER_NODE_PFAIL (1 << 2)                        /* Failure? Need acknowledge */
#define CLUSTER_NODE_FAIL (1 << 3)                         /* The node is believed to be malfunctioning */
#define CLUSTER_NODE_MYSELF (1 << 4)                       /* This node is myself */
#define CLUSTER_NODE_HANDSHAKE (1 << 5)                    /* We have still to exchange the first ping */
#define CLUSTER_NODE_NOADDR (1 << 6)                       /* We don't know the address of this node */
#define CLUSTER_NODE_MEET (1 << 7)                         /* Send a MEET message to this node */
#define CLUSTER_NODE_MIGRATE_TO (1 << 8)                   /* Primary eligible for replica migration. */
#define CLUSTER_NODE_NOFAILOVER (1 << 9)                   /* Replica will not try to failover. */
#define CLUSTER_NODE_EXTENSIONS_SUPPORTED (1 << 10)        /* This node supports extensions. */
#define CLUSTER_NODE_LIGHT_HDR_PUBLISH_SUPPORTED (1 << 11) /* This node supports light message header for publish type. */
#define CLUSTER_NODE_LIGHT_HDR_MODULE_SUPPORTED (1 << 12)  /* This node supports light message header for module type. */
#define CLUSTER_NODE_NULL_NAME                                                                                         \
    "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
    "\000\000\000\000\000\000\000\000\000\000\000\000"

#define nodeIsPrimary(n) ((n)->flags & CLUSTER_NODE_PRIMARY)
#define nodeIsReplica(n) ((n)->flags & CLUSTER_NODE_REPLICA)
#define nodeInHandshake(n) ((n)->flags & CLUSTER_NODE_HANDSHAKE)
#define nodeInMeetState(n) ((n)->flags & CLUSTER_NODE_MEET)
#define nodeHasAddr(n) (!((n)->flags & CLUSTER_NODE_NOADDR))
#define nodeTimedOut(n) ((n)->flags & CLUSTER_NODE_PFAIL)