[JAVA-2146] Don't get exceptions from driver when Write concern not met. Created: 08/Mar/16 Updated: 11/Sep/19 Resolved: 08/Mar/16 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | None |
| Affects Version/s: | 3.2.0 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | John Page | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Writing to a 3.2 Database - either a replica set or a sharded cluster. Where the write concern cannot be satisfied - for example 1 + Arbiter all that is remaining in 2 + A cluster and a write concern of 2 I get no exceptions thrown when calling MongoCollection.bulkWrite(). If I have a hard error - such as no primary I get an exception - but anywhere I would expect that the BulkWriteException.WriteConcernError is populated - no exception is thrown. Also - when submitting a batch and where I have continueOnError enabled, and unordered operations - I would expect an exception to be thrown but to be able to see the failure reason for each operations - similar to this [ https://docs.mongodb.org/manual/reference/method/BulkWriteResult/ ] , how do I get similar functionality through he Java driver? |
| Comments |
| Comment by John Page [ 08/Mar/16 ] | ||||||||||||||||||||||||||||
|
Thanks Jeff | ||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 08/Mar/16 ] | ||||||||||||||||||||||||||||
|
About your second question: here's some sample code which shows how to see all the write errors in an unordered bulkWrite:
It prints:
| ||||||||||||||||||||||||||||
| Comment by John Page [ 08/Mar/16 ] | ||||||||||||||||||||||||||||
|
Mistake in not setting wtimeout | ||||||||||||||||||||||||||||
| Comment by John Page [ 08/Mar/16 ] | ||||||||||||||||||||||||||||
|
Sorry - This one is my fault - I didn't realise that you HAD to specify a wtimeout - I thought it had a default value. I'll close this works as designed. | ||||||||||||||||||||||||||||
| Comment by John Page [ 08/Mar/16 ] | ||||||||||||||||||||||||||||
|
If I specify the write concern as above I do get an Exception thrown. If however I specify it via the URI on connection (which is what I am doing) then the write concern is obeyed and Adding .withWriteConcern(WriteConcern.W2.withWTimeout(1, TimeUnit.SECONDS)) works but it's important that URI is the thing handling write concerns here. | ||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 08/Mar/16 ] | ||||||||||||||||||||||||||||
|
Also note that as per the Javadoc the bulkWrite method throws a MongoBulkWriteException in this situation, not a BulkWriteException. BulkWriteException couldn't be re-used in the new CRUD API because of its dependence on the DBObject class. | ||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 08/Mar/16 ] | ||||||||||||||||||||||||||||
|
I can't reproduce this. With this code:
I get this exception:
when I bring down one of the two data-bearing nodes in my replica set. Do you see anything different about your test case from the one I'm using? |