[CDRIVER-2809] Pass non-const event structs to APM callbacks Created: 29/Aug/18 Updated: 16/Oct/23 |
|
| Status: | Backlog |
| Project: | C Driver |
| Component/s: | libmongoc |
| Affects Version/s: | None |
| Fix Version/s: | 2.0.0 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | A. Jesse Jiryu Davis | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
| Epic Link: | CDRIVER-4742 |
| Description |
|
The event structs passed to SDAM monitoring callbacks are const, e.g.:
Furthermore, the event accessors give const pointers:
However, mongoc_topology_description_has_readable_server / writable server take non-const mongoc_topology_description_t pointers, because they must perform server selection which is a non-const operation on the topology description. Calling mongoc_topology_description_has_readable_server / writable_server on the topology description provided to an SDAM monitoring callback is a documented use case in the SDAM monitoring spec, it shouldn't require the user to cast away const. We can de-const some types without breaking compatibility. Since we provide no public setter functions for any event structs, we could de-const them all without changing semantics significantly, and keep all the callback signatures consistent. Let's consider doing that. |
| Comments |
| Comment by Githook User [ 10/Sep/18 ] | |||||||||||||
|
Author: {'name': 'A. Jesse Jiryu Davis', 'email': 'jesse@mongodb.com', 'username': 'ajdavis'}Message: CDRIVER-2809 topology listeners must cast away const | |||||||||||||
| Comment by A. Jesse Jiryu Davis [ 07/Sep/18 ] | |||||||||||||
|
This can't be done until 2.0, since changing the type of the callback functions is backward-breaking. Let's say I updated this typedef in mongoc-apm.h to make the pointer to the event struct non-const:
If I have code compatible with the previous typedef, like this:
... then the typedef change in the driver results in this warning from Clang:
For now, users will have to cast away const to call mongoc_topology_description_has_readable_server / writable server. I'll note this in the docs. |