Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-10539

Missed index for sharding key

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.2.1
    • Component/s: Index Maintenance, Sharding
    • Environment:
      OS: Ubuntu 12.04
      Mongo: Sharded cluster based on MongoDB 2.2.1 for Linux
    • Sharding
    • ALL
    • Hide

      MongoDB sharded cluster.

      Please use Mongo shell to reproduce this issue:

      mongos> use sharding_test;
      mongos> sh.enableSharding("sharding_test");
      
      mongos> db.createCollection('test1');
      mongos> sh.shardCollection("sharding_test.test1", { 'a1234567890': 1, 'b1234567890': 1, 'c1234567890': 1 });
      { "collectionsharded" : "sharding_test.test1", "ok" : 1 }
      mongos> db.test1.insert({ 'a1234567890': 1, 'b1234567890': 1, 'c1234567890': 1 });
      mongos> db.test1.getIndexes();
      [
              {
                      "v" : 1,
                      "key" : {
                              "_id" : 1
                      },
                      "ns" : "sharding_test.test1",
                      "name" : "_id_"
              },
              {
                      "v" : 1,
                      "key" : {
                              "a1234567890" : 1,
                              "b1234567890" : 1,
                              "c1234567890" : 1
                      },
                      "ns" : "sharding_test.test1",
                      "name" : "a1234567890_1_b1234567890_1_c1234567890_1"
              }
      ]
      
      mongos> db.createCollection('test2');
      mongos> sh.shardCollection("sharding_test.test2", { 'a1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890': 1, 'b1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890': 1, 'c1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890': 1 });
      { "collectionsharded" : "sharding_test.test2", "ok" : 1 }
      mongos> db.test2.insert({ "a1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" : 1, "b1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" : 1, "c1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" : 1  });
      mongos> db.test2.getIndexes();
      [
              {
                      "v" : 1,
                      "key" : {
                              "_id" : 1
                      },
                      "ns" : "sharding_test.test2",
                      "name" : "_id_"
              }
      ]
      

      As you can see there is index for sharding key of sharding_test.test1 collection and no index for sharding key of sharding_test.test2.

      Moreover there is no any exception observed.

      Expected result (any one is acceptible):

      • at least throw exception
      • create index for sharding key if there are no suitable indexes which overlap sharding key
      • introduce possibility manually specify index name for sharding key
      Show
      MongoDB sharded cluster. Please use Mongo shell to reproduce this issue: mongos> use sharding_test; mongos> sh.enableSharding( "sharding_test" ); mongos> db.createCollection( 'test1' ); mongos> sh.shardCollection( "sharding_test.test1" , { 'a1234567890' : 1, 'b1234567890' : 1, 'c1234567890' : 1 }); { "collectionsharded" : "sharding_test.test1" , "ok" : 1 } mongos> db.test1.insert({ 'a1234567890' : 1, 'b1234567890' : 1, 'c1234567890' : 1 }); mongos> db.test1.getIndexes(); [ { "v" : 1, "key" : { "_id" : 1 }, "ns" : "sharding_test.test1" , "name" : "_id_" }, { "v" : 1, "key" : { "a1234567890" : 1, "b1234567890" : 1, "c1234567890" : 1 }, "ns" : "sharding_test.test1" , "name" : "a1234567890_1_b1234567890_1_c1234567890_1" } ] mongos> db.createCollection( 'test2' ); mongos> sh.shardCollection( "sharding_test.test2" , { 'a1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890' : 1, 'b1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890' : 1, 'c1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890' : 1 }); { "collectionsharded" : "sharding_test.test2" , "ok" : 1 } mongos> db.test2.insert({ "a1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" : 1, "b1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" : 1, "c1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" : 1 }); mongos> db.test2.getIndexes(); [ { "v" : 1, "key" : { "_id" : 1 }, "ns" : "sharding_test.test2" , "name" : "_id_" } ] As you can see there is index for sharding key of sharding_test.test1 collection and no index for sharding key of sharding_test.test2. Moreover there is no any exception observed. Expected result (any one is acceptible): at least throw exception create index for sharding key if there are no suitable indexes which overlap sharding key introduce possibility manually specify index name for sharding key

      Mongo doesn't create an index for sharding key if index name (constructed by mongo in background) exceeds 128 characters.

      As result such case of sharded collection without index for sharding key will cause performance degradation.

      Additionally reproduced this issue by using Mongo Java Driver 2.9.3 with write concern 2 (REPLICAS_SAFE) - the same situation, no any exception observed.

            Assignee:
            backlog-server-sharding [DO NOT USE] Backlog - Sharding Team
            Reporter:
            nvolynets Nazar Volynets
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: