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

Missed index for sharding key

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Gone away
    • Affects Version/s: 2.2.1
    • Fix Version/s: None
    • Component/s: Indexing, Sharding
    • Labels:
    • Environment:
      OS: Ubuntu 12.04
      Mongo: Sharded cluster based on MongoDB 2.2.1 for Linux
    • Operating System:
      ALL
    • Steps To Reproduce:
      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

      Description

      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.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: