[CXX-439] [C++11 Driver] Make lifetime of BSONObj more explicit to the user Created: 05/Dec/14 Updated: 24/Apr/15 Resolved: 04/Mar/15 |
|
| Status: | Closed |
| Project: | C++ Driver |
| Component/s: | API |
| Affects Version/s: | None |
| Fix Version/s: | 0.1.0 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Antoine Hom | Assignee: | Andrew Morrow (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Hello, When you call the next() function on a cursor, in the 26compat driver, it gives you back a BSONObj by value, however its lifetime is driven by some internal mechanism inside the cursor object. We have been bitten by this and quickly fixed it by explicitely calling the copy() method if our BSONObj outlives the next call to next(). We do understand that from a performance point of view, and given that it was directly in the server before, that this behavior of no-copy is beneficial. However, in a brand new driver (such as the one you seem to be creating on master branch) it would be very nice to have better visibility on the lifetime on the object just by looking at what return the functions. |
| Comments |
| Comment by Andrew Morrow (Inactive) [ 04/Mar/15 ] |
|
Happy that helped. If you don't mind, I'd like to close this ticket. If you have feedback on the new library we would be very interested to hear it, but the mongodb-dev mailing list is probably a better forum than this jira ticket. Feel free to-reopen if you feel the need. Thanks, |
| Comment by Antoine Hom [ 24/Feb/15 ] |
|
Hello Andrew, Thanks a lot for the notification, I will take time in the next two weeks to take a deeper look at this new BSON library, but from the description you gave I can already see that it is going in the right direction! I will make sure to add feedbacks here after I dig into it. Cheers, |
| Comment by Andrew Morrow (Inactive) [ 19/Feb/15 ] |
|
As you noted, we are developing a new C++ driver, using C++11 features, on the master branch. In the past few weeks the design of the BSON library component of that driver has stabilized. If you are interested, we would certainly appreciate your feedback on the design of the new BSON library, which I believe does provide the functionality you are requesting. In particular, the new BSON library provides different types for an unowned view of a BSON document, called bsoncxx::document::view, and a unique owning handle to a BSON document, called bsoncxx::document::value. Most API methods that return BSON will return a document::view, but you can construct a document::value from a document::view to get an owning copy. There are two additional things to consider:
We are interested in hearing your thoughts. Thanks, |
| Comment by Andrew Morrow (Inactive) [ 05/Dec/14 ] |
|
Hi Antoine - Thank you for the feedback. As you note, we are working on a C++11 driver on the master branch. We are currently iterating on a draft of the core interfaces, which we hope to submit for internal review soon, and then public comment sometime in the next few weeks. So your timing is very good. It is likely that the first version of the new C++11 driver will ship with a very minimal BSON API since we are focusing our efforts on the driver API first, and you can always use libbson (the C BSON library) to construct or read BSON. However, feedback like this is extremely useful as it will help inform the direction of the pure C++11 BSON library that we intend to develop once the core driver interfaces are stabilized. Thanks, |