0

I want to create a replicaset of confiserver. For that I performed the following steps:

1. I created two config server using the following configs:

sharding:
 clusterRole: configsvr

replication:
 replSetName: TestConfigServer1

net:
 bindIp: 127.0.0.1
 port: 27018

storage:
 dbPath: E:\Programming\MongoDBProgramming\Mongodb

sharding:
 clusterRole: configsvr

replication:
 replSetName: TestConfigServer1

net:
 bindIp: 127.0.0.1
 port: 27019

storage:
 dbPath: E:\Programming\MongoDBProgramming\Mongodb1


2. Then I connected "mongo" to the first config, and ran following commands:

rs.initiate()
rs.add( {_id: 1,host: 127.0.0.1:27019} )

This created the replicaset with 27018 port as primary.

Then after closing all the mongod servers, I tried to start the replicaset again.

I started the port 27018 first using the corresponding config file, and then I tried started port 27019 the same way. For the 27019 I got the following error:

2020-05-20T21:48:37.449+0530 F - [replication-0] Fatal assertion 40088 InitialSyncFailure: error cloning databases :: caused by :: Location14037: Error cloning collection '.new_enrollment' :: caused by :: can't create user databases on a --configsvr instance at src\mongo\db\repl\replication_coordinator_impl.cpp 743

Also, when connected mongo shell to the 27018 server, and checked the replicaset status, then it showed the 27018 server as secondary. What am I doing wrong here?


Edit: Result from rs.status()

TestConfigServer1:SECONDARY> rs.status()
{
        "set" : "TestConfigServer1",
        "date" : ISODate("2020-05-20T17:03:47.950Z"),
        "myState" : 2,
        "term" : NumberLong(4),
        "syncingTo" : "",
        "syncSourceHost" : "",
        "syncSourceId" : -1,
        "configsvr" : true,
        "heartbeatIntervalMillis" : NumberLong(2000),
        "majorityVoteCount" : 2,
        "writeMajorityCount" : 2,
        "optimes" : {
                "lastCommittedOpTime" : {
                        "ts" : Timestamp(0, 0),
                        "t" : NumberLong(-1)
                },
                "lastCommittedWallTime" : ISODate("1970-01-01T00:00:00Z"),
                "appliedOpTime" : {
                        "ts" : Timestamp(1589991517, 1),
                        "t" : NumberLong(4)
                },
                "durableOpTime" : {
                        "ts" : Timestamp(1589991517, 1),
                        "t" : NumberLong(4)
                },
                "lastAppliedWallTime" : ISODate("2020-05-20T16:18:37.962Z"),
                "lastDurableWallTime" : ISODate("2020-05-20T16:18:37.962Z")
        },
        "lastStableRecoveryTimestamp" : Timestamp(1589907661, 1),
        "lastStableCheckpointTimestamp" : Timestamp(1589907661, 1),
        "members" : [
                {
                        "_id" : 0,
                        "name" : "127.0.0.1:27018",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 3168,
                        "optime" : {
                                "ts" : Timestamp(1589991517, 1),
                                "t" : NumberLong(4)
                        },
                        "optimeDate" : ISODate("2020-05-20T16:18:37Z"),
                        "syncingTo" : "",
                        "syncSourceHost" : "",
                        "syncSourceId" : -1,
                        "infoMessage" : "could not find member to sync from",
                        "configVersion" : 2,
                        "self" : true,
                        "lastHeartbeatMessage" : ""
                },
                {
                        "_id" : 1,
                        "name" : "127.0.0.1:27019",
                        "health" : 0,
                        "state" : 8,
                        "stateStr" : "(not reachable/healthy)",
                        "uptime" : 0,
                        "optime" : {
                                "ts" : Timestamp(0, 0),
                                "t" : NumberLong(-1)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(0, 0),
                                "t" : NumberLong(-1)
                        },
                        "optimeDate" : ISODate("1970-01-01T00:00:00Z"),
                        "optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"),
                        "lastHeartbeat" : ISODate("2020-05-20T17:03:46.549Z"),
                        "lastHeartbeatRecv" : ISODate("2020-05-20T16:18:37.166Z"),
                        "pingMs" : NumberLong(7),
                        "lastHeartbeatMessage" : "Error connecting to 127.0.0.1:27019 :: caused by :: No connection could be made because the target machine actively refused it.",
                        "syncingTo" : "",
                        "syncSourceHost" : "",
                        "syncSourceId" : -1,
                        "infoMessage" : "",
                        "configVersion" : -1
                }
        ],
        "ok" : 1,
        "$gleStats" : {
                "lastOpTime" : Timestamp(0, 0),
                "electionId" : ObjectId("7fffffff0000000000000004")
        },
        "lastCommittedOpTime" : Timestamp(0, 0),
        "$clusterTime" : {
                "clusterTime" : Timestamp(1589991517, 1),
                "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                        "keyId" : NumberLong(0)
                }
        },
        "operationTime" : Timestamp(1589991517, 1)
}
V K
  • 1,645
  • 3
  • 26
  • 57

1 Answers1

1

I'm guessing you started the first config server in a data directory that was previously used for another deployment. Start with an empty data directory.

D. SM
  • 13,584
  • 3
  • 12
  • 21
  • Yesterday, I ran the config server on the database path. Today I am facing this problem. So whenever I restart my server, do I have to create new database? – V K May 20 '20 at 17:07
  • No but you do need to keep the directories for each mongod instance separate and use each one appropriately. A name like `E:\Programming\MongoDBProgramming\Mongodb` doesn't tell you *what* is in that directory. – D. SM May 20 '20 at 17:20
  • It is separated, one is in Mongodb1 directory and the other in Mongodb. – V K May 21 '20 at 10:06
  • I gave different path for the 27019 server DB, but still got the same error. – V K May 21 '20 at 16:16
  • "new_enrollment" is a database you created at some point, yes? – D. SM May 21 '20 at 20:49
  • No, it is a collection. – V K May 22 '20 at 02:15
  • 1
    I don't think you can create a collection before you added the first shard. Of course, shards can be added only after initialization. Looks like you executed commands in wrong order. Stick stricktly to the order given in https://docs.mongodb.com/manual/tutorial/deploy-shard-cluster/index.html – Wernfried Domscheit May 22 '20 at 06:31
  • @WernfriedDomscheit I already had a databse, I was trying to create shards for that. – V K May 23 '20 at 16:05