[JAVA-168] WriteConcern constructor sets getlasterror incorrectly for w<1 Created: 28/Sep/10  Updated: 08/Feb/23  Resolved: 22/Nov/10

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: 2.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Dan Flye Assignee: Eliot Horowitz (Inactive)
Resolution: Cannot Reproduce Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Creating a WriteConcern with a w value of 0 or -1 incorrectly sets getlasterror to 1 instead of 0.

The callGetLastError method correctly returns true only if w > 0.

It appears that this line in the constructor WriteConcern( int w , int wtimeout , boolean fsync):
_command = new BasicDBObject( "getlasterror" , 1 );
should be change to:
_command = new BasicDBObject( "getlasterror" , _w > 0 ? 1 : 0 );



 Comments   
Comment by Eliot Horowitz (Inactive) [ 22/Nov/10 ]

This is working exactly as expected for me.
I see errors in the log - but no error is thrown.

Comment by Dan Flye [ 28/Sep/10 ]

The code in question is a junit test that attempts to exercise the various persistency layers in our app, with Morphia used for pojo/bson conversion.

Chunk of pseudo code after wading through a bunch of classes is below.

My scenario was to fire up the test with mongo running, stop the instance part way through, hope to observe a lack of errors, then restart the mongo instance. With original code, errors thrown each iteration; revised code, no errors thrown.

// setup code: instantiate initial user object and insert in mongo
defaultWriteConcern = new WriteConcern(-1, 0, false);
for (int i = 0; i < 1000000; i++) {
DBCollection coll = db.getCollection("user");
WriteResult wr = null;
db.requestStart();
try

{ user.setPassword(TEST_NEW_PASSWORD + "_" + i); // use Morphia to convert user pojo to DBObject obj wr = coll.update(query, obj, false, false, defaultWriteConcern) }

catch (Exception e)

{ logger.info("defaultWriteConcern: " + defaultWriteConcern); }

finally

{ db.requestDone(): }

}

Comment by Eliot Horowitz (Inactive) [ 28/Sep/10 ]

The value of the "getlasterror" field shouldn't matter at all.
Can you describe your test?

Comment by Dan Flye [ 28/Sep/10 ]

I'm going by what the Java API docs state:

"WriteConcern control the write behavior for with various options, as well as exception raising on error conditions.

w

-1 = don't even report network errors
0 = default, don't call getLastError by default
1 = basic, call getLastError, but don't wait for slaves
2+= wait for slaves"

My testing was done passing -1 for w; I was still seeing backtraces when my test mongo instance was off while attempting to call update... after changing the driver code as suggested above, the driver ignored network errors as I'd expected when w was -1.

Comment by Eliot Horowitz (Inactive) [ 28/Sep/10 ]

w=0 and w=1 should be the same.
what are you seeing that's wrong?

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