Distributing data across a sharded collection

Why do I get the following error?
There appears to be a valid replica set that is a shard with a primary node up and running,.

Error:
balancer:
Currently enabled: yes
Currently running: no
Balancer active window is set between and server local time
Failed balancer rounds in last 5 attempts: 5
Last reported error: Could not find host matching read preference { mode: “primary” } for set m103-repl

How can I fix it?

Thanks

shard status:

MongoDB Enterprise mongos> sh.status()
— Sharding Status —
sharding version: {
“_id” : 1,
“minCompatibleVersion” : 5,
“currentVersion” : 6,
“clusterId” : ObjectId(“5e304a2cb87942a203d25b38”)
}
shards:
{ “_id” : “m103-repl”, “host” : “m103-repl/192.168.103.100:27001,192.168.103.100:27002,m103:27003”, “state” : 1 }
active mongoses:
“3.6.16” : 1
autosplit:
Currently enabled: yes
balancer:
Currently enabled: yes
Currently running: no
Balancer active window is set between and server local time
Failed balancer rounds in last 5 attempts: 5
Last reported error: Could not find host matching read preference { mode: “primary” } for set m103-repl
Time of Reported error: Thu Jan 30 2020 21:29:22 GMT+0000 (UTC)
Migration Results for the last 24 hours:
No recent migrations
databases:
{ “_id” : “config”, “primary” : “config”, “partitioned” : true }
config.system.sessions
shard key: { “_id” : 1 }
unique: false
balancing: true
chunks:
m103-repl 1
{ “_id” : { “$minKey” : 1 } } -->> { “_id” : { “$maxKey” : 1 } } on : m103-repl Timestamp(2, 0)

MongoDB Enterprise mongos>

Status of replica set:
MongoDB Enterprise m103-repl:PRIMARY> rs.status()
{
“set” : “m103-repl”,
“date” : ISODate(“2020-01-30T21:56:47.527Z”),
“myState” : 1,
“term” : NumberLong(10),
“syncingTo” : “”,
“syncSourceHost” : “”,
“syncSourceId” : -1,
“heartbeatIntervalMillis” : NumberLong(2000),
“optimes” : {
“lastCommittedOpTime” : {
“ts” : Timestamp(1580421400, 1),
“t” : NumberLong(10)
},
“readConcernMajorityOpTime” : {
“ts” : Timestamp(1580421400, 1),
“t” : NumberLong(10)
},
“appliedOpTime” : {
“ts” : Timestamp(1580421400, 1),
“t” : NumberLong(10)
},
“durableOpTime” : {
“ts” : Timestamp(1580421400, 1),
“t” : NumberLong(10)
}
},
“members” : [
{
“_id” : 0,
“name” : “192.168.103.100:27001”,
“health” : 1,
“state” : 1,
“stateStr” : “PRIMARY”,
“uptime” : 2822,
“optime” : {
“ts” : Timestamp(1580421400, 1),
“t” : NumberLong(10)
},
“optimeDate” : ISODate(“2020-01-30T21:56:40Z”),
“syncingTo” : “”,
“syncSourceHost” : “”,
“syncSourceId” : -1,
“infoMessage” : “”,
“electionTime” : Timestamp(1580419768, 1),
“electionDate” : ISODate(“2020-01-30T21:29:28Z”),
“configVersion” : 5,
“self” : true,
“lastHeartbeatMessage” : “”
},
{
“_id” : 1,
“name” : “192.168.103.100:27002”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 1642,
“optime” : {
“ts” : Timestamp(1580421400, 1),
“t” : NumberLong(10)
},
“optimeDurable” : {
“ts” : Timestamp(1580421400, 1),
“t” : NumberLong(10)
},
“optimeDate” : ISODate(“2020-01-30T21:56:40Z”),
“optimeDurableDate” : ISODate(“2020-01-30T21:56:40Z”),
“lastHeartbeat” : ISODate(“2020-01-30T21:56:46.879Z”),
“lastHeartbeatRecv” : ISODate(“2020-01-30T21:56:47.482Z”),
“pingMs” : NumberLong(0),
“lastHeartbeatMessage” : “”,
“syncingTo” : “192.168.103.100:27001”,
“syncSourceHost” : “192.168.103.100:27001”,
“syncSourceId” : 0,
“infoMessage” : “”,
“configVersion” : 5
},
{
“_id” : 2,
“name” : “m103:27003”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 1628,
“optime” : {
“ts” : Timestamp(1580421400, 1),
“t” : NumberLong(10)
},
“optimeDurable” : {
“ts” : Timestamp(1580421400, 1),
“t” : NumberLong(10)
},
“optimeDate” : ISODate(“2020-01-30T21:56:40Z”),
“optimeDurableDate” : ISODate(“2020-01-30T21:56:40Z”),
“lastHeartbeat” : ISODate(“2020-01-30T21:56:46.879Z”),
“lastHeartbeatRecv” : ISODate(“2020-01-30T21:56:45.850Z”),
“pingMs” : NumberLong(0),
“lastHeartbeatMessage” : “”,
“syncingTo” : “192.168.103.100:27002”,
“syncSourceHost” : “192.168.103.100:27002”,
“syncSourceId” : 1,
“infoMessage” : “”,
“configVersion” : 5
}
],
“ok” : 1,
“operationTime” : Timestamp(1580421400, 1),
“$gleStats” : {
“lastOpTime” : Timestamp(0, 0),
“electionId” : ObjectId(“7fffffff000000000000000a”)
},
“$configServerState” : {
“opTime” : {
“ts” : Timestamp(1580421398, 1),
“t” : NumberLong(4)
}
},
“$clusterTime” : {
“clusterTime” : Timestamp(1580421400, 1),
“signature” : {
“hash” : BinData(0,“GUHSD/JBLjh+xsM67oMoqcjyzYc=”),
“keyId” : NumberLong(“6787006191286353946”)
}
}
}
MongoDB Enterprise m103-repl:PRIMARY>

Please check this line
{ “_id” : “m103-repl”, “host” : “m103-repl/192.168.103.100:27001,192.168.103.100:27002,m103:27003”, “state” : 1 }

3rd node added with hostname but other two with IP
I think m103 is not being resolved
Please check our forum.You will get tips for fixing this
You may need to edit your /etc/hosts

1 Like

Hi @Howard_84497,

As @Ramachandra_37567 mentioned, there might be an issue with the mapping of the Hostname and the IP address.

Please run this command at the vagrant prompt and share the output :

ping m103

Please have a look at this post.

Thanks,
Shubham Ranjan
Curriculum Services Engineer

I had edited this file previously to fix another error. It appears to be pointed in the correct direction.

vagrant@m103:~$ ping m103

PING m103.mongodb.university (192.168.103.100) 56(84) bytes of data.

64 bytes from m103.mongodb.university (192.168.103.100): icmp_seq=1 ttl=64 time=0.019 ms

64 bytes from m103.mongodb.university (192.168.103.100): icmp_seq=2 ttl=64 time=0.038 ms

64 bytes from m103.mongodb.university (192.168.103.100): icmp_seq=3 ttl=64 time=0.042 ms

64 bytes from m103.mongodb.university (192.168.103.100): icmp_seq=4 ttl=64 time=0.043 ms

64 bytes from m103.mongodb.university (192.168.103.100): icmp_seq=5 ttl=64 time=0.037 ms

And

vagrant@m103:~$ cat /etc/hosts

192.168.103.100
m103.mongodb.university
m103

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4

::1

localhost localhost.localdomain localhost6 localhost6.localdomain6

fe00::0 ip6-localnet

ff00::0 ip6-mcastprefix

ff02::1 ip6-allnodes

ff02::2 ip6-allrouters

ff02::3 ip6-allhosts

192.168.103.100 m103 m103

Hi @Howard_84497,

Okay great, so the hostname and IP address mapping is correct here.

So in this case, the error message that you are seeing in the Last reported error field is totally normal. It just tells you about the most recent error message thrown by the balancer.

I think you are good to go here. Please let me know if you are still facing any issue.

Happy Learning :slight_smile:

Thanks,
Shubham Ranjan
Curriculum Services Engineer