Correct me if I'm wrong for Sharding/Replication

32 views
Skip to first unread message

Avise Sudhakar Rao

unread,
Oct 29, 2012, 3:16:59 AM10/29/12
to mongod...@googlegroups.com
Hi Team,

Can you let me know whether we need to include Arbiter also in the Cluster settings? (In the below example I had excluded Arbiter).

And also let me know for Production setup what all the careful step I should take.

And also in case of no unique value exist in the collection then how should I have shard collection key?

Sharding/Replication
2 Shards (each with two slaves)
========================================================

Replica Set 1
---------------------
mkdir /opt/data/11 /opt/data/22 /opt/data/33
mongod --dbpath /opt/data/11 --port 20001 --replSet rs_A  > /tmp/rs_A1.log &
mongod --dbpath /opt/data/22 --port 20002 --replSet rs_A > /tmp/rs_A2.log &
mongod --dbpath /opt/data/33 --port 20003 --replSet rs_A > /tmp/rs_A3.log &

mongo --port 20001
use admin

> rs.initiate({"_id": 'rs_A', members: [
                          {"_id": 0, "host": "localhost:20001"},
                          {"_id": 1, "host": "localhost:20002"},
                          {"_id": 2, "host": "localhost:20003", "arbiterOnly": true}]})


Replica Set 2
---------------------------

mkdir /opt/data/44 /opt/data/55 /opt/data/66
mongod --dbpath /opt/data/44 --port 30001 --replSet rs_B  > /tmp/rs_B1.log &
mongod --dbpath /opt/data/55 --port 30002 --replSet rs_B > /tmp/rs_B2.log &
mongod --dbpath /opt/data/66 --port 30003 --replSet rs_B > /tmp/rs_B3.log &

mongo --port 30001
use admin

> rs.initiate({"_id": 'rs_B', members: [
                          {"_id": 0, "host": "localhost:30001"},
                          {"_id": 1, "host": "localhost:30002"},
                          {"_id": 2, "host": "localhost:30003", "arbiterOnly": true}]})


Sharding Setting
-------------------------

Config Server settings:-

$ bin/mongod --configsvr --dbpath /data/example/config1 --port 40001
$ bin/mongod --configsvr --dbpath /data/example/config1 --port 40001
$ bin/mongod --configsvr --dbpath /data/example/config1 --port 40001

Config DB server settings:-

$ bin/mongos --configdb localhost:20001,localhost:20002,localhost:20003 --port 27017 --chunkSize 1

$ bin/mongos --configdb localhost:30001,localhost:30002,localhost:30003 --port 27018 --chunkSize 1

$ bin/mongo localhost:27017/admin
mongos> db.runCommand( { addshard : "rs_A/localhost:20001,localhost:20002" } )
{ "shardAdded" : "rs_A", "ok" : 1 }


$ bin/mongo localhost:27018/admin
mongos> db.runCommand( { addshard : "rs_B/localhost:30001,localhost:30002" } )
{ "shardAdded" : "rs_B", "ok" : 1 }


Thanks,
Sudhakar

Avise Sudhakar Rao

unread,
Oct 29, 2012, 3:44:59 AM10/29/12
to mongod...@googlegroups.com
Hello Team,

I got the answer for the first question, as even-though I add arbiter in the cluster settings mongo shard is good enough to exclude arbiter.

Below is the output what I received eventhough I add arbiter:-

(localhost:20003 and localhost:30003 is arbiter)

mongos>  db.runCommand( { addshard : "rs_A/localhost:20001,localhost:20002,localhost:20003" } )

{ "shardAdded" : "rs_A", "ok" : 1 }
mongos> db.runCommand( { addshard : "rs_B/localhost:30001,localhost:30002,localhost:30003" } )

{ "shardAdded" : "rs_B", "ok" : 1 }
mongos> db.runCommand({listshards:1})
{
        "shards" : [
                {
                        "_id" : "rs_A",
                        "host" : "rs_A/localhost:20001,localhost:20002"
                },
                {
                        "_id" : "rs_B",
                        "host" : "rs_B/localhost:30001,localhost:30002"
                }
        ],
        "ok" : 1
}
mongos>

Please let me the information on other two questions:-
2) And also let me know for Production setup what all the careful step I should take.
3) And also in case of no unique value exist in the collection then how should I have shard collection key?


Thanks,
Sudhakar

Jeremy Mikola

unread,
Oct 29, 2012, 12:58:55 PM10/29/12
to mongod...@googlegroups.com


On Monday, October 29, 2012 3:45:27 AM UTC-4, Sudhakar wrote:

Please let me the information on other two questions:-
2) And also let me know for Production setup what all the careful step I should take.

It looks like you're already on the right path with three config servers and replica sets for the shards themselves. The Sharding Architectures documentation discusses some aspects of properly designed production systems. For added redundancy, you may want to explore the Replication Architectures documentation and consider increasing the size of your replica sets for geographic distribution (e.g. a hidden secondary in another data center).
 
3) And also in case of no unique value exist in the collection then how should I have shard collection key?

Your documents will already have a unique _id, but you certainly don't need to include that in the shard key (and you likely never want to make it the shard key itself). Based on your schema, you will want to pick one or more fields across your documents to partition your collection into value ranges. The Sharding Internals documentation goes into detail about this, and discusses the impact of choosing different keys (e.g. write scaling, query isolation).
Reply all
Reply to author
Forward
0 new messages