Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-65103

incorrect HostAndPort alphabetical order

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 6.2.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Fully Compatible
    • ALL
    • Service Arch 2022-09-05, Service Arch 2022-09-19

      The alphabetical order of HostAndPort entries is significant in targeting hedged reads.
      But the order we use doesn't seem proper, as it's relying on the HostAndPort::toString.

      https://github.com/mongodb/mongo/blob/2c77d92ddcd9b1157cd13fb97dd3580b67e205a1/src/mongo/executor/network_interface_tl.cpp#L534-L541

       if (targetHostsInAlphabeticalOrder) {
              // Sort the target hosts by host names.
              std::sort(request.target.begin(),
                        request.target.end(),
                        [](const HostAndPort& target1, const HostAndPort& target2) {
                            return target1.toString() < target2.toString();
                        });
          }
      

      I can see a few problems with this.

      • DNS is case-insensitive, but this sort is not.
      • IPv6 addresses start with a "[", an ASCII character that falls between the A-Z and a-Z character ranges, so a hybrid IPv6/IPv4 set will I suppose end up with a the IPv4 addrs ordered with the uppercase hosts, then ALL the IPv6 hosts, and then the lowercase hosts. This is definitely not the intent of the sort.
      • It's expensive to compute toString on each of the NlogN comparisons of a sort.

            Assignee:
            celina.tala@mongodb.com Celina Tala
            Reporter:
            billy.donahue@mongodb.com Billy Donahue
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: