Chapter 1: Replica Set Transactions Lab: Error Handling

Following step’s now working for me.

mongo --eval ‘rs.initiate()’

mongo --eval ‘rs.add(“192.168.40.100:27027”);rs.add(“192.168.40.100:27037”)’

mongo --eval ‘conf = rs.conf();conf.members[0].host=“192.168.40.100:27017”;rs.reconfig(conf);’

vagrant@m040:/shared$ mongo --eval ‘rs.add(“192.168.40.100:27027”);rs.add(“192.168.40.100:27037”)’
MongoDB shell version v4.0.6
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“fdfe2cb7-ac30-4f5e-b840-9baa91457c5f”) }
MongoDB server version: 4.0.6
{
“operationTime” : Timestamp(1550951254, 1),
“ok” : 0,
“errmsg” : “replSetReconfig should only be run on PRIMARY, but my state is SECONDARY; use the “force” argument to override”,
“code” : 10107,
“codeName” : “NotMaster”,
“$clusterTime” : {
“clusterTime” : Timestamp(1550951254, 1),
“signature” : {
“hash” : BinData(0,“AAAAAAAAAAAAAAAAAAAAAAAAAAA=”),
“keyId” : NumberLong(0)
}
}
}

vagrant@m040:/shared$ mongo --eval ‘conf = rs.conf();conf.members[0].host=“192.168.40.100:27017”;rs.reconfig(conf);’
MongoDB shell version v4.0.6
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“ef1dc9b5-22d7-4ae4-bb54-004f507dc8f2”) }
MongoDB server version: 4.0.6
{
“operationTime” : Timestamp(1550951254, 1),
“ok” : 0,
“errmsg” : “replSetReconfig should only be run on PRIMARY, but my state is SECONDARY; use the “force” argument to override”,
“code” : 10107,
“codeName” : “NotMaster”,
“$clusterTime” : {
“clusterTime” : Timestamp(1550951254, 1),
“signature” : {
“hash” : BinData(0,“AAAAAAAAAAAAAAAAAAAAAAAAAAA=”),
“keyId” : NumberLong(0)
}
}
}

And furthermore, if I try loader.py

vagrant@m040:/shared$ python3 loader.py --uri “mongodb://m040:27017/m040?replicaSet=M040”
Traceback (most recent call last):
File “loader.py”, line 158, in
main(arguments)
File “loader.py”, line 122, in main
drop_dataset(uri)
File “loader.py”, line 29, in drop_dataset
db.drop_collection(‘cities’)
File “/usr/local/lib/python3.4/dist-packages/pymongo/database.py”, line 748, in drop_collection
with self.__client._socket_for_writes() as sock_info:
File “/usr/local/lib/python3.4/dist-packages/pymongo/mongo_client.py”, line 1085, in _socket_for_writes
server = self._get_topology().select_server(writable_server_selector)
File “/usr/local/lib/python3.4/dist-packages/pymongo/topology.py”, line 224, in select_server
address))
File “/usr/local/lib/python3.4/dist-packages/pymongo/topology.py”, line 183, in select_servers
selector, server_timeout, address)
File “/usr/local/lib/python3.4/dist-packages/pymongo/topology.py”, line 199, in _select_servers_loop
self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: No primary available for writes

vagrant@m040:/shared$ netstat -tlnp
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:27027 0.0.0.0:* LISTEN 2670/mongod
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:27037 0.0.0.0:* LISTEN 2757/mongod
tcp 0 0 0.0.0.0:37343 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 2588/mongod
tcp6 0 0 :::111 :::* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -
tcp6 0 0 :::59129 :::* LISTEN -

vagrant@m040:/shared$ mongo --port 27017
MongoDB shell version v4.0.6
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“c8b1049c-9d7b-448e-9b65-0da459dada46”) }
MongoDB server version: 4.0.6
Server has startup warnings:
2019-02-26T15:02:26.134+0000 I STORAGE [initandlisten]
2019-02-26T15:02:26.135+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-02-26T15:02:26.135+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-02-26T15:02:28.253+0000 I CONTROL [initandlisten]
2019-02-26T15:02:28.254+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-02-26T15:02:28.254+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-02-26T15:02:28.254+0000 I CONTROL [initandlisten]