Skip to content

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

Merged
merged 6 commits into from
Jan 7, 2021

Conversation

kevinAlbs
Copy link
Collaborator

@kevinAlbs kevinAlbs commented Dec 18, 2020

Summary of changes:

  • Add a bson_parser_t make test parsing code consistent and safer. By default, extra fields are considered an error.
  • Add the entity map for the unified test runner.

Notes:

  • example-insertOne.json exercises the client, database, and collection entity types. Support for bucket and session.defaultTransactionOptions will be added when needed.

@kevinAlbs kevinAlbs changed the title CDRIVER-3422 add entity map CDRIVER-3422 add entity map and BSON parser Dec 18, 2020
@kevinAlbs kevinAlbs force-pushed the unified-part3.CDRIVER-3422 branch from 266e7ab to 274a541 Compare December 18, 2020 16:07
@kevinAlbs kevinAlbs marked this pull request as ready for review December 18, 2020 16:07
LL_FOREACH_SAFE (parser->entries, entry, tmp)
{
/* Destroy alternates. */
LL_FOREACH_SAFE (entry->alternates, alternate, tmp2)
Copy link
Contributor

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)

Copy link
Collaborator Author

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.
Copy link
Contributor

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.

Copy link
Collaborator Author

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);
Copy link
Contributor

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?

Copy link
Collaborator Author

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);
Copy link
Contributor

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

Copy link
Collaborator Author

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) {
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

char* w_string;
int64_t *wtimeoutms;

parser = bson_parser_new ();
Copy link
Contributor

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!

Copy link
Collaborator Author

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!


#include "mongoc/mongoc.h"

mongoc_write_concern_t * bson_to_write_concern (bson_t *bson, bson_error_t* error);
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Contributor

@samantharitter samantharitter left a 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"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, unused include.

Copy link
Contributor

@bazile-clyde bazile-clyde left a 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.

@kevinAlbs kevinAlbs merged commit 8a27205 into mongodb:master Jan 7, 2021
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.

3 participants