[CXX-898] DBClientBase::insert() error handling Created: 19/Apr/16  Updated: 11/Sep/19  Resolved: 26/Apr/16

Status: Closed
Project: C++ Driver
Component/s: API
Affects Version/s: legacy-1.0.6
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Judy Han [X] Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux xxx 2.6.32-573.18.1.el6.x86_64 #1 SMP Wed Jan 6 11:20:49 EST 2016 x86_64 x86_64 x86_64 GNU/Linux



 Description   

I am calling DBClientBase::insert(), I am trying to add error handling code.
From the implementation:

2043 // prefer using the bulk API for this
2044 void DBClientBase::insert(const string& ns,
2045                           const vector<BSONObj>& v,
2046                           int flags,
2047                           const WriteConcern* wc) {
2048     ScopedWriteOperations inserts;
2049 
2050     vector<BSONObj>::const_iterator bsonObjIter;
2051     for (bsonObjIter = v.begin(); bsonObjIter != v.end(); ++bsonObjIter) {
2052         uassert(0,
2053                 "document to be inserted exceeds maxBsonObjectSize",
2054                 (*bsonObjIter).objsize() <= getMaxBsonObjectSize());
2055         inserts.enqueue(new InsertWriteOperation(*bsonObjIter));
2056     }
2057 
2058     bool ordered = !(flags & InsertOption_ContinueOnError);
2059 
2060     WriteResult writeResult;
2061     _write(ns, inserts.ops, ordered, wc, &writeResult);
2062 }

In line 2060 - 2061, it looks the errorCode is written in writeResult? If so, it is not passed back to the caller.
How would the caller do the error handling in this case? Does that mean I have to modify this API?
Please let me know if I miss something.
Thanks!
Judy



 Comments   
Comment by Judy Han [X] [ 26/Apr/16 ]

Thanks a lot for the clarification!

Comment by Andrew Morrow (Inactive) [ 26/Apr/16 ]

Hi -

All that ticket is saying is that the C++11 driver inherits its SSL configuration from the C driver: If the C driver is configured with SSL, then so is the C++11 driver. If the C driver is not configured with SSL, then neither is the C++11 driver. For testing purposes, it would be useful for us to be able to build the C++11 driver without SSL, to ensure that it functions correctly when SSL support is not available, without needing to build the C driver twice to do that.

The C++11 driver definitely supports SSL, as long as the C driver that it is built above does.

Comment by Judy Han [X] [ 26/Apr/16 ]

Hi Andrew,
I will use the bulk API for now.
Thank you very much for providing the detailed information regarding the new c++ driver and schedule. I will see if we can switch to the new c++ driver now.

sorry I have a follow up question on the new c++ driver. It seems having a known issue:
CXX-778 - C++ driver SSL cannot be configured independently of C driver

Could you elaborate a bit on that? We do need SSL support.

Thanks!
Judy

Comment by Andrew Morrow (Inactive) [ 26/Apr/16 ]

I can't say for sure that there is zero over head to doing it, but I would be surprised if it is noticeable. And, it will let you get the WriteResult, which is what you really want here, I think. For the record, the C++11 driver does flow all operations, even apparently scalar ones, through its bulk API.

As to the C++11 driver: Yes, it is production ready. The upcoming 3.0.2 should have some important bug fixes in it including some small API tweaks. We are aiming to release a 3.1.0 this summer with several important build fixes and an improved error handling API. Finally, we should be releasing a 3.2.0 in the Fall to pair up with the release of MongoDB 3.4. That release is anticipated to be API and ABI stable.

Please note that after we release C++11 3.2.0 and MongoDB 3.4, we will probably begin planning to EOL the 26compat and legacy drivers. We may issue a legacy-1.2.x release stream if there are changes required for us to support MongoDB 3.4, but we are unlikely to offer support for new MongoDB 3.4 features in any version of the legacy driver.

Comment by Judy Han [X] [ 26/Apr/16 ]

Hi Andrew,

Thanks for the info. Yes, I am using bulk API when I am doing bulk insert/upsert. However, we also need to do some single inserts for sparsely changed objects. Are you suggesting that I should always use bulk API even for single inserts? It seems a bit of overkill for that. Is there any repercussions for doing that, performance wise?

And yes, the new C++11 drive looks much more powerful. Is it production ready? I would like to give it a try someday but not at the moment, we have decided to stay on legacy driver.

Thanks,
Judy

Comment by Andrew Morrow (Inactive) [ 24/Apr/16 ]

Hi Judy.Han -

Yes, I think you are correct that you cannot obtain that WriteResult object using this API. I believe this has always been so: I went back and looked at how this function was defined in 26compat, where the implementation was quite different, and it too had no way to communicate an error.

However, there is good news, and it is contained in the comment above.

Instead of using this API, you should use the bulk API to do multi-document inserts. Please see src/mongo/client/bulk_operation_builder.h. That API will give you back the WriteResult information which you can use to handle errors.

Please let me know if you have any other questions.

PS: Have you considered upgrading to the new C++11 driver? It offers a much improved interface.

Generated at Wed Feb 07 22:00:43 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.