0

Using MongoDB 2.6, I've setup four replication sets: a, b, c & d:

>rs.conf()

a:PRIMARY> rs.conf()
{
    "_id" : "name_of_replset",
    "version" : 1,
    "members" : [
        {
            "_id" : 0,
            "host" : "fedora_cje:port_number"
        },
        {
            "_id" : 1,
            "host" : "fedora_cje:port_number"
        },
        {
            "_id" : 2,
            "host" : "fedora_cje:port_number"
        }
    ]
}

Those replication sets have been added to shards

>sh.status()

 shards:
    {  "_id" : "a",  "host" : "a/fedora_cje:27000,fedora_cje:27001,fedora_cje:27002" }
    {  "_id" : "b",  "host" : "b/fedora_cje:27100,fedora_cje:27101,fedora_cje:27102" }
    {  "_id" : "c",  "host" : "c/fedora_cje:27200,fedora_cje:27201,fedora_cje:27202" }
    {  "_id" : "d",  "host" : "d/fedora_cje:27300,fedora_cje:27301,fedora_cje:27302" }

At the bottom of sh.status(), I am seeing this message

{  "_id" : "test",  "partitioned" : false,  "primary" : "d" }
{  "_id" : "test_collection",  "partitioned" : false,  "primary" : "d" }

but test and test_collection don't exist in the test_cluster database.

Inserting records, the fourth replication set and fourth shard are apparently ignored.

test_cluster.test_cluster_collection.stats()

"nchunks" : 3,
"shards" : {
    "a" : {...
    "b" : {...
    "c" : {

Notice also that the number of chunks remains at 3.

I am using the default /etc/mongod.conf file.

This is the insert statement being used:

>use test_cluster
>t=db.test_cluster.test_sharded_collection
>for( var i=0; i < 20000; i++ ){t.insert( { x:i,y:3,z:"test                       test" } )}

Question: Why is the fourth replication set and consequently the fourth shard being ignored during inserts?

1

There are a few confusing pieces here, first you list this piece of sh.status():

{  "_id" : "test",  "partitioned" : false,  "primary" : "d" }
{  "_id" : "test_collection",  "partitioned" : false,  "primary" : "d" }

That means that there is a test database, a test_collection database, not collections. It also indicates that neither of them are sharded - that is what "partitioned" : false means.

You then show some output from test_cluster.test_cluster_collection.stats() but that is not one of the databases from the sh.status command. It is a collection from the test_cluster database, and there is no indication of how that is sharded, though it would be listed in sh.status(). Basically the two pieces of information have nothing to do with each other.

Your for loop will also be inserting into the test_sharded_collection as a sub-collection of test_cluster. In other words, the full namespace you are inserting into is test_cluster.test_cluster.test_sharded_collection, and I suspect that is not sharded which is why you are likely not seeing the chunks increase. What I suspect you intended to do was insert into test_cluster.test_sharded_collection. Try this for your inserts instead:

use test_cluster;
for( var i=0; i < 20000; i++ ){db.test_sharded_collection.insert( { x:i,y:3,z:"test                       test" } )};

The full output of sh.status(), and specifically the section about the test_sharded_collection would help me confirm my suspicions.

  • Hello Adam, I will get back to you shortly on this. I cleared out the cluster directory for the MongoDB chapter 6 homework and need to start over. – Craig Efrein Jun 16 '14 at 5:51
  • Hello Adam, working on 202 now and got a chance to redo the cluster and replications sets. Stopping the balancer before inserts did the trick. – Craig Efrein Jul 19 '14 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.