[SERVER-64476] system.js fails to work seamlessly in sharded collections Created: 14/Mar/22  Updated: 16/Nov/23  Resolved: 20/Jul/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Charlie Swanson Assignee: Garaudy Etienne
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-64458 system.js can be sharded via rename Closed
is related to SERVER-925 support for stored js Closed
is related to SERVER-82802 Enable system.js functionality when c... Backlog
is related to SERVER-83269 Deprecate system.js Needs Scheduling
Operating System: ALL
Participants:

 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)
}



 Comments   
Comment by Ratika Gandhi [ 12/May/22 ]

garaudy.etienne@mongodb.com To check with analytics teams to understand the usage of system.js. 

Comment by Charlie Swanson [ 18/Mar/22 ]

kaloian.manassiev I think it's fine to hang out on a backlog since it's been an issue forever. I just knew it was a problem and didn't see any ticket tracking it. Maybe put it in that epic? Or at least "related to"?

Comment by Kaloian Manassiev [ 18/Mar/22 ]

charlie.swanson, this seems like a "global collections" kind of project, not just some sharding bug. What do you expect that we do with this ticket in particular?

Generated at Thu Feb 08 06:00:26 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.