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

$match stage following $listSessions not working against mongos

    • Fully Compatible
    • ALL
    • v4.0, v3.6
    • Hide

      The following is a modified jstests/core/list_all_sessions.js test which demonstrates this issue. The following will pass when run against the core suite but will fail against the sharding_jscore_passthrough suite:

       

      // Sessions are asynchronously flushed to disk, so a stepdown immediately after calling
      // startSession may cause this test to fail to find the returned sessionId.
      // @tags: [does_not_support_stepdowns]
      
      
      // Basic tests for the $listSessions {allUsers:true} aggregation stage.
      
      
      (function() {
          'use strict';
          load('jstests/aggregation/extras/utils.js');
      
      
          const admin = db.getSiblingDB("admin");
          const config = db.getSiblingDB("config");
          const pipeline = [{'$listSessions': {allUsers: true}}];
          function listSessions() {
              return config.system.sessions.aggregate(pipeline);
          }
          function listSessionsWithFilter(filter) {
              return config.system.sessions.aggregate([{'$listSessions': {allUsers: true}}, {$match: filter}]);
          }
      
      
          // Get current log level.
          let originalLogLevel = assert.commandWorked(admin.setLogLevel(1)).was.verbosity;
      
      
          try {
              // Start a new session and capture its sessionId.
              const myid = assert.commandWorked(admin.runCommand({startSession: 1})).id.id;
              assert(myid !== undefined);
              assert.commandWorked(admin.runCommand({refreshLogicalSessionCacheNow: 1}));
      
      
              // Ensure that the cache now contains the session and is visible by admin.
              assert.soon(function() {
                  const resultArray = listSessions().toArray();
                  if (resultArray.length < 1) {
                      return false;
                  }
                  const resultArrayMine = resultArray
                                              .map(function(sess) {
                                                  return sess._id.id;
                                              })
                                              .filter(function(id) {
                                                  return 0 == bsonWoCompare({x: id}, {x: myid});
                                              });
                  return resultArrayMine.length == 1;
              }, "Failed to locate session in collection");
      
      
              const sessionList = listSessionsWithFilter({_id: "non_existent"}).toArray();
              assert.eq(0, sessionList.length, tojson(sessionList));
      
      
              // Make sure pipelining other collections fail.
              assertErrorCode(admin.system.collections, pipeline, ErrorCodes.InvalidNamespace);
          } finally {
              admin.setLogLevel(originalLogLevel);
          }
      })(); 
      Show
      The following is a modified jstests/core/list_all_sessions.js test which demonstrates this issue. The following will pass when run against the core suite but will fail against the sharding_jscore_passthrough suite:   // Sessions are asynchronously flushed to disk, so a stepdown immediately after calling // startSession may cause this test to fail to find the returned sessionId. // @tags: [does_not_support_stepdowns] // Basic tests for the $listSessions {allUsers: true } aggregation stage. (function() {     'use strict' ;     load( 'jstests/aggregation/extras/utils.js' );     const admin = db.getSiblingDB( "admin" );     const config = db.getSiblingDB( "config" );     const pipeline = [{ '$listSessions' : {allUsers: true }}];     function listSessions() {         return config.system.sessions.aggregate(pipeline);     }     function listSessionsWithFilter(filter) {         return config.system.sessions.aggregate([{ '$listSessions' : {allUsers: true }}, {$match: filter}]);     }     // Get current log level.     let originalLogLevel = assert .commandWorked(admin.setLogLevel(1)).was.verbosity;     try {         // Start a new session and capture its sessionId.         const myid = assert .commandWorked(admin.runCommand({startSession: 1})).id.id;         assert (myid !== undefined);         assert .commandWorked(admin.runCommand({refreshLogicalSessionCacheNow: 1}));         // Ensure that the cache now contains the session and is visible by admin.         assert .soon(function() {             const resultArray = listSessions().toArray();             if (resultArray.length < 1) {                 return false ;             }             const resultArrayMine = resultArray                                         .map(function(sess) {                                             return sess._id.id;                                         })                                         .filter(function(id) {                                             return 0 == bsonWoCompare({x: id}, {x: myid});                                         });             return resultArrayMine.length == 1;         }, "Failed to locate session in collection" );         const sessionList = listSessionsWithFilter({_id: "non_existent" }).toArray();         assert .eq(0, sessionList.length, tojson(sessionList));         // Make sure pipelining other collections fail.         assertErrorCode(admin.system.collections, pipeline, ErrorCodes.InvalidNamespace);     } finally {         admin.setLogLevel(originalLogLevel);     } })();
    • Query 2018-11-19, Query 2018-12-03

      Observed on 3.6.7. I haven't checked if previous/later versions are also affected.

      It seems that a $match stage following $listSessions is ignored.

       Without $match stage:

      Josefs-MacBook-Pro(mongos-3.6.7)[mongos] config> db.system.sessions.aggregate( [  { $listSessions: { allUsers: true } } ], {cursor:{}} )
      {
        "cursor": {
          "id": NumberLong("0"),
          "ns": "config.system.sessions",
          "firstBatch": [
            {
              "_id": {
                "id": UUID("fade4449-fde7-482f-8885-eadba6cdfdc0")),
                "uid": BinData(0, "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=")
              },
              "lastUse": ISODate("2018-09-19T11:19:14.542Z")
            },
            {
              "_id": {
                "id": UUID("e048de11-40bd-4c9a-9d49-57312a7038a3")),
                "uid": BinData(0, "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=")
              },
              "lastUse": ISODate("2018-09-19T11:24:07.797Z")
            },
            {
              "_id": {
                "id": UUID("282ffe3c-d93a-414b-9a4a-69169689fdee")),
                "uid": BinData(0, "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=")
              },
              "lastUse": ISODate("2018-09-19T11:24:07.797Z")
            }
          ]
        },
        "ok": 1,
        "operationTime": Timestamp(1537356383, 1),
        "$clusterTime": {
          "clusterTime": Timestamp(1537356388, 1),
          "signature": {
            "hash": BinData(0, "AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
            "keyId": NumberLong("0")
          }
        }
      }
      

      With $match stage:

      Josefs-MacBook-Pro(mongos-3.6.7)[mongos] config> db.system.sessions.aggregate( [  { $listSessions: { allUsers: true } }, {"$match":{ "_id.id":UUID("e048de11-40bd-4c9a-9d49-57313") }} ], {cursor:{}} )
      {
        "cursor": {
          "id": NumberLong("0"),
          "ns": "config.system.sessions",
          "firstBatch": [
            {
              "_id": {
                "id": UUID("fade4449-fde7-482f-8885-eadba6cdfdc0")),
                "uid": BinData(0, "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=")
              },
              "lastUse": ISODate("2018-09-19T11:19:14.542Z")
            },
            {
              "_id": {
                "id": UUID("e048de11-40bd-4c9a-9d49-57312a7038a3")),
                "uid": BinData(0, "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=")
              },
              "lastUse": ISODate("2018-09-19T11:24:07.797Z")
            },
            {
              "_id": {
                "id": UUID("282ffe3c-d93a-414b-9a4a-69169689fdee")),
                "uid": BinData(0, "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=")
              },
              "lastUse": ISODate("2018-09-19T11:24:07.797Z")
            }
          ]
        },
        "ok": 1,
        "operationTime": Timestamp(1537356383, 1),
        "$clusterTime": {
          "clusterTime": Timestamp(1537356383, 1),
          "signature": {
            "hash": BinData(0, "AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
            "keyId": NumberLong("0")
          }
        }
      }
      

            Assignee:
            jacob.evans@mongodb.com Jacob Evans
            Reporter:
            josef.ahmad@mongodb.com Josef Ahmad
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: