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

Changestream with updateLookup uasserts on updates from before collection was sharded

    • Fully Compatible
    • ALL
    • v4.2, v4.0
    • Query 2019-12-02, Query 2019-12-30, Query 2020-01-13, Query 2020-01-27, Query 2020-02-10

      An update operation writes the modified document's documentKey to the o2 field of its oplog entry; this is used by $changeStream to look up the document in the cluster if the updateLookup option is specified. An update on a sharded collection will write the shard key plus _id to the o2 field; on an unsharded collection, just the _id. But this means that if an unsharded collection is subsequently sharded on a key other than _id, the updateLookup for all pre-sharding update events will attempt to target the lookup by _id alone, will be unable to target a single shard, and will therefore always fail with an exception.

      It is possible for this failure to occur in one of two different ways:
      1. An assertion which fails just the change stream, which would look something like this:

        ok: 0
        code: 1,
        codeName: "InternalError",
        msg: "Unable to target lookup query to a single shard: {query.toString()}

      2. An invariant failure on a mongos process which would look something like this in the logs:

      Invariant failure shardResult.size() == 1u src/mongo/s/commands/pipeline_s.cpp

            bernard.gorman@mongodb.com Bernard Gorman
            bernard.gorman@mongodb.com Bernard Gorman
            0 Vote for this issue
            6 Start watching this issue