We have 16384 hash slots. The hash slot of a given key is obtained * as the least significant 14 bits of the crc16 of the key. * * However if the key contains the {...} pattern, only the part between * { and } is hashed. This may be useful in the future to force certain * keys to be in the same node (assuming no resharding is in progress). */
| 3280 | * { and } is hashed. This may be useful in the future to force certain |
| 3281 | * keys to be in the same node (assuming no resharding is in progress). */ |
| 3282 | static unsigned int clusterManagerKeyHashSlot(char *key, int keylen) { |
| 3283 | int s, e; /* start-end indexes of { and } */ |
| 3284 | |
| 3285 | for (s = 0; s < keylen; s++) |
| 3286 | if (key[s] == '{') break; |
| 3287 | |
| 3288 | /* No '{' ? Hash the whole key. This is the base case. */ |
| 3289 | if (s == keylen) return crc16(key,keylen) & 0x3FFF; |
| 3290 | |
| 3291 | /* '{' found? Check if we have the corresponding '}'. */ |
| 3292 | for (e = s+1; e < keylen; e++) |
| 3293 | if (key[e] == '}') break; |
| 3294 | |
| 3295 | /* No '}' or nothing between {} ? Hash the whole key. */ |
| 3296 | if (e == keylen || e == s+1) return crc16(key,keylen) & 0x3FFF; |
| 3297 | |
| 3298 | /* If we are here there is both a { and a } on its right. Hash |
| 3299 | * what is in the middle between { and }. */ |
| 3300 | return crc16(key+s+1,e-s-1) & 0x3FFF; |
| 3301 | } |
| 3302 | |
| 3303 | /* Return a string representation of the cluster node. */ |
| 3304 | static sds clusterManagerNodeInfo(clusterManagerNode *node, int indent) { |
no test coverage detected