diff options
author | Mihai Andrei <mihai.andrei@10gen.com> | 2021-09-13 23:20:19 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-09-13 23:55:08 +0000 |
commit | 15c51de0d4700d490c71ca70f961c3c44c1d4a1c (patch) | |
tree | 6e415ce171ccc92eaa7bc1f250464e39d2450e67 /src/mongo/db/pipeline/expression.h | |
parent | 926b0287318744f7ef751aa10e64ec310d36695e (diff) | |
download | mongo-15c51de0d4700d490c71ca70f961c3c44c1d4a1c.tar.gz |
SERVER-58379 Extend REGISTER macros to support API version, FCV, and conditional checks for accumulators, expressions, and window functions
Diffstat (limited to 'src/mongo/db/pipeline/expression.h')
-rw-r--r-- | src/mongo/db/pipeline/expression.h | 71 |
1 files changed, 42 insertions, 29 deletions
diff --git a/src/mongo/db/pipeline/expression.h b/src/mongo/db/pipeline/expression.h index a0a2d08bdee..cb68e7cef5b 100644 --- a/src/mongo/db/pipeline/expression.h +++ b/src/mongo/db/pipeline/expression.h @@ -73,16 +73,37 @@ class DocumentSource; * An expression registered this way can be used in any featureCompatibilityVersion and will be * considered part of the stable API. */ -#define REGISTER_STABLE_EXPRESSION(key, parser) \ - MONGO_INITIALIZER_GENERAL(addToExpressionParserMap_##key, \ - ("BeginExpressionRegistration"), \ - ("EndExpressionRegistration")) \ - (InitializerContext*) { \ - Expression::registerExpression("$" #key, \ - (parser), \ - AllowedWithApiStrict::kAlways, \ - AllowedWithClientType::kAny, \ - boost::none); \ +#define REGISTER_STABLE_EXPRESSION(key, parser) \ + REGISTER_EXPRESSION_CONDITIONALLY(key, \ + parser, \ + AllowedWithApiStrict::kAlways, \ + AllowedWithClientType::kAny, \ + boost::none, \ + true); + +/** + * Like REGISTER_EXPRESSION_WITH_MIN_VERSION, except you can also specify a condition, + * evaluated during startup, that decides whether to register the parser. + * + * For example, you could check a feature flag, and register the parser only when it's enabled. + * + * Note that the condition is evaluated only once, during a MONGO_INITIALIZER. Don't specify + * a condition that can change at runtime, such as FCV. (Feature flags are ok, because they + * cannot be toggled at runtime.) + * + * This is the most general REGISTER_EXPRESSION* macro, which all others should delegate to. + */ +#define REGISTER_EXPRESSION_CONDITIONALLY( \ + key, parser, allowedWithApiStrict, allowedClientType, minVersion, ...) \ + MONGO_INITIALIZER_GENERAL(addToExpressionParserMap_##key, \ + ("BeginExpressionRegistration"), \ + ("EndExpressionRegistration")) \ + (InitializerContext*) { \ + if (!(__VA_ARGS__)) { \ + return; \ + } \ + Expression::registerExpression( \ + "$" #key, (parser), (allowedWithApiStrict), (allowedClientType), (minVersion)); \ } /** @@ -106,30 +127,22 @@ class DocumentSource; * parser and enforce the 'sometimes' behavior during that invocation. No extra validation will be * done here. */ -#define REGISTER_EXPRESSION_WITH_MIN_VERSION( \ - key, parser, allowedWithApiStrict, allowedClientType, minVersion) \ - MONGO_INITIALIZER_GENERAL(addToExpressionParserMap_##key, \ - ("BeginExpressionRegistration"), \ - ("EndExpressionRegistration")) \ - (InitializerContext*) { \ - Expression::registerExpression( \ - "$" #key, (parser), (allowedWithApiStrict), (allowedClientType), (minVersion)); \ - } +#define REGISTER_EXPRESSION_WITH_MIN_VERSION( \ + key, parser, allowedWithApiStrict, allowedClientType, minVersion) \ + REGISTER_EXPRESSION_CONDITIONALLY( \ + key, parser, allowedWithApiStrict, allowedClientType, minVersion, true) /** * Registers a Parser only if test commands are enabled. Use this if your expression is only used * for testing purposes. */ -#define REGISTER_TEST_EXPRESSION(key, allowedWithApiStrict, allowedClientType, parser) \ - MONGO_INITIALIZER_GENERAL(addToExpressionParserMap_##key, \ - ("BeginExpressionRegistration"), \ - ("EndExpressionRegistration")) \ - (InitializerContext*) { \ - if (getTestCommandsEnabled()) { \ - Expression::registerExpression( \ - "$" #key, (parser), (allowedWithApiStrict), (allowedClientType), boost::none); \ - } \ - } +#define REGISTER_TEST_EXPRESSION(key, allowedWithApiStrict, allowedClientType, parser) \ + REGISTER_EXPRESSION_CONDITIONALLY(key, \ + parser, \ + allowedWithApiStrict, \ + allowedClientType, \ + boost::none, \ + getTestCommandsEnabled()); class Expression : public RefCountable { public: |