[SERVER-17904] Auto- and User-Generated-Shard Names May Colide Created: 07/Apr/15  Updated: 06/Dec/22  Resolved: 09/Dec/19

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: 3.0.1
Fix Version/s: 3.4.9

Type: Bug Priority: Minor - P4
Reporter: John Page Assignee: [DO NOT USE] Backlog - Sharding Team
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Sharding
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

echo "===> create directories"
mkdir config s1 s2 s3
 
echo "===> start mongodb instances:"
mongod --logpath s1.log --dbpath s1 --port 27016 --fork
mongod --logpath s2.log --dbpath s2 --port 27015 --fork
mongod --logpath s3.log --dbpath s3 --port 27014 --fork
 
mongod --logpath config.log --dbpath config --configsvr --port 27013 --fork
 
mongos --logpath mongos.log --port 27012 --configdb localhost:27013 --fork
 
ps -ef | grep mongo
echo -e "-----\n"
 
echo "===> add first shard with manual name"
mongo --port 27012 admin --eval 'printjson(db.runCommand({addShard: "127.0.0.1:27016", name: "shard1"}));'
echo -e "-----\n"
 
echo "===> add second shard with automatic name"
mongo --port 27012 admin --eval 'printjson(sh.addShard("127.0.0.1:27015"));'
echo -e "-----\n"
 
echo "===> add third shard with automatic name"
mongo --port 27012 admin --eval 'printjson(sh.addShard("127.0.0.1:27014"));'
echo -e "-----\n"
 
echo "===> sh.status()"
mongo --port 27012 admin --eval 'printjson(sh.status());'
echo -e "-----\n"
 
echo "shutting things down:"
for port in 27016 27015 27014 27013 27012; do
    echo "shutting down server on $port"
    mongo --port $port admin --quiet --eval "db.shutdownServer()"
done
echo -e "-----\n"
 
ps -ef | grep mongo

Participants:

 Description   

When I add a third shard to a cluster where the first one was explicitly named and the second wasn't I get a duplicate key error and cannot add the shard.

I saw this starting a cluster with mlaunch then adding a second shard.



 Comments   
Comment by Sheeri Cabral (Inactive) [ 09/Dec/19 ]

it has been fixed at least since 3.4 if not before.

Comment by Sam Kleinman (Inactive) [ 08/Apr/15 ]

Verified the issue. Appears to be in the logic for picking auto-generated shard names in this function: https://github.com/mongodb/mongo/blob/master/src/mongo/s/catalog/legacy/catalog_manager_legacy.cpp#L829-856

Comment by John Page [ 08/Apr/15 ]

That was a simple typo - all three shards have their own directories.

Notable that the first unnamed shard gets 0002 for some reason (not 0000 or 0001)

I don't have this set up anymore - but if you basically copy and paste the instructions do you not see the same error?

Comment by Sam Kleinman (Inactive) [ 08/Apr/15 ]

A few additional questions:

First, from the steps you provided, in shell 5, you started a second instance using the same dbpath as shard1/shell 3, and that nothing uses the shard3 directory. Is th

Second, could you provide the output of the following operation:

db.getSiblingDB("config").shards.find().toArray()

from the mongo shell while connected to a mongos?

Generated at Thu Feb 08 03:45:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.