[SERVER-34764] Spurious "readConcern level snapshot is only valid in multi-statement transactions" error Created: 01/May/18  Updated: 29/Oct/23  Resolved: 04/Jun/18

Status: Closed
Project: Core Server
Component/s: Replication
Affects Version/s: 3.7.9
Fix Version/s: 4.0.0-rc5, 4.1.1

Type: Bug Priority: Major - P3
Reporter: Bruce Lucas (Inactive) Assignee: Pavithra Vetriselvan
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.0
Sprint: Repl 2018-05-21, Repl 2018-06-04, Repl 2018-06-18
Participants:

 Description   

The findOne below gets a "readConcern level snapshot is only valid in multi-statement transactions" even though it is in a transaction.

    ses = db.getMongo().startSession()
    dbs = ses.getDatabase("test")
    printjson(dbs.createCollection("c", {writeConcern: {w: "majority"}}))
    printjson(ses.startTransaction())
    printjson(dbs.c.findOne({$where: "sleep(2000)"}))



 Comments   
Comment by Githook User [ 11/Jun/18 ]

Author:

{'username': 'pvselvan', 'name': 'Pavi Vetriselvan', 'email': 'pvselvan@umich.edu'}

Message: SERVER-34764 use inMultiDocumentTransaction instead of autocommit val to avoid spurious readConcern error

(cherry picked from commit 95d855d31b949cadf5047da16b5b8a623c4269f5)
Branch: v4.0
https://github.com/mongodb/mongo/commit/1d378efb7e7aec14404b4d50df524fc2f1a3e881

Comment by Githook User [ 04/Jun/18 ]

Author:

{'username': 'pvselvan', 'name': 'Pavi Vetriselvan', 'email': 'pvselvan@umich.edu'}

Message: SERVER-34764 use inMultiDocumentTransaction instead of autocommit val to avoid spurious readConcern error
Branch: master
https://github.com/mongodb/mongo/commit/95d855d31b949cadf5047da16b5b8a623c4269f5

Comment by Bruce Lucas (Inactive) [ 18/May/18 ]

Standalone repro:

    db=/ssd/db
 
    mongod --version
    mongo --version
 
    killall -9 mongod
    rm -rf $db
    mkdir -p $db/{r0,r1,r2}
    mongod --dbpath $db/r0 --port 27017 --logpath $db/r0.log --replSet r --logappend --fork
    mongod --dbpath $db/r1 --port 27117 --logpath $db/r1.log --replSet r --logappend --fork
    mongod --dbpath $db/r2 --port 27217 --logpath $db/r2.log --replSet r --logappend --fork
    mongo --eval '
        rs.initiate({
            _id: "r",
            members: [
                 {_id: 0, host: "127.0.0.1:27017"},
                 {_id: 1, host: "127.0.0.1:27117"},
                 {_id: 2, host: "127.0.0.1:27217"}
            ]
        })
    '
 
    mongo 'mongodb://127.0.0.1:27017/test?replicaSet=r'  --eval '
        ses = db.getMongo().startSession()
        dbs = ses.getDatabase("test")
        printjson(dbs.createCollection("c", {writeConcern: {w: "majority"}}))
        printjson(ses.startTransaction())
        printjson(dbs.c.findOne({$where: "sleep(2000)"}))
    '

Output:

db version v3.7.9
git version: 681d1e0bf8d45c366848678811bad6f1a471f20c
OpenSSL version: OpenSSL 1.0.2d 9 Jul 2015
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1404
    distarch: x86_64
    target_arch: x86_64
MongoDB shell version v3.7.9
git version: 681d1e0bf8d45c366848678811bad6f1a471f20c
OpenSSL version: OpenSSL 1.0.2d 9 Jul 2015
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1404
    distarch: x86_64
    target_arch: x86_64
 
...
 
2018-05-18T10:47:02.855-0400 E QUERY    [js] Error: error: {
	"ok" : 0,
	"errmsg" : "readConcern level snapshot is only valid in multi-statement transactions",
	"code" : 72,
	"codeName" : "InvalidOptions",
	"operationTime" : Timestamp(1526654822, 1),
	"$clusterTime" : {
		"clusterTime" : Timestamp(1526654822, 1),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	}
} :

Generated at Thu Feb 08 04:37:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.