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

mongo shell does not abort transaction on quit

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • 4.0.1, 4.1.2
    • 4.1.7
    • Shell
    • None
    • Repl 2018-12-17, Repl 2019-01-14

    Description

      After executing below code in mongo shell:

      /* First two lines are optional */
      use test;
      db.createCollection('col1');
      session = db.getMongo().startSession();
      session.startTransaction();
      session.getDatabase("test").col1.insert({"a" : "b"});
      

      If the user then quit (SIGINT) the shell, the transaction will still be alive in the server until transactionLifetimeLimitSeconds is reached.

      Snippet MongoDB log showed that there is endSessions sent, but transaction within the session is not aborted.

      2018-08-28T17:09:17.572+1000 I COMMAND  [conn4] command config.transactions appName: "MongoDB Shell" command: find { find: "transactions", filter: { _id: { id: UUID("7ba23bf5-a74c-4c71-bfa8-dabb6b3d6f46"), uid: BinData(0, E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855) } }, ntoreturn: 1, singleBatch: true, $db: "config" } planSummary: IDHACK keysExamined:0 docsExamined:0 cursorExhausted:1 numYields:0 nreturned:0 reslen:233 locks:{ Global: { acquireCount: { r: 1 } }, Database: { acquireCount: { r: 1 } }, Collection: { acquireCount: { r: 1 } } } protocol:op_msg 0ms
      2018-08-28T17:09:17.572+1000 I COMMAND  [conn4] command test.col1 appName: "MongoDB Shell" command: insert { insert: "col1", ordered: true, lsid: { id: UUID("7ba23bf5-a74c-4c71-bfa8-dabb6b3d6f46") }, $clusterTime: { clusterTime: Timestamp(1535440152, 1), signature: { hash: BinData(0, 0000000000000000000000000000000000000000), keyId: 0 } }, txnNumber: 0, autocommit: false, stmtId: 0, startTransaction: true, $db: "test" } ninserted:1 keysInserted:1 numYields:0 reslen:230 locks:{} protocol:op_msg 0ms
      2018-08-28T17:09:17.574+1000 I COMMAND  [conn4] command admin.$cmd appName: "MongoDB Shell" command: replSetGetStatus { replSetGetStatus: 1.0, forShell: 1.0, $clusterTime: { clusterTime: Timestamp(1535440152, 1), signature: { hash: BinData(0, 0000000000000000000000000000000000000000), keyId: 0 } }, $db: "admin" } numYields:0 reslen:893 locks:{} protocol:op_msg 0ms
      2018-08-28T17:09:20.638+1000 I COMMAND  [conn4] command admin.$cmd appName: "MongoDB Shell" command: endSessions { endSessions: [ { id: UUID("71e24f05-1ec6-41f8-a333-3da8aac6000e") } ], $db: "admin" } numYields:0 reslen:163 locks:{} protocol:op_msg 0ms
      2018-08-28T17:09:20.638+1000 I COMMAND  [conn4] command admin.$cmd appName: "MongoDB Shell" command: endSessions { endSessions: [ { id: UUID("7ba23bf5-a74c-4c71-bfa8-dabb6b3d6f46") } ], $db: "admin" } numYields:0 reslen:163 locks:{} protocol:op_msg 0ms
      2018-08-28T17:09:20.638+1000 I NETWORK  [conn4] end connection 127.0.0.1:58100 (1 connection now open)
      

      Until the transaction life time is reached:

      2018-08-28T17:10:39.435+1000 D STORAGE  [conn2] create collection test.col1 {}
      2018-08-28T17:10:39.435+1000 D STORAGE  [startPeriodicThreadToAbortExpiredTransactions] Slow WT transaction. Lifetime of SnapshotId 673 was 81863ms
      2018-08-28T17:10:39.435+1000 D -        [conn2] User Assertion: NamespaceExists: a collection 'test.col1' already exists src/mongo/db/commands/dbcommands.cpp 426
      2018-08-28T17:10:39.436+1000 D COMMAND  [conn2] assertion while executing command 'create' on database 'test' with arguments '{ create: "col1", lsid: { id: UUID("cc125e16-60d8-4c39-bd56-362f738aaa20") }, $clusterTime: { clusterTime: Timestamp(1535440132, 1), signature: { hash: BinData(0, 0000000000000000000000000000000000000000), keyId: 0 } }, $db: "test" }': NamespaceExists: a collection 'test.col1' already exists
      2018-08-28T17:10:39.436+1000 I COMMAND  [conn2] command test.col1 appName: "MongoDB Shell" command: create { create: "col1", lsid: { id: UUID("cc125e16-60d8-4c39-bd56-362f738aaa20") }, $clusterTime: { clusterTime: Timestamp(1535440132, 1), signature: { hash: BinData(0, 0000000000000000000000000000000000000000), keyId: 0 } }, $db: "test" } numYields:0 ok:0 errMsg:"a collection 'test.col1' already exists" errName:NamespaceExists errCode:48 reslen:255 locks:{ Global: { acquireCount: { r: 1, w: 1 } }, Database: { acquireCount: { W: 1 }, acquireWaitCount: { W: 1 }, timeAcquiringMicros: { W: 74156010 } } } protocol:op_msg 74157ms
      2018-08-28T17:10:39.438+1000 I COMMAND  [conn2] command admin.$cmd appName: "MongoDB Shell" command: replSetGetStatus { replSetGetStatus: 1.0, forShell: 1.0, $clusterTime: { clusterTime: Timestamp(1535440232, 1), signature: { hash: BinData(0, 0000000000000000000000000000000000000000), keyId: 0 } }, $db: "admin" } numYields:0 reslen:893 locks:{} protocol:op_msg 0ms
      

      Attachments

        Activity

          People

            jesse@mongodb.com A. Jesse Jiryu Davis
            wan.bachtiar@mongodb.com Wan Bachtiar
            Votes:
            1 Vote for this issue
            Watchers:
            14 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: