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

system.js fails to work seamlessly in sharded collections

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Won't Fix
    • None
    • None
    • None
    • None
    • ALL

    Description

      (I couldn't find a duplicate but this was a known issue - please duplicate if you know of one)

      The 'system.js' collection is consulted locally on each shard, but there is no mechanism to ensure that its contents are identical on each shard. In order to use this correctly for a sharded collection, you have to directly connect to a shard and insert the same documents on each shard.

      mongos> db.adminCommand({enableSharding: "test"})
      {
              "ok" : 1,
              "$clusterTime" : {
                      "clusterTime" : Timestamp(1647270677, 3),
                      "signature" : {
                              "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                              "keyId" : NumberLong(0)
                      }
              },
              "operationTime" : Timestamp(1647270677, 2)
      }
      mongos> db.foo.find({$where: "return isTwo(this.x)"})
      mongos> db.adminCommand({shardCollection: "test.foo", key: {_id: "hashed"}})
      {
              "collectionsharded" : "test.foo",
              "ok" : 1,
              "$clusterTime" : {
                      "clusterTime" : Timestamp(1647270747, 44),
                      "signature" : {
                              "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                              "keyId" : NumberLong(0)
                      }
              },
              "operationTime" : Timestamp(1647270747, 40)
      }
      mongos> db.foo.insert([{}, {}])
      BulkWriteResult({
              "writeErrors" : [ ],
              "writeConcernErrors" : [ ],
              "nInserted" : 2,
              "nUpserted" : 0,
              "nMatched" : 0,
              "nModified" : 0,
              "nRemoved" : 0,
              "upserted" : [ ]
      })
      mongos> db.foo.find({$where: "return isTwo(this.x)"})
      Error: error: {
              "ok" : 0,
              "errmsg" : "Encountered non-retryable error during query :: caused by :: Executor error during find command :: caused by :: ReferenceError: isTwo is not defined :\n@:1:15\n",
              "code" : 139,
              "codeName" : "JSInterpreterFailure",
              "$clusterTime" : {
                      "clusterTime" : Timestamp(1647270782, 1),
                      "signature" : {
                              "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                              "keyId" : NumberLong(0)
                      }
              },
              "operationTime" : Timestamp(1647270777, 3)
      }
      mongos> db.system.js.insertOne({_id: "isTwo", value: function(x) { return x === 2 }})
      { "acknowledged" : true, "insertedId" : "isTwo" }
      mongos> db.foo.find({$where: "return isTwo(this.x)"})
      Error: error: {
              "ok" : 0,
              "errmsg" : "Encountered non-retryable error during query :: caused by :: Executor error during find command :: caused by :: ReferenceError: isTwo is not defined :\n@:1:15\n",
              "code" : 139,
              "codeName" : "JSInterpreterFailure",
              "$clusterTime" : {
                      "clusterTime" : Timestamp(1647271179, 1),
                      "signature" : {
                              "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                              "keyId" : NumberLong(0)
                      }
              },
              "operationTime" : Timestamp(1647270818, 2)
      }
      

      Attachments

        Issue Links

          Activity

            People

              garaudy.etienne@mongodb.com Garaudy Etienne
              charlie.swanson@mongodb.com Charlie Swanson
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: