Add type safety and/or validation around shard key schema

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Catalog and Routing
    • 🟩 Routing and Topology
    • None
    • None
    • None
    • None
    • None
    • None

      In https://github.com/10gen/mongo/pull/45660, we fixed a bug where we were calling 
      Chunk findIntersectingChunkWithSimpleCollation(const BSONObj& shardKey) on a bson object that did not conform to the schema of the shard key. Therefore, the incorrect shard was silently being returned. 
       
       
      Consider doing validation in this and other functions around using the shard key. The ideal thing would be to do static type checking, but even some runtime checks to show an error instead of silently returning the wrong thing would be preferable.
       
      For example, what `split` does with the same bug:

      +++ b/jstests/noPassthrough/txns_retryable_writes_sessions/refresh_remove_entries_after_update_fails.js
      @@ -314,10 +314,7 @@ function onlyOneShardFailedTest() {
               admin.runCommand({
                   split: "config.system.sessions",
                   middle: {
      -                _id: {
      -                    id: middle,
      -                    uid: BinData(0, ""),
      -                },
      +                id: middle,
                   },
               }),
           ); 

      yields an error:

      /home/ubuntu/mongo/jstests/noPassthrough/txns_retryable_writes_sessions/refresh_remove_entries_after_update_fails.js (253 Failure executing JS file)
              [FIRST Part of Exception]
              uncaught exception: Error: command failed: {
              	"ok" : 0,
              	"errmsg" : "new split key { id: UUID(\"80000000-0000-0000-0000-000000000000\") } is not valid for shard key pattern { _id: 1 }",
              	"$clusterTime" : {
              		"clusterTime" : Timestamp(1767826806, 48),
              		"signature" : {
              			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
              			"keyId" : NumberLong(0)
              		}
              	},
              	"operationTime" : Timestamp(1767826806, 48)
              } with original command request: {
              	"split" : "config.system.sessions",
              	"middle" : {
              		"id" : UUID("80000000-0000-0000-0000-000000000000")

            Assignee:
            Unassigned
            Reporter:
            Indy Prentice
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: