[SERVER-65103] incorrect HostAndPort alphabetical order Created: 30/Mar/22  Updated: 29/Oct/23  Resolved: 15/Sep/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 6.2.0-rc0

Type: Bug Priority: Minor - P4
Reporter: Billy Donahue Assignee: Celina Tala
Resolution: Fixed Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Service Arch 2022-09-05, Service Arch 2022-09-19
Participants:

 Description   

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.


 Comments   
Comment by Githook User [ 14/Sep/22 ]

Author:

{'name': 'Celina Tala', 'email': 'celinahtala@gmail.com', 'username': 'celinatala-1'}

Message: SERVER-65103 Use case-insensitive comparator for sorting hedging targets in tests
Branch: master
https://github.com/mongodb/mongo/commit/52a951ea596b467ad9164b1410d5ebcce8050f2e

Comment by Billy Donahue [ 31/Mar/22 ]

I didn't observe a problem caused by this in tests. I'm just reading the code.

This could become an issue when running tests outside of Evergreen.

In an Evergreen build host, I suppose all the servers are co-hosted and hostnames are going to be identical and the HostAndPort will only vary by port number.

Comment by Max Hirschhorn [ 31/Mar/22 ]

My understanding of targetHostsInAlphabeticalOrder

bool targetHostsInAlphabeticalOrder =
    MONGO_unlikely(networkInterfaceSendRequestsToTargetHostsInAlphabeticalOrder.shouldFail(
        [request](const BSONObj&) { return request.hedgeOptions != boost::none; }));

is that it is only used to get a deterministic order of messages being dispatched for tests to assert results on. Do we know that the case-sensitivity or IPv6 address issues actually affect the behavior in practice in Evergreen?

Generated at Thu Feb 08 06:01:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.