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

Documents with null value for hashed shard key are not returned via mongos

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical - P2
    • Resolution: Fixed
    • Affects Version/s: 2.4.0-rc1
    • Fix Version/s: 2.4.0-rc2
    • Component/s: Sharding
    • Labels:
      None
    • Environment:
      OS X, 3 shards on 3 replica sets, 1 mongos
    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

      Import the 2009 NYS campaign finance database http://www.elections.ny.gov/NYSBOE/download/ZipDataFiles/2009gen.zip using mongoimport -d qa -c gen2009 -fieldFile headers.h --ignoreBlanks --type csv 2009gen.out (note that headers.h is attached to this ticket)
      mongo
      > use qa
      > db.gen2009.ensureIndex(

      {CITY:"hashed"}

      )
      > db.gen2009.find(

      {CITY:null}

      ) should return 7463 documents
      > sh.enableSharding("qa")
      > sh.shardCollection("qa.gen2009",

      {CITY:"hashed"}

      )
      > db.gen2009.find(

      {CITY:null}

      ) -returns no documents
      > db.gen2009.find(

      {CITY:null}

      ).count() returns 7463
      > db.gen2009.find(

      {STATE:null}

      ).count() returns 7322 documents

      Show
      Import the 2009 NYS campaign finance database http://www.elections.ny.gov/NYSBOE/download/ZipDataFiles/2009gen.zip using mongoimport -d qa -c gen2009 -fieldFile headers.h --ignoreBlanks --type csv 2009gen.out (note that headers.h is attached to this ticket) mongo > use qa > db.gen2009.ensureIndex( {CITY:"hashed"} ) > db.gen2009.find( {CITY:null} ) should return 7463 documents > sh.enableSharding("qa") > sh.shardCollection("qa.gen2009", {CITY:"hashed"} ) > db.gen2009.find( {CITY:null} ) -returns no documents > db.gen2009.find( {CITY:null} ).count() returns 7463 > db.gen2009.find( {STATE:null} ).count() returns 7322 documents

      Description

      I have a collection of 100k+ documents where about 7% are missing the field used for a hashed shard key. While you cannot shard a collection where some documents are missing the shard key field, you can if you used a hashed shard key.

      Prior to sharding, queries on the field (using

      {CITY: null}

      ) succeed, after sharding they appear to fail. The query is directed to the shards and they appear to process it, but mongos does not return any documents. Only happens if the field with null values is the shard key.

      Have reproduced with mongo shell and pymongo, have not narrowed down enough to write JS test case.

      Am not seeing any obvious errors in my mongos or mongod logs.

        Attachments

        1. headers.h
          0.3 kB
        2. missing_key.js
          1.0 kB

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: