[JAVA-593] NullPointerException at com.mongodb.WriteResult.getN() Created: 02/Jul/12 Updated: 19/Oct/16 Resolved: 30/Jul/12 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | None |
| Affects Version/s: | 2.7.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Kay Agahd | Assignee: | Jeffrey Yemin |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Linux 64 Bit |
||
| Issue Links: |
|
||||||||
| Description |
|
We may get a NPE on calling db.getCollection("offers").update(query, updates, false, true);
We see the error from time to time in our logs and don't know yet how to repoduce it. While tracing down the issue I found another bug: |
| Comments |
| Comment by Hendy Irawan [ 29/Apr/14 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
may be related to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 30/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
OK, thanks for the feedback. Closing this out now. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Kay Agahd [ 30/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The error is gone since we replaced all SATA-HD's by SSD's. Since then, the system looks much more fluid. This confirms the suspicion that the above error is only thrown when mongo is overloaded. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Kay Agahd [ 10/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks Scott. I've created a private JIRA with logs of mongos and the config dump here: For now, we will use WriteConcern.SAFE to see if it fixes the NPE. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Scott Hernandez (Inactive) [ 10/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There is no indication from the output that it is new since it contains no date so I just wanted to make sure the output hadn't changed. If you are going to be using WriteResult.getN() to check the status of the write then you should use WriteConcern.SAFE since you are effectively doing that anyway so there is no advantage to doing the error detection yourself, nor any change in performance. Basically, if you care about the status of the write, and check any properties of the WriteResult, you should always be using WriteConcern.SAFE or higher. Can you upload the logs from the mongos server at covering 16:12:01 and provide a mongodump of the config db? As this is not a java issue it might be best to create a Core Server or Community Private issue to investigate the server part – why there is no error message coming back for the failed write. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Kay Agahd [ 10/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
As I've written and as you can see, the string did not change. We don't use WriteConcern.SAFE to speed-up updates. However, we should read the ok value so the client can repeat its update in case of failure. Is it possible to check the ok value using WriteConcern.NORMAL or do we need WriteConcern.SAFE for this? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Scott Hernandez (Inactive) [ 10/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Now that you have started using the new constructor, without a list of servers since it just a single mongos instance, has that string changed? Is this the new string? Fundamentally you need to a WriteConcern.SAFE and not NORMAL if you are using the code you provided. Your code never checks to make sure that everything was okay with the write, and it wasn't as you can see from the ok value of 0 (false). This still seems like a strange response from the mongos instance but is valid, yet missing some data for the error message. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Kay Agahd [ 10/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Just for completeness:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Kay Agahd [ 10/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Yes, it's exactly the same String that I've posted above at Jul 04 2012 09:13:52 AM UTC | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Scott Hernandez (Inactive) [ 09/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
It is possible; can you provide the toString() value for the WriteResult when this happens? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Kay Agahd [ 09/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Please reopen. We found the same bug in our logs today even when it worked without problems during the whole weekend. As suggested, we are using the single argument constructor. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 06/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Closing for real now. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Kay Agahd [ 06/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Yes it seems to fix the bug - no NPE last night! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 05/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Apologies, shouldn't have closed until you confirmed that. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Kay Agahd [ 05/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I'll keep you up to date if this workaround solved the NPE. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 05/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
OK, closing this out then. Thanks for the report. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Kay Agahd [ 05/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I found a solution to my question above: my connection code sends the command replSetGetStatus to the admin db of the first given server address. If the result contains a field {"info":"mongos"} then it will use the single argument constructor and returns the mongo instance to the client application. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Kay Agahd [ 04/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks, good to know! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 04/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Ah, so you're passing a list of mongos addresses to a constructor that is expecting a list of replica set members. The driver currently does not support load balancing across multiple mongos instances. Can you change your code to use the Mongo constructor that takes a single address and see if the error goes away? I suspect that it will. Note that in the next driver release we will start supporting mongos failover ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Kay Agahd [ 04/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
VoilĂ :
We instantiate Mongo by using this constructor:
Param replicaSetSeeds contains three of our mongos addresses [sx210.ipx:27018, sx176.ipx:27018, sx177.ipx:27018].
COLUMNS is a com.google.common.collect.BiMap to map the field names of our offer object to the field names of our MongoDB. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Scott Hernandez (Inactive) [ 04/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
What does sh.status() show from the shell, and how are you connecting with java (what Mongo constructor are you using with what options)? Can you post the code in the try block as well? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Kay Agahd [ 04/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I could reproduce it and print out the WriteResult instance. The following java code produced the log lines shown below:
logs:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Kay Agahd [ 03/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Yes, it's a sharded collection. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 02/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Can you change your code to log the toString() value of the WriteResult instance in the case where you get this exception? It's definitely unusual not to have an "n" field in the getlasterror response, so I'd like to see the full response if you can get it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Scott Hernandez (Inactive) [ 02/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Is this a sharded collection? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Kay Agahd [ 02/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
We are using WriteConcern.NORMAL and are calling:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 02/Jul/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Any idea what method you called in DBCollection to get that WriteResult? Are you setting WriteConcern, or using the default? |