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. */
| 4168 | * |
| 4169 | * The function returns the string representation as an SDS string. */ |
| 4170 | sds clusterGenNodeDescription(clusterNode *node, int use_pport) { |
| 4171 | int j, start; |
| 4172 | sds ci; |
| 4173 | int port = use_pport && node->pport ? node->pport : node->port; |
| 4174 | |
| 4175 | /* Node coordinates */ |
| 4176 | ci = sdscatlen(sdsempty(),node->name,CLUSTER_NAMELEN); |
| 4177 | ci = sdscatfmt(ci," %s:%i@%i ", |
| 4178 | node->ip, |
| 4179 | port, |
| 4180 | node->cport); |
| 4181 | |
| 4182 | /* Flags */ |
| 4183 | ci = representClusterNodeFlags(ci, node->flags); |
| 4184 | |
| 4185 | /* Slave of... or just "-" */ |
| 4186 | ci = sdscatlen(ci," ",1); |
| 4187 | if (node->slaveof) |
| 4188 | ci = sdscatlen(ci,node->slaveof->name,CLUSTER_NAMELEN); |
| 4189 | else |
| 4190 | ci = sdscatlen(ci,"-",1); |
| 4191 | |
| 4192 | unsigned long long nodeEpoch = node->configEpoch; |
| 4193 | if (nodeIsSlave(node) && node->slaveof) { |
| 4194 | nodeEpoch = node->slaveof->configEpoch; |
| 4195 | } |
| 4196 | /* Latency from the POV of this node, config epoch, link status */ |
| 4197 | ci = sdscatfmt(ci," %I %I %U %s", |
| 4198 | (long long) node->ping_sent, |
| 4199 | (long long) node->pong_received, |
| 4200 | nodeEpoch, |
| 4201 | (node->link || node->flags & CLUSTER_NODE_MYSELF) ? |
| 4202 | "connected" : "disconnected"); |
| 4203 | |
| 4204 | /* Slots served by this instance. If we already have slots info, |
| 4205 | * append it diretly, otherwise, generate slots only if it has. */ |
| 4206 | if (node->slots_info) { |
| 4207 | ci = sdscatsds(ci, node->slots_info); |
| 4208 | } else if (node->numslots > 0) { |
| 4209 | start = -1; |
| 4210 | for (j = 0; j < CLUSTER_SLOTS; j++) { |
| 4211 | int bit; |
| 4212 | |
| 4213 | if ((bit = clusterNodeGetSlotBit(node,j)) != 0) { |
| 4214 | if (start == -1) start = j; |
| 4215 | } |
| 4216 | if (start != -1 && (!bit || j == CLUSTER_SLOTS-1)) { |
| 4217 | if (bit && j == CLUSTER_SLOTS-1) j++; |
| 4218 | |
| 4219 | if (start == j-1) { |
| 4220 | ci = sdscatfmt(ci," %i",start); |
| 4221 | } else { |
| 4222 | ci = sdscatfmt(ci," %i-%i",start,j-1); |
| 4223 | } |
| 4224 | start = -1; |
| 4225 | } |
| 4226 | } |
| 4227 | } |
no test coverage detected