[SERVER-1885] Host names must be distinct within first segment Created: 04/Oct/10  Updated: 12/Jul/16  Resolved: 21/Oct/10

Status: Closed
Project: Core Server
Component/s: Replication
Affects Version/s: 1.6.2
Fix Version/s: 1.7.2

Type: Bug Priority: Minor - P4
Reporter: Chris Johnson Assignee: Mathias Stearn
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Minor Change
Operating System: ALL
Participants:

 Description   

When setting up a replica set it appears only portion of the hostname up to the first period is checked for when doing the isSelf check. This results in a message about bad configs when attempting to use hosts of the following form:

mongo1.primary.domain.com
mongo1.backup.domain.com

I believe it is due to this portion of util/hostandport.h

86 /** returns true if strings seem to be the same hostname.
87 "nyc1" and "nyc1.acme.com" are treated as the same.
88 in fact "nyc1.foo.com" and "nyc1.acme.com" are treated the same -
89 we oly look up to the first period.
90 */
91 inline bool sameHostname(const string& a, const string& b)

{ 92 return str::before(a, '.') == str::before(b, '.'); 93 }

which appears to be called from the isSelf method in util/message.cpp which appears to be used in checkMembersUpForConfigChange of db/repl/rs_initiate.cpp

I was unable to find information indicating that this was an intentional restriction on hostnames.



 Comments   
Comment by Mathias Stearn [ 21/Oct/10 ]

We now only consider hostnames equal if they are the same or one is a dotted prefix of the other so that "a", "a.b", and "a.b.c" are all the same but "a.b", "a.c", and "a.com" are all considered distinct.

Comment by auto [ 21/Oct/10 ]

Author:

{'login': 'RedBeard0531', 'name': 'Mathias Stearn', 'email': 'mathias@10gen.com'}

Message: Better sameHostname() SERVER-1885
http://github.com/mongodb/mongo/commit/98a84c219dfa6ccae569fdcdea8f918f3273b5de

Comment by Dwight Merriman [ 21/Oct/10 ]

i agree it needs to be smarter.

the main case we need to handle is

host01
vs
host01.mycompany.com

thse might be the same host – we would want true for sameHost for this.

otherwise i totally agree.

Comment by Mathias Stearn [ 21/Oct/10 ]

@Dwight: why do we compare hostnames like this? Is there any downside to just checking for equality?

Generated at Thu Feb 08 02:58:20 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.