-
Notifications
You must be signed in to change notification settings - Fork 455
CDRIVER-3422 add entity map and BSON parser #712
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
CDRIVER-3422 add entity map and BSON parser #712
Conversation
266e7ab
to
274a541
Compare
LL_FOREACH_SAFE (parser->entries, entry, tmp) | ||
{ | ||
/* Destroy alternates. */ | ||
LL_FOREACH_SAFE (entry->alternates, alternate, tmp2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can alternates ever have alternates? My gut says that if we ended up in that situation, something's gone wrong. I think we should check for it, though, or handle it another way. The bson_parser_entry_destroy
method could BSON_ASSERT that entry->alternates
is NULL
, or could free its own alternatives instead of this method here freeing the alternatives (which might be a more natural place to free an entry's alternatives anyway)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, alternates cannot have alternates. I added a check in bson_parser_parse
to assert when iterating over the alternates
that they have alternates
set to NULL.
e->key = bson_strdup (key); | ||
|
||
if (alternate) { | ||
/* There should already be an entry. Add this to the list of alternates. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would feel better as a test implementor to label all the alternatives as you go, rather than needing to make the first entry different. Could we change this logic to search for an existing alternative first, then fall back to treating this as a new entry?
This method could be restructured to search for the existing key
first. If 'key
is found and this isn't an alternate, error. If it is an alternate, then add as an alternate. If key
is not found, add in the new entry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good idea. I went with that approach. If adding an alternate and no existing entry exists, a new entry is created.
bson_parser_allow_extra (bson_parser_t *bp, bool val); | ||
|
||
void | ||
bson_parser_destroy (bson_parser_t *bp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we'd ever have a use for a "clear" method that reset the parser to a state where it could be used on new bson?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could see that potentially being useful. I think the "clear" would only need to destroy all output parameters and NULL them.
parser = bson_parser_new (); | ||
bson_parser_utf8 (parser, "id", &entity->id); | ||
bson_parser_utf8 (parser, "client", &client_id); | ||
bson_parser_doc (parser, "sessionOptions", &session_opts_bson); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like sessionOptions
should be an optional document, not a required one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
if (!entity) { | ||
return; | ||
} | ||
if (entity->type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when would we expect to have an entity that didn't have a type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. Entities should always have a type. I changed this to an assertion.
src/libmongoc/tests/unified/util.c
Outdated
char* w_string; | ||
int64_t *wtimeoutms; | ||
|
||
parser = bson_parser_new (); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this bson_parser
is already proving to be so handy!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I hope it is useful!
src/libmongoc/tests/unified/util.h
Outdated
|
||
#include "mongoc/mongoc.h" | ||
|
||
mongoc_write_concern_t * bson_to_write_concern (bson_t *bson, bson_error_t* error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this is a slightly different style from our normal header declarations? Clang format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I did forget to run clang-format. Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little formatting nit, otherwise LGTM!
#include "entity-map.h" | ||
|
||
#include "bson-parser.h" | ||
#include "TestSuite.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, unused include.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few nits but otherwise LGTM.
Summary of changes:
bson_parser_t
make test parsing code consistent and safer. By default, extra fields are considered an error.Notes:
client
,database
, andcollection
entity types. Support forbucket
andsession.defaultTransactionOptions
will be added when needed.