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

killCursors doesn't kill idleCursor on sharded clusters

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Works as Designed
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • ALL
    • QE 2021-09-20

    Description

      Attempting to use killCursors to kill an idleCursor will output that the cursorId isn't found despite being present in currentOp on a sharded replicaset.

      When this behavior occurs on an unsharded replica set, the idleCursor is correctly identified and deleted.

      Looking closely at the currentOp on an unsharded and sharded cluster, the difference is the sharded cluster idleCursor includes a cursor.originatingCommand.$audit field, whereas it's absent in the idleCursor operation on an unsharded cluster.

      Observed output:

      {
      	"cursorsKilled" : [ ],
      	"cursorsNotFound" : [
      		NumberLong("2835470530442257976")
      	],
      	"cursorsAlive" : [ ],
      	"cursorsUnknown" : [ ],
      	"ok" : 1,
      	"operationTime" : Timestamp(1631130082, 1),
      	"$clusterTime" : {
      		"clusterTime" : Timestamp(1631130082, 1),
      		"signature" : {
      			"hash" : BinData(0,"PTeTErvUUsQjtD5TL7HxEWBfkLE="),
      			"keyId" : NumberLong("7005639500034473987")
      		}
      	}
      }
      

      currentOp on sharded cluster:

      {
      		"shard" : "shard01",
      		"type" : "idleCursor",
      		"host" : "Edwins-MBP.cable.rcn.com:27018",
      		"ns" : "test.test_col",
      		"lsid" : {
      			"id" : UUID("e0d86751-ae27-4711-90d4-58182f15dd38"),
      			"uid" : BinData(0,"eOZyqfHfiVpfviPDWgAERmzNFnUp8UBdlWKN50Fv9fo=")
      		},
      		"planSummary" : "COLLSCAN",
      		"cursor" : {
      			"cursorId" : NumberLong("2835470530442257976"),
      			"createdDate" : ISODate("2021-09-08T19:41:03.243Z"),
      			"lastAccessDate" : ISODate("2021-09-08T19:41:03.243Z"),
      			"nDocsReturned" : NumberLong(101),
      			"nBatchesReturned" : NumberLong(1),
      			"noCursorTimeout" : false,
      			"tailable" : false,
      			"awaitData" : false,
      			"originatingCommand" : {
      				"find" : "test_col",
      				"readConcern" : {
      					"provenance" : "implicitDefault"
      				},
      				"runtimeConstants" : {
      					"localNow" : ISODate("2021-09-08T19:41:03.243Z"),
      					"clusterTime" : Timestamp(1631130063, 11259)
      				},
      				"_use44SortKeys" : true,
      				"shardVersion" : [
      					Timestamp(0, 0),
      					ObjectId("000000000000000000000000")
      				],
      				"databaseVersion" : {
      					"uuid" : UUID("9ae75994-3008-42f8-8771-c1ed457a8c1c"),
      					"lastMod" : 1
      				},
      				"clientOperationKey" : UUID("ec06493f-4d94-4973-850c-04bba4a63d0f"),
      				"lsid" : {
      					"id" : UUID("e0d86751-ae27-4711-90d4-58182f15dd38"),
      					"uid" : BinData(0,"eOZyqfHfiVpfviPDWgAERmzNFnUp8UBdlWKN50Fv9fo=")
      				},
      				"$clusterTime" : {
      					"clusterTime" : Timestamp(1631130063, 11259),
      					"signature" : {
      						"hash" : BinData(0,"xn16OBRLaxcrTFxyj3rOltF6EKw="),
      						"keyId" : NumberLong("7005639500034473987")
      					}
      				},
      				"$audit" : {
      					"$impersonatedUsers" : [
      						{
      							"user" : "user",
      							"db" : "admin"
      						}
      					],
      					"$impersonatedRoles" : [
      						{
      							"role" : "dbAdminAnyDatabase",
      							"db" : "admin"
      						},
      						{
      							"role" : "userAdminAnyDatabase",
      							"db" : "admin"
      						},
      						{
      							"role" : "readWriteAnyDatabase",
      							"db" : "admin"
      						},
      						{
      							"role" : "clusterAdmin",
      							"db" : "admin"
      						}
      					]
      				},
      				"$client" : {
      					"application" : {
      						"name" : "MongoDB Shell"
      					},
      					"driver" : {
      						"name" : "MongoDB Internal Client",
      						"version" : "4.4.8"
      					},
      					"os" : {
      						"type" : "Darwin",
      						"name" : "Mac OS X",
      						"architecture" : "x86_64",
      						"version" : "20.5.0"
      					},
      					"mongos" : {
      						"host" : "Edwins-MBP.cable.rcn.com:27017",
      						"client" : "127.0.0.1:50963",
      						"version" : "4.4.8"
      					}
      				},
      				"$configServerState" : {
      					"opTime" : {
      						"ts" : Timestamp(1631130062, 1),
      						"t" : NumberLong(2)
      					}
      				},
      				"$db" : "test"
      			}
      		}
      	}
      

      currentOp on a different, unsharded cluster. This operation can be killed by the killCursors command.

      {
      		"type" : "idleCursor",
      		"host" : "Edwins-MBP.cable.rcn.com:27017",
      		"ns" : "test.test_col",
      		"lsid" : {
      			"id" : UUID("3e710e06-4f2f-478a-9729-3593997d0e06"),
      			"uid" : BinData(0,"eOZyqfHfiVpfviPDWgAERmzNFnUp8UBdlWKN50Fv9fo=")
      		},
      		"planSummary" : "COLLSCAN",
      		"cursor" : {
      			"cursorId" : NumberLong("6473309381379159077"),
      			"createdDate" : ISODate("2021-09-08T18:16:31.965Z"),
      			"lastAccessDate" : ISODate("2021-09-08T18:16:31.965Z"),
      			"nDocsReturned" : NumberLong(101),
      			"nBatchesReturned" : NumberLong(1),
      			"noCursorTimeout" : false,
      			"tailable" : false,
      			"awaitData" : false,
      			"originatingCommand" : {
      				"find" : "test_col",
      				"filter" : {
       
      				},
      				"lsid" : {
      					"id" : UUID("3e710e06-4f2f-478a-9729-3593997d0e06")
      				},
      				"$clusterTime" : {
      					"clusterTime" : Timestamp(1631122562, 1),
      					"signature" : {
      						"hash" : BinData(0,"v0W3OnNwG/AVseVNtpul6k4g+nQ="),
      						"keyId" : NumberLong("7005607966384586753")
      					}
      				},
      				"$db" : "test"
      			}
      		}
      	}
      

      Repro:

      mlaunch init --auth --sharded 1 --replicaset --nodes 2
      

      // insert some docs
      bulk = db.getSiblingDB("test").getCollection("test_col").initializeUnorderedBulkOp();
      for (let i = 0; i < 20000; i++) {
        bulk.insert({ a: i, x: "x".repeat(1024) });
      }
      bulk.execute();
       
      // create idleCursor
      db.getSiblingDB("test").getCollection("test_col").find();
       
      // get idleCursor cursorId
      db.getSiblingDB("admin").aggregate([
        { $currentOp: { allUsers: true, idleCursors: true } },
        { $match: { type: "idleCursor" } },
      ]).toArray().map((o) => o.cursor.cursorId);
       
      // kill cursor 
      db.getSiblingDB("test").runCommand({ killCursors: "test_col", cursors: [Long("<idleCursorId>")] });
      

      Attachments

        Activity

          People

            bernard.gorman@mongodb.com Bernard Gorman
            edwin.zhou@mongodb.com Edwin Zhou
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: