Chapter 3: Sharding Lab - Configure a Sharded Cluster sh.addShard() error

MongoDB Enterprise mongos> sh.addShard("m103-repl/192.168.100.103:27001")
{
	"ok" : 0,
	"errmsg" : "Could not find host matching read preference { mode: \"primary\" } for set m103-repl",
	"code" : 133,
	"codeName" : "FailedToSatisfyReadPreference",
	"operationTime" : Timestamp(1541244613, 1),
	"$clusterTime" : {
		"clusterTime" : Timestamp(1541244613, 1),
		"signature" : {
			"hash" : BinData(0,"Ucq9J+peGR3Th8pVjzy7KwnJx7c="),
			"keyId" : NumberLong("6619575279322923034")
		}
	}
}

for help!

…while I kill all mongod and mongos process, then restarted, do what do before again, it’s work!..
I don’t know what’s reason, but it’s ok… :disappointed_relieved:

Well, that’s part of the learning experience, no?

Keep trying and keep figuring things out to understand what’s happening. You know what would be even cooler? If you managed to reproduce the earlier error situation, and went about troubleshooting.

MongoDB Enterprise mongos> sh.addShard("m103-repl/192.168.103.100:27001")
{
        "ok" : 0,
        "errmsg" : "Could not find host matching read preference { mode: \"primary\" } for set m103-repl",
        "code" : 133,
        "codeName" : "FailedToSatisfyReadPreference",
        "operationTime" : Timestamp(1548334263, 1),
        "$clusterTime" : {
                "clusterTime" : Timestamp(1548334263, 1),
                "signature" : {
                        "hash" : BinData(0,"Y4sz/z4AnlYjosytf0H+uifXA7U="),
                        "keyId" : NumberLong("6649631447575429142")
                }
        }
}

heldup here

Hi

Did you solve the error?

Yes
I used alias m103 in one of the config files which caused the error
Replaced with IP to make it work

1 Like

Aren’t your third and fourth octets of the IP address inverted? 192.168.103.100 instead of 192.168.100.103…

Hi
I am getting the same error,

MongoDB Enterprise mongos>  sh.addShard("m103-repl/192.168.103.100:27002")
{
        "ok" : 0,
        "errmsg" : "Could not find host matching read preference { mode: \"primary\" } for set m103-repl",
        "code" : 133,
        "codeName" : "FailedToSatisfyReadPreference",
        "operationTime" : Timestamp(1562498984, 1),
        "$clusterTime" : {
                "clusterTime" : Timestamp(1562498984, 1),
                "signature" : {
                        "hash" : BinData(0,"JVQ1fHHZ4WuAeYObKiYohrxrLws="),
                        "keyId" : NumberLong("6710653178980859910")
                }
        }
}
MongoDB Enterprise mongos>

I have checked the configuration files many times, I shutdown all the CSRS, Mongos, and the Replica set and start over twice, still the same issue.
also I checked the log files of monogs and replica set.

can you help!! thank you

Did you add first node-27001 as shard
Was it successful?
What does rs.status() & sh.status() show
May be issue with /etc/hosts for m103

This error is telling you that the replica set m103-repl doesn’t seem to have a primary node, and if everything is set up correctly then it should have one primary and two secondaries. If you connect the mongo shell to that replica set and run rs.status(), this’ll tell you about the members of the replica set. Does it have 3 members? Are any of them unhealthy / unreachable?

Hi Ramachandra
Yes I have tries with first node 27001, which is the primary , it thrown the same error in first place, then I have tries with 27002.
Also i checked the hosts file:
vagrant@m103:~ sudo cat /etc/hosts 127.0.1.1 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 vagrant@m103:~

Also I checked the keyfile and the permission on the directories.

Hi

Also cheked the rs.status ().
I have all the members:
There is only one member or RS is a ROLLBACK state:

here is the output of rs.status()

MongoDB Enterprise m103-repl:PRIMARY> rs.status()
{
        "set" : "m103-repl",
        "date" : ISODate("2019-07-07T18:18:44.968Z"),
        "myState" : 1,
        "term" : NumberLong(23),
        "syncingTo" : "",
        "syncSourceHost" : "",
        "syncSourceId" : -1,
        "heartbeatIntervalMillis" : NumberLong(2000),
        "optimes" : {
                "lastCommittedOpTime" : {
                        "ts" : Timestamp(1562523521, 1),
                        "t" : NumberLong(23)
                },
                "readConcernMajorityOpTime" : {
                        "ts" : Timestamp(1562523521, 1),
                        "t" : NumberLong(23)
                },
                "appliedOpTime" : {
                        "ts" : Timestamp(1562523521, 1),
                        "t" : NumberLong(23)
                },
                "durableOpTime" : {
                        "ts" : Timestamp(1562523521, 1),
                        "t" : NumberLong(23)
                }
        },
        "members" : [
                {
                        "_id" : 1,
                        "name" : "m103:27002",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 55713,
                        "optime" : {
                                "ts" : Timestamp(1562523521, 1),
                                "t" : NumberLong(23)
                        },
                        "optimeDate" : ISODate("2019-07-07T18:18:41Z"),
                        "syncingTo" : "",
                        "syncSourceHost" : "",
                        "syncSourceId" : -1,
                        "infoMessage" : "",
                        "electionTime" : Timestamp(1562519028, 1),
                        "electionDate" : ISODate("2019-07-07T17:03:48Z"),
                        "configVersion" : 5,
                        "self" : true,
                        "lastHeartbeatMessage" : ""
                },
                {
                        "_id" : 2,
                        "name" : "m103:27003",
                        "health" : 1,
                        "state" : 9,
                        "stateStr" : "ROLLBACK",
                        "uptime" : 36020,
                        "optime" : {
                                "ts" : Timestamp(1562064712, 1),
                                "t" : NumberLong(7)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(1562064712, 1),
                                "t" : NumberLong(7)
                        },
                        "optimeDate" : ISODate("2019-07-02T10:51:52Z"),
                        "optimeDurableDate" : ISODate("2019-07-02T10:51:52Z"),
                        "lastHeartbeat" : ISODate("2019-07-07T18:18:43.088Z"),
                        "lastHeartbeatRecv" : ISODate("2019-07-07T18:18:44.308Z"),
                        "pingMs" : NumberLong(0),
                        "lastHeartbeatMessage" : "",
                        "syncingTo" : "m103:27001",
                        "syncSourceHost" : "m103:27001",
                        "syncSourceId" : 3,
                        "infoMessage" : "",
                        "configVersion" : 5
                },
                {
                        "_id" : 3,
                        "name" : "m103:27001",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 36020,
                        "optime" : {
                                "ts" : Timestamp(1562523521, 1),
                                "t" : NumberLong(23)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(1562523521, 1),
                                "t" : NumberLong(23)
                        },
                        "optimeDate" : ISODate("2019-07-07T18:18:41Z"),
                        "optimeDurableDate" : ISODate("2019-07-07T18:18:41Z"),
                        "lastHeartbeat" : ISODate("2019-07-07T18:18:43.358Z"),
                        "lastHeartbeatRecv" : ISODate("2019-07-07T18:18:44.388Z"),
                        "pingMs" : NumberLong(0),
                        "lastHeartbeatMessage" : "",
                        "syncingTo" : "m103:27002",
                        "syncSourceHost" : "m103:27002",
                        "syncSourceId" : 1,
                        "infoMessage" : "",
                        "configVersion" : 5
                }
        ],
        "ok" : 1
}
MongoDB Enterprise m103-repl:PRIMARY>

One more thing . I have re-configure the replica set with the ip rather than the host name .

Hi
Thanks all for your help!!
I fixed the issue by rebuild the replica set from scratch . and it did works

1 Like

One more thing:

This is the full step hope it will be useful for reference: :sunglasses:


vagrant@m103:~$ mongo --port 26000 -u m103-admin -p "m103-pass" --authenticationDatabase admin
MongoDB shell version v3.6.11
connecting to: mongodb://127.0.0.1:26000/?authSource=admin&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("905219ad-74e2-4f88-bf97-14638584be49") }
MongoDB server version: 3.6.11
MongoDB Enterprise mongos>
MongoDB Enterprise mongos>
MongoDB Enterprise mongos>
MongoDB Enterprise mongos>
MongoDB Enterprise mongos> sh.status()
--- Sharding Status ---
  sharding version: {
        "_id" : 1,
        "minCompatibleVersion" : 5,
        "currentVersion" : 6,
        "clusterId" : ObjectId("5d6148cc9bb0a8d2db906ce7")
  }
  shards:
  active mongoses:
        "3.6.11" : 1
  autosplit:
        Currently enabled: yes
  balancer:
        Currently enabled:  yes
        Currently running:  no
        Failed balancer rounds in last 5 attempts:  0
        Migration Results for the last 24 hours:
                No recent migrations
  databases:
        {  "_id" : "config",  "primary" : "config",  "partitioned" : true }

MongoDB Enterprise mongos>
MongoDB Enterprise mongos>
MongoDB Enterprise mongos>
MongoDB Enterprise mongos>
MongoDB Enterprise mongos>
MongoDB Enterprise mongos>
MongoDB Enterprise mongos> sh.addShard(m103-repl/192.168.103.100:27001)
2019-08-24T15:33:05.777+0000 E QUERY    [thread1] SyntaxError: missing ) after argument list @(shell):1:29
MongoDB Enterprise mongos>
MongoDB Enterprise mongos>
MongoDB Enterprise mongos> use admin;
switched to db admin
MongoDB Enterprise mongos> sh.status()
--- Sharding Status ---
  sharding version: {
        "_id" : 1,
        "minCompatibleVersion" : 5,
        "currentVersion" : 6,
        "clusterId" : ObjectId("5d6148cc9bb0a8d2db906ce7")
  }
  shards:
  active mongoses:
        "3.6.11" : 1
  autosplit:
        Currently enabled: yes
  balancer:
        Currently enabled:  yes
        Currently running:  no
        Failed balancer rounds in last 5 attempts:  0
        Migration Results for the last 24 hours:
                No recent migrations
  databases:
        {  "_id" : "config",  "primary" : "config",  "partitioned" : true }

MongoDB Enterprise mongos> sh.addShard("m103-repl/192.168.103.100:27001")
{
        "shardAdded" : "m103-repl",
        "ok" : 1,
        "operationTime" : Timestamp(1566660926, 10),
        "$clusterTime" : {
                "clusterTime" : Timestamp(1566660926, 10),
                "signature" : {
                        "hash" : BinData(0,"lGgmzfISdHpLgUwWi+LxxXEOt4I="),
                        "keyId" : NumberLong("6728739359278759955")
                }
        }
}
MongoDB Enterprise mongos> sh.status()
--- Sharding Status ---
  sharding version: {
        "_id" : 1,
        "minCompatibleVersion" : 5,
        "currentVersion" : 6,
        "clusterId" : ObjectId("5d6148cc9bb0a8d2db906ce7")
  }
  shards:
        {  "_id" : "m103-repl",  "host" : "m103-repl/192.168.103.100:27001,192.168.103.100:27002,192.168.103.100:27003",  "state" : 1 }
  active mongoses:
        "3.6.11" : 1
  autosplit:
        Currently enabled: yes
  balancer:
        Currently enabled:  yes
        Currently running:  no
        Failed balancer rounds in last 5 attempts:  0
        Migration Results for the last 24 hours:
                No recent migrations
  databases:
        {  "_id" : "config",  "primary" : "config",  "partitioned" : true }

MongoDB Enterprise mongos>
MongoDB Enterprise mongos>
MongoDB Enterprise mongos>
MongoDB Enterprise mongos>
MongoDB Enterprise mongos>
MongoDB Enterprise mongos>

Hello. I am not sure but probably there is an error in the quiz. The speaker of the lecture “Balancing” says that mongos was used to run the balancing process in prior version of mongoDb. Nevertheless, mongos is not the correct answer.

Hello @Maksim_Pashkov, sorry about the late reply – thanks for the message.

The clarification in the Problem is “a sharded cluster running MongoDB 3.6”, signifying that we are asking specifically about later versions of MongoDB, where Balancing is handled by the primary node of the Config Server Replica Set (CSRS).

I hope this helps answer your question. Good luck in the rest of the course!

Matt

1 Like