Questions on Enabling Sharding on a Database ( pre-sharded confguration)

55 views
Skip to first unread message

Dmitriy Royzenberg

unread,
Feb 22, 2011, 3:53:47 PM2/22/11
to mongod...@googlegroups.com
http://www.mongodb.org/display/DOCS/Configuring+Sharding
Can you please clarify the statement in "Enabling Sharding on a Database" section:
Once enabled, mongos will place new collections on the primary shard for that database.
Existing collections within the database will stay on the original shard.
Question:
1) Isn't that the original shard and primary shard are the same thing here?

2) If I'd like to configure sharding configuration to take advantage of mongos routing, but not yet shard my data (be kind of ready when i need it)
   do I need to issue db.runCommand( { enablesharding : "<dbname>" } ); or not?
   What would be a difference to issue or not to issue the command in case if I have only one shard?

3) Is it possible to configure mongos without sharding and only with replica sets?



Gates

unread,
Feb 22, 2011, 5:52:35 PM2/22/11
to mongodb-user
> 1) Isn't that the original shard and primary shard are the same thing here?

Not necessarily. A new shard with no data could become the "primary"
for new collections.

> 3) Is it possible to configure mongos without sharding and only with replica sets?

No. If you look at mongos, it only connects to the config DB(s). So
you need a Config DB + a router (mongoS)

> 2) ..do I need to issue db.runCommand( { enablesharding : "<dbname>" } ); or not?

If you do not issue this command, then the Config DB will not be able
to find the <dbname>. So until you issue this command the router
(mongoS) will not be able to find any of your existing data.

> What would be a difference to issue or not to issue the command in case if I have only one shard?

The data will not be accessible from MongoS until you shard it.

Andrew Armstrong

unread,
Feb 22, 2011, 6:50:46 PM2/22/11
to mongodb-user
Hm, so does that mean if you have a sharded database (and a client
talks via mongos) and an unsharded database, the client who connects
via mongos wont see the unsharded database?

And they'd need to explicitly connect to the right server?

Seems easier to just always shard in that case.

Gaetan Voyer-Perrault

unread,
Feb 22, 2011, 7:31:29 PM2/22/11
to mongod...@googlegroups.com
Seems easier to just always shard in that case.

Kind of, except that you then need to add a config db (or three) and you need to run MongoS on all of your web servers. So you definitely add a bunch of moving parts.

--
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.


Gates

unread,
Feb 22, 2011, 5:08:51 PM2/22/11
to mongodb-user
> 1) Isn't that the original shard and primary shard are the same thing here?

Not necessarily. A new shard with no data could become the "primary"
for new collections.

> 3) Is it possible to configure mongos without sharding and only with replica sets?

No. If you look at mongos, it only connects to the config DB(s). So
you need a Config DB + a router (mongoS)

> 2) ..do I need to issue db.runCommand( { enablesharding : "<dbname>" } ); or not?

If you do not issue this command, then the Config DB will not be able
to find the <dbname>. So until you issue this command the router
(mongoS) will not be able to find any of your existing data.

> What would be a difference to issue or not to issue the command in case if I have only one shard?

The data will not be accessible from MongoS until you shard it.

- Gates

On Feb 22, 12:53 pm, Dmitriy Royzenberg <ccmdmit...@gmail.com> wrote:

Eliot Horowitz

unread,
Feb 23, 2011, 5:36:37 AM2/23/11
to mongod...@googlegroups.com
That's not quite right.

You can mix and match sharded and unsharded dbs and collections very easily.

For example, you can have 3 databases in a cluster, only 1 of which
has sharding enabled.

The other 2 dbs will live entirely on 1 shard and mongos will route.

For the 1 sharded db, it can have sharded and non-sharded collections
as well and all will be routed through mongos.

Dmitriy Royzenberg

unread,
Feb 23, 2011, 12:31:34 PM2/23/11
to mongodb-user



>
> > 2) ..do I need to issue db.runCommand( { enablesharding : "<dbname>" } ); or not?
>
> If you do not issue this command, then the Config DB will not be able
> to find the <dbname>. So until you issue this command the router
> (mongoS) will not be able to find any of your existing data.
>
> > What would be a difference to issue or not to issue the command in case if I have only one shard?
>
> The data will not be accessible from MongoS until you shard it.


Thanks, Eliot
Just to clarify my understanding to the answer above.
So in case if I want mongos routing but not yet shard my data ( and
lets say I have 3 databases with 4 collection in each)

Once I setup my replica sets ( lets say 3 in total) with only One
shard.
I have to issue :
db.runCommand( { enablesharding : "<dbname>" } ); for each database
name in order for mongos to access it.
But I Don't need to shard individual collections. as I can do it later
when I have the need.
is that correct?

Thanks,
Dmitriy

Eliot Horowitz

unread,
Feb 23, 2011, 5:28:46 PM2/23/11
to mongod...@googlegroups.com
No, you don't need to do anything.
Just bring up 3 empty shards.
Call addShard.
Then just start using as normal.

Dmitriy Royzenberg

unread,
Feb 24, 2011, 9:54:20 AM2/24/11
to mongodb-user
hmm. Interesting,
Can you clarify why it is sufficient, as earlier Gates posted that:
"If you do not issue this command, then the Config DB will not be able
to find the <dbname>. So until you issue this command the router
(mongoS) will not be able to find any of your existing data. "

So. will mongos see my data w/o the command or not?

Thanks

Eliot Horowitz

unread,
Feb 24, 2011, 11:11:57 AM2/24/11
to mongod...@googlegroups.com
IN my email i send empty shards.
If you have existing data, its a tiny bit different.

Bring up mongos
add only old shard with existing data
access it, mongos will learn where it is.
Add more shards.

Dmitriy Royzenberg

unread,
Feb 24, 2011, 10:59:48 PM2/24/11
to mongodb-user
Thanks that's helpful!
Reply all
Reply to author
Forward
0 new messages