Skip to content

CDRIVER-1193, CDRIVER-1198: Expose mongoc_server_description_type_t and improve SDAM logging #322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

jmikola
Copy link
Member

@jmikola jmikola commented Apr 12, 2016

} mongoc_server_description_type_t;
/* this is used for declaring gSDAMTransitionTable and should be defined as the
* number of unique states in mongoc_server_description_type_t */
#define MONGOC_SERVER_DESCRIPTION_TYPES 9
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood to previous code correctly, defining this as the last enum value simply allowed you to keep track of the number of unique states for purposes of declaring the SDAM transition table. This value was never intended to be a type itself, which is its switch case was "invalid". I believe this #define accomplishes that and I left a comment here for good measure.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It tells us how many elements we need to account for in the transition table and was a neat way of keeping track of it.

I think moving it to the .c file it is used in may be the best course of action

Copy link
Member Author

@jmikola jmikola Apr 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mongoc-topology-description.c? That seems a bit odd given that it has a MONGOC_SERVER_DESCRIPTION prefix. If moved there, would you want it at the top of the C file below the #include lines or right above the jump table definition?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems weird to define an enum in one place, the count of it in another place, and then its only used in the 3rd place.

Its unfortunate that this enum must be exposed, because it means we are knowingly breaking the ABI as soon as we add another entry to it, which will break your "enum to string" right off the bat.

I strongly recommend instead that we rather return the stringification of the types.
If you want to represent that as a number somewhere else, then thats fine. Any unknown strings can then be represented as a 0 in the app or something....

@jmikola jmikola force-pushed the cdriver-1193 branch 5 times, most recently from 5a79de9 to cbd3520 Compare April 14, 2016 15:42
@@ -104,6 +94,10 @@ mongoc_server_description_set_set_version (mongoc_server_description_t *descript
void
mongoc_server_description_set_election_id (mongoc_server_description_t *description,
const bson_oid_t *election_id);

const char *
mongoc_server_description_type_string (const mongoc_server_description_t *description);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errrrrrrr. Private functions should start with _, but I guess no other function here does that :/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Existing private functions in this file didn't use an underscore prefix, so I didn't use it. I can change this in the second commit if you decide that CDRIVER-1198 is worthwhile.

jmikola added 2 commits April 15, 2016 15:13
This changes mongoc_server_description_type() to return the enum value instead of a string.
@jmikola
Copy link
Member Author

jmikola commented Apr 20, 2016

Closing this. CDRIVER-1198 was split off into #323 and we decided to maintain a server description type map manually in the PHP driver (see mongodb/mongo-php-driver#291).

@jmikola jmikola closed this Apr 20, 2016
@jmikola jmikola deleted the cdriver-1193 branch April 20, 2016 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants