[DOCS-14149] writeConcern w:0 with j:true doesn't work Created: 22/Jan/21  Updated: 30/Oct/23  Resolved: 31/Oct/22

Status: Closed
Project: Documentation
Component/s: manual, Server
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Task Priority: Major - P3
Reporter: Darshan Jayarama Assignee: Emet Ozar
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 1 year, 14 weeks, 2 days ago
Epic Link: DOCSP-11701

 Description   

Description

Hi Team,

As per our documentation in writeConcern,

If you specify w: 0 but include j: true, the j: true prevails to request acknowledgment from the standalone mongod or the primary of a replica set.

This is not allowed through any driver connectivity, because of java-driver, PyMongo throws error like below:
//java

 ?minPoolSize=15&maxPoolSize=45&connectTimeoutMS=30000&socketTimeoutMS=60000&wtimeoutMS=300&retryWrites=true&ssl=false&authMechanism=SCRAM-SHA-1&w=0&journal=true 
 
java.lang.IllegalArgumentException: state should be: journal is false when w is 0 

//Pymongo

>>> uri="mongodb://root:rootpass@127.0.0.1:27017/admin?authMechanism=SCRAM-SHA-1&w=0&journal=true"
>>> 
>>> 
>>> conn = mc(uri)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/darshanj/anaconda3/lib/python3.7/site-packages/pymongo/mongo_client.py", line 692, in __init__
    username, password, dbase, opts)
  File "/Users/darshanj/anaconda3/lib/python3.7/site-packages/pymongo/client_options.py", line 164, in __init__
    self.__write_concern = _parse_write_concern(options)
  File "/Users/darshanj/anaconda3/lib/python3.7/site-packages/pymongo/client_options.py", line 61, in _parse_write_concern
    return WriteConcern(concern, wtimeout, j, fsync)
  File "/Users/darshanj/anaconda3/lib/python3.7/site-packages/pymongo/write_concern.py", line 76, in __init__
    raise ConfigurationError("Cannot set w to 0 and j to True")
pymongo.errors.ConfigurationError: Cannot set w to 0 and j to True
>>> pymongo.version
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'pymongo' is not defined
>>>

But the same connection string works as expected from mongo shell:

MacBook-Pro-52:myApp darshanj$ mongo "mongodb://root:rootpass@127.0.0.1:27017/admin?authMechanism=SCRAM-SHA-1&w=0&journal=true"
MongoDB shell version v4.2.8
connecting to: mongodb://127.0.0.1:27017/admin?authMechanism=SCRAM-SHA-1&compressors=disabled&gssapiServiceName=mongodb&journal=true&w=0
Implicit session: session { "id" : UUID("d744cd39-b32d-488c-888d-c4de0b2f0d68") }
MongoDB server version: 4.2.11
Server has startup warnings: 
2020-12-14T11:47:59.151+0530 I  CONTROL  [initandlisten] 
2020-12-14T11:47:59.158+0530 I  CONTROL  [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
MongoDB Enterprise > show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
mydb    0.000GB
test    0.004GB
MongoDB Enterprise > use mydb
switched to db mydb
MongoDB Enterprise > db.mytab.insert({a:"m"})
WriteResult({ "nInserted" : 1 })
MongoDB Enterprise > 

Our documentation should be updated with these points that w:0 with j:true is not allowed if connection is from driver.

Thanks,
Darshan

Scope of changes

Impact to Other Docs

MVP (Work and Date)

Resources (Scope or Design Docs, Invision, etc.)



 Comments   
Comment by Education Bot [ 31/Oct/22 ]

Hello! This ticket has been closed due to inactivity. If you believe this ticket is still important, please reopen it and leave a comment to explain why. Thank you!

Comment by Bernie Hackett [ 29/Jan/21 ]

tl;dr, the driver behavior is correct, the shell behavior is wrong and really confusing.

Raising an error is the correct behavior per the spec:

https://github.com/mongodb/specifications/blob/master/source/read-write-concern/read-write-concern.rst#inconsistent-writeconcern

When you configure any write concern other than w=0 you're asking the server to wait to complete some task before returning a result to the driver and therefore unblocking the application thread waiting for the response. Setting w=0, regardless of any other option, tells the server "don't send a response". So saying, "wait until the write is committed to the journal before responding, but also don't ever send me a response" makes no sense. Journaling has been enabled by default in the server since MongoDB 2.0, you don't have to explicitly tell the server to commit a write to the journal for it to happen.

Comment by Jeffrey Allen [ 26/Jan/21 ]

Thanks very much Chris. I'm moving to blocked until we get more information.

Generated at Thu Feb 08 08:09:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.