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

Code before:

struct _clusterNode {
    mstime_t ctime;                         /* Node object creation time. */
    char name[CLUSTER_NAMELEN];             /* Node name, hex string, sha1-size */
    char shard_id[CLUSTER_NAMELEN];         /* shard id, hex string, sha1-size */
    int flags;                              /* CLUSTER_NODE_... */
    uint64_t configEpoch;                   /* Last configEpoch observed for this node */
    unsigned char slots[CLUSTER_SLOTS / 8]; /* slots handled by this node */
    uint16_t *slot_info_pairs;              /* Slots info represented as (start/end) pair (consecutive index). */
    int slot_info_pairs_count;              /* Used number of slots in slot_info_pairs */
    int numslots;                           /* Number of slots handled by this node */
    int num_replicas;                       /* Number of replica nodes, if this is a primary */
    clusterNode **replicas;                 /* pointers to replica nodes */
    clusterNode *replicaof;                 /* pointer to the primary node. Note that it
                                             may be NULL even if the node is a replica
                                             if we don't have the primary node in our
                                             tables. */
    unsigned long long last_in_ping_gossip; /* The number of the last carried in the ping gossip section */
    mstime_t ping_sent;                     /* Unix time we sent latest ping */
    mstime_t pong_received;                 /* Unix time we received the pong */
    mstime_t data_received;                 /* Unix time we received any data */
    mstime_t meet_sent;                     /* Unix time we sent latest meet packet */
    mstime_t fail_time;                     /* Unix time when FAIL flag was set */
    mstime_t repl_offset_time;              /* Unix time we received offset for this node */
    mstime_t orphaned_time;                 /* Starting time of orphaned primary condition */
    mstime_t last_connect_attempted;        /* Unix time we last tried to establish a link */
    mstime_t inbound_link_freed_time;       /* Last time we freed the inbound link for this node.
                                               If it was never freed, it is the same as ctime */
    long long repl_offset;                  /* Last known repl offset for this node. */
    char ip[NET_IP_STR_LEN];                /* Latest known IP address of this node */
    sds announce_client_ipv4;               /* IPv4 for clients only. */
    sds announce_client_ipv6;               /* IPv6 for clients only. */
    sds hostname;                           /* The known hostname for this node */
    sds human_nodename;                     /* The known human readable nodename for this node */
    int tcp_port;                           /* Latest known clients TCP port. */
    int tls_port;                           /* Latest known clients TLS port */
    int cport;                              /* Latest known cluster port of this node. */
    clusterLink *link;                      /* TCP/IP link established toward this node */
    clusterLink *inbound_link;              /* TCP/IP link accepted from this node */
    list *fail_reports;                     /* List of nodes signaling this as failing */
    int is_node_healthy;                    /* Boolean indicating the cached node health.
                                               Update with updateAndCountChangedNodeHealth(). */
};

/* Struct used for storing slot statistics. */
typedef struct slotStat {
    uint64_t cpu_usec;
    uint64_t network_bytes_in;
    uint64_t network_bytes_out;
} slotStat;


Review comment (suggestion):
Better to term it as 

```suggestion
    mstime_t outbound_link_attempt_time; /* Unix time we last tried to establish an outgoing link */
```

Code after:
static_assert(offsetof(clusterMsgLight, notused1) == offsetof(clusterMsg, port), "unexpected field offset");
static_assert(offsetof(clusterMsgLight, type) == offsetof(clusterMsg, type), "unexpected field offset");
static_assert(offsetof(clusterMsgLight, notused2) == offsetof(clusterMsg, count), "unexpected field offset");
static_assert(offsetof(clusterMsgLight, data) == 16, "unexpected field offset");

#define CLUSTERMSG_LIGHT_MIN_LEN (sizeof(clusterMsgLight) - sizeof(union clusterMsgData))

struct _clusterNode {
    mstime_t ctime;                         /* Node object creation time. */
    char name[CLUSTER_NAMELEN];             /* Node name, hex string, sha1-size */
    char shard_id[CLUSTER_NAMELEN];         /* shard id, hex string, sha1-size */
    int flags;                              /* CLUSTER_NODE_... */
    uint64_t configEpoch;                   /* Last configEpoch observed for this node */
    unsigned char slots[CLUSTER_SLOTS / 8]; /* slots handled by this node */
    uint16_t *slot_info_pairs;              /* Slots info represented as (start/end) pair (consecutive index). */
    int slot_info_pairs_count;              /* Used number of slots in slot_info_pairs */
    int numslots;                           /* Number of slots handled by this node */
    int num_replicas;                       /* Number of replica nodes, if this is a primary */
    clusterNode **replicas;                 /* pointers to replica nodes */
    clusterNode *replicaof;                 /* pointer to the primary node. Note that it
                                             may be NULL even if the node is a replica
                                             if we don't have the primary node in our
                                             tables. */
    unsigned long long last_in_ping_gossip; /* The number of the last carried in the ping gossip section */
    mstime_t ping_sent;                     /* Unix time we sent latest ping */
    mstime_t pong_received;                 /* Unix time we received the pong */
    mstime_t data_received;                 /* Unix time we received any data */
    mstime_t meet_sent;                     /* Unix time we sent latest meet packet */
    mstime_t fail_time;                     /* Unix time when FAIL flag was set */
    mstime_t orphaned_time;                 /* Starting time of orphaned primary condition */
    mstime_t outbound_link_attempt_time;    /* Unix time we last tried to establish an outgoing link */
    mstime_t inbound_link_freed_time;       /* Last time we freed the inbound link for this node.
                                               If it was never freed, it is the same as ctime */
    long long repl_offset;                  /* Last known repl offset for this node. */
    char ip[NET_IP_STR_LEN];                /* Latest known IP address of this node */
    sds announce_client_ipv4;               /* IPv4 for clients only. */
    sds announce_client_ipv6;               /* IPv6 for clients only. */
    sds hostname;                           /* The known hostname for this node */
    sds human_nodename;                     /* The known human readable nodename for this node */
    int tcp_port;                           /* Latest known clients TCP port. */
    int tls_port;                           /* Latest known clients TLS port */
    int cport;                              /* Latest known cluster port of this node. */
    clusterLink *link;                      /* TCP/IP link established toward this node */
    clusterLink *inbound_link;              /* TCP/IP link accepted from this node */
    list *fail_reports;                     /* List of nodes signaling this as failing */
    int is_node_healthy;                    /* Boolean indicating the cached node health.
                                               Update with updateAndCountChangedNodeHealth(). */
};

/* Struct used for storing slot statistics. */
typedef struct slotStat {