Not sharded collection in other replica

79 views
Skip to first unread message

jean carlo

unread,
Nov 16, 2012, 12:05:50 PM11/16/12
to mongod...@googlegroups.com
Hi guys, I have 3 shards and each has  a replica of three machines.

When I have created a collection not sharded throw mongos, this collections is stored in the first shard1 ( I do  not why)  and the others not sharded collection too.

So this is a problem, beacause my cluster has a lot of traffic over this collections not sharded and we have a whole cluster where only one machine ( the primary replica of the shar1) get all the traffic.

How can I move this collections to another replica, or shard?. And how can I set the mongos to know where is this collection which has been moved?

I do a cloneCollection from a primary replica (shard1) to another primary replica(shar2) and thas works but when I do a insert throw mongos, it still insert over the collection in shar1 and does not over the shar2. 


--

Este mensaje y sus adjuntos se dirigen exclusivamente a su destinatario, puede contener información privilegiada o confidencial y es para uso exclusivo de la persona o entidad de destino. Si no es usted. el destinatario indicado, queda notificado de que la lectura, utilización, divulgación y/o copia sin autorización puede estar prohibida en virtud de la legislación vigente. Si ha recibido este mensaje por error, le rogamos que nos lo comunique inmediatamente por esta misma vía y proceda a su destrucción.

The information contained in this transmission is privileged and confidential information intended only for the use of the individual or entity named above. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this transmission in error, do not read it. Please immediately reply to the sender that you have received this communication in error and then delete it.

gregor

unread,
Nov 16, 2012, 12:16:41 PM11/16/12
to mongod...@googlegroups.com
If you have sharded a database all unsharded collections in that shard are help on the primary shard
You can move the primary shard with this command. 

All unsharded collections will move to the new primary. The only way to have unsharded collections on different shards is to have them in different databases with different primary shards.

Jean Carlo Rivera

unread,
Nov 16, 2012, 12:38:46 PM11/16/12
to mongod...@googlegroups.com
Thank you very much for you reply gregor.

About movePrimary, I've read the documentation and it seem to need a empty shard to do the movePrimary

Important

 

Only use movePrimary when:

  • the database does not contain any collections with data, or
  • you have drained all sharded collections using the removeShard command.

See Remove Shards from an Existing Sharded Cluster for a complete procedure.


because all my shards has data and this is a  production cluster. 


I'm rigtht?



--
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
See also the IRC channel -- freenode.net#mongodb



--

Saludos

Jean Carlo Rivera
-------

gregor

unread,
Nov 16, 2012, 1:28:37 PM11/16/12
to mongod...@googlegroups.com
My bad you are right. If you do a cloneCollection "data" from database "a" with primary shard "shard1" to database "b" with primary shard "shard2"  then  b.data.find() returns nothing? Are you calling cloneCollection from mongos? What does b.data.find().explain(0 reutrn?

Jean Carlo Rivera

unread,
Nov 16, 2012, 2:09:02 PM11/16/12
to mongod...@googlegroups.com
I am not calling cloneCollection from mongos, I'm calling from mongod from a replica master. I will try with mongos and tellyou what happened

Jean Carlo Rivera

unread,
Nov 16, 2012, 3:02:28 PM11/16/12
to mongod...@googlegroups.com
Uhmmm the problem with  cloneCollection is that you have to run in the server (or replica) where you want to store the collection, so, I should run this command from a primary replica of one no-primary shard, and not over mongos, right?.

What I did was, 
I've created a collection over test database throw mongos. this collection was stored in primary shard, that's ok.
So I connect to another primary replica of other shard which is not primary shard, and I ran this command.

testset3:PRIMARY> db.runCommand({cloneCollection:"test.users",from:"primary.replica.primary.shard:10000",query:{},copyIndexes:false})
{ "ok" : 1 }

It cloned all the users collection in the shar3. Then when I did an explain in mongos  this is what happened

mongos> db.users.find().explain()
{
        "cursor" : "BasicCursor",
        "isMultiKey" : false,
        "n" : 1,
        "nscannedObjects" : 1,
        "nscanned" : 1,
        "nscannedObjectsAllPlans" : 1,
        "nscannedAllPlans" : 1,
        "scanAndOrder" : false,
        "indexOnly" : false,
        "nYields" : 0,
        "nChunkSkips" : 0,
        "millis" : 0,
        "indexBounds" : {

        },
        "server" : "chewbacca:10000",
        "millis" : 0
}

It still search the collection in primary shard, and if I remove this collections, mongos does not know that this collection is in another shard.

Is there a way to tell a mongos that this collections is in another shard which is not the primary shard without change the primary shard??



On Fri, Nov 16, 2012 at 1:58 PM, gregor <gre...@10gen.com> wrote:

gregor

unread,
Nov 16, 2012, 3:19:41 PM11/16/12
to mongod...@googlegroups.com
If it's not a big collection and it's called "smallcol" and is in db "olddb" you could 
mongodump --db olddb --collection smallcol
and then create a db with a different primary shard (use moveprimary to control that)  (say "newdb" and do a 
monogorestore --db newdb --collection smallcol dump/

make sure and do the dump and restore through mongos. then you can do a 

gregor

unread,
Nov 16, 2012, 3:20:31 PM11/16/12
to mongod...@googlegroups.com
actually you can do this on a big collection too it will just take longer  :)

Jean Carlo Rivera

unread,
Nov 16, 2012, 3:33:07 PM11/16/12
to mongod...@googlegroups.com
I really appreciated your help Gregor :), this is a real option, the problem is in olddb we have sharded collections. So I don't want loss this data when I use moveprimary function, we have 3 shards.

If I choice this solution. Mongos could know where is each collections ? 

Suppose I have about 6 collections without sharding. And I want to spread out this collection throw each shards. At the end, mongos might know where is each collection?

fortunately theses collections aren't so big

gregor

unread,
Nov 16, 2012, 4:19:40 PM11/16/12
to mongod...@googlegroups.com
So the point is that you won't move the olddb that contains sharded collections. You will create a new db (newdb) and when it is still empty, choose which shard is primary for newdb and then mongorestore to it. Or you could mongorestore to a another db that has sharded collections but has a different primary shard to olddb. As long as you do it through mongos it will work. Only if you create collections/db direclty on a shard (not via monogos) , then mongos doesn't know about it. Test it with one collection - once you have done the mongorestore, check that the collection is there before you drop the old collection from olddb though! Also keep your monogodump just in case!

Jean Carlo Rivera

unread,
Nov 16, 2012, 4:36:07 PM11/16/12
to mongod...@googlegroups.com
Thanks for your help, I am going to do that in test environment.

Thinking in another solution for balancing my loads, I might shard all my collections. The problem is I have to warranty that each collection has the same field( key sharding) and the findandmodify, which we use frecuentely over them, has at less one field key sharding in its query.

jean carlo

unread,
Nov 19, 2012, 4:49:39 PM11/19/12
to mongod...@googlegroups.com
Hey gregor, thank very much indeed again for your help.

I proved your solutions and works very well in my environment testing. So We are going to do in production environment.

gregor

unread,
Nov 22, 2012, 8:13:07 AM11/22/12
to mongod...@googlegroups.com
Great - let me know if you need any more help :)
Reply all
Reply to author
Forward
0 new messages