Upgrading Cluster shards tinto ReplicaSets shards.

52 views
Skip to first unread message

Erez Zarum

unread,
Jan 13, 2011, 12:47:35 PM1/13/11
to mongod...@googlegroups.com
Hello,
I have 3 shards servers in a cluster, those shards server currently do
not have any replicasets configured.
I would like to upgrade them with replicasets.

for that i shutdown the whole cluster and started them with --replSet.
I also added another members and an arbiter.
This is the current configuration:
config0 - localhost:20000
mongos - localhost:27017
shard0 - localhost:10000 / replSet - localhost:10010 / arbiter -
localhost:10020
shard1 - localhost:10001 / replSet - localhost:10011 / arbiter -
localhost:10021
shard2 - localhost:10002 / replSet - localhost:10012 / arbiter -
localhost:10022

All work well between them, the failover works, but the real problem is
in the cluster.
because the cluster does not know that those shards are replicasets.

If i had built the cluster from scratch with those replicasets i know i
would have used: db.runCommand({ addshard : shard0/localhost:10000}); to
add a replicaset named shard0 to the cluster.
This will not work because the cluster already knows localhost:10000 and
i get an error
"can't add shard shard0/localhost:10000 because a local database
'shardDb' exists in another shard0000:localhost:10000

How can i modify the cluster configuration so it will be aware those
shards have replicasets?

Thanks!

Scott Hernandez

unread,
Jan 13, 2011, 1:07:07 PM1/13/11
to mongod...@googlegroups.com
The thing that strikes about this is that you really shouldn't be
using localhost (esp. for production systems). Why add more instances
on the same machine?

Is this a test configuration? If not, this seems like a bad idea.

> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mongodb-user?hl=en.
>
>

Erez Zarum

unread,
Jan 13, 2011, 1:33:59 PM1/13/11
to mongod...@googlegroups.com
Correct, this is a test configuration only.

Eliot Horowitz

unread,
Jan 13, 2011, 3:29:57 PM1/13/11
to mongod...@googlegroups.com
You would have to modify the config by hand, so great care must be used :)
You need to take down mongos, and edit the config db directly. The
shards collection specifically, and put it in the replset info
<name>/server1,server2

Erez Zarum

unread,
Jan 13, 2011, 3:26:20 PM1/13/11
to mongod...@googlegroups.com
Hey,
Thanks for your reply,
How would one do that?
Is there any documentation on that?

Thanks!!

Eliot Horowitz

unread,
Jan 13, 2011, 3:32:49 PM1/13/11
to mongod...@googlegroups.com
No documentation per se, but if you look at the config db, it should
pretty obvious.
Its a regular mongo collection, so you would just do an update() with
the shard name.
If you send db.shards.find() output, we can check you've got it right.

Erez Zarum

unread,
Jan 13, 2011, 3:49:03 PM1/13/11
to mongod...@googlegroups.com
As example:
# mongo
MongoDB shell version: 1.6.5
connecting to: test
> use config
switched to db config
> db.shards.find();
{ "_id" : "shard0000", "host" : "localhost:10001" }
{ "_id" : "shard0001", "host" : "localhost:10002" }
{ "_id" : "shard0002", "host" : "localhost:10003" }
{ "_id" : "shard0", "host" : "shard0/localhost:10000" }

Ofer Fort

unread,
Jan 13, 2011, 4:30:43 PM1/13/11
to mongod...@googlegroups.com
Is this only because the test env is on one server? Will this be any
different, in production when each shard is on it's own machine

Eliot Horowitz

unread,
Jan 13, 2011, 6:32:51 PM1/13/11
to mongod...@googlegroups.com
@ofer Not sure what you mean.
I would never recommend going into production with a single node
shard, so you should really never get into this state for real.

Erez Zarum

unread,
Jan 14, 2011, 3:24:14 AM1/14/11
to mongod...@googlegroups.com
How would i update the config database?
You are also writing: <name>/server1,server2, isn't it supposed to be
name/server1?
"If the individual shards consist of replica sets, they can be added by
specifying
replicaSetName/<serverhostname>[:port][,serverhostname2[:port],...],
where at least one server in the replica set is given."
So, everytime i add a new ReplicaSet member into the shard i need to
update the config server?

> db.shards.find();
{ "_id" : "shard0000", "host" : "localhost:10001" }
{ "_id" : "shard0001", "host" : "localhost:10002" }
{ "_id" : "shard0002", "host" : "localhost:10003" }
{ "_id" : "shard0", "host" : "shard0/localhost:10000" }

That's my config server, i have shutdown mongos and connect directly to
the config server.

Thanks!

Erez Zarum

unread,
Jan 14, 2011, 6:27:30 AM1/14/11
to mongod...@googlegroups.com
I think i figured out myself, please correct me if anything is wrong,
The shard i want to add have a replSetName "shard1", if i update the
config db i must retain the name of the previous shard as id (shard0000)
but the host should be shard1/localhost:10001.

example:

> db.shards.update( { _id: "shard0000" }, { _id: "shard1", "host" :
"shard1/localhost:10001" });
> db.shards.find();

{ "_id" : "shard0001", "host" : "localhost:10002" }
{ "_id" : "shard0002", "host" : "localhost:10003" }
{ "_id" : "shard0", "host" : "shard0/localhost:10000" }

{ "_id" : "shard1", "host" : "shard1/localhost:10001" }

mongos fails here.., he can't find shard0000 while doing a balance.

> db.shards.update({ _id : "shard0000" }, { _id : "shard0000", "host" :
"shard1/localhost:10001" });
> db.shards.find();


{ "_id" : "shard0001", "host" : "localhost:10002" }
{ "_id" : "shard0002", "host" : "localhost:10003" }
{ "_id" : "shard0", "host" : "shard0/localhost:10000" }

{ "_id" : "shard0000", "host" : "shard1/localhost:10001" }

mongos works, he can find shard0000 and also know it's a replicaset,
shard1/localhost...
Fri Jan 14 11:30:24 [Balancer] updated set to:
shard1/localhost:10001,localhost:10011

Correct?

Kristina Chodorow

unread,
Jan 14, 2011, 9:05:39 AM1/14/11
to mongod...@googlegroups.com
Yes, if it knows it's a replica set, it'll update its configuration as the set changes.
Reply all
Reply to author
Forward
0 new messages