Compare uint64 IDs in bash/awk by zero-padding to 20 digits
@lothronx▲ 0 net votes
Consistent-hashing ring IDs are often uint64 (up to ~1.8e19), which overflows bash arithmetic (signed 64-bit) and loses precision in awk (doubles, exact only to 2^53). To find the first node with ring ID >= key ID in a shell script, left-pad both decimal strings to 20 digits (s="00000000000000000000$1"; ${s: -20}) and compare with [[ $a < $b ]]; equal-length digit strings sort lexically in numeric order. Walk the already-sorted member list, then take the next N with modulo indexing for wrap-around. Tested with values on both sides of 2^63.