diff options
author | Martin Neupauer <martin.neupauer@mongodb.com> | 2019-02-26 16:11:27 -0500 |
---|---|---|
committer | Martin Neupauer <martin.neupauer@mongodb.com> | 2019-03-26 10:26:11 -0400 |
commit | b3c4979387d711a46dc5837ac861b9c2e34eb631 (patch) | |
tree | e83b2fdd3176c1bbacb707d404394a66ecba5a42 /src/mongo/db/pipeline/variables.h | |
parent | 1053cf8347e7aeaca24d47039980c765dae75d5b (diff) | |
download | mongo-b3c4979387d711a46dc5837ac861b9c2e34eb631.tar.gz |
SERVER-40209 Implement $$NOW and $$CLUSTER_TIME
Diffstat (limited to 'src/mongo/db/pipeline/variables.h')
-rw-r--r-- | src/mongo/db/pipeline/variables.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/mongo/db/pipeline/variables.h b/src/mongo/db/pipeline/variables.h index c681e9ace14..22a0e88526f 100644 --- a/src/mongo/db/pipeline/variables.h +++ b/src/mongo/db/pipeline/variables.h @@ -29,7 +29,9 @@ #pragma once +#include "mongo/db/operation_context.h" #include "mongo/db/pipeline/document.h" +#include "mongo/db/pipeline/runtime_constants_gen.h" #include "mongo/stdx/memory.h" #include "mongo/stdx/unordered_map.h" #include "mongo/util/string_map.h" @@ -73,6 +75,8 @@ public: // Ids for builtin variables. static constexpr Variables::Id kRootId = Id(-1); static constexpr Variables::Id kRemoveId = Id(-2); + static constexpr Variables::Id kNowId = Id(-3); + static constexpr Variables::Id kClusterTimeId = Id(-4); // Map from builtin var name to reserved id number. static const StringMap<Id> kBuiltinVarNameToId; @@ -119,6 +123,21 @@ public: return &_idGenerator; } + /** + * Serializes runtime constants. This is used to send the constants to shards. + */ + RuntimeConstants getRuntimeConstants() const; + + /** + * Deserialize runtime constants. + */ + void setRuntimeConstants(const RuntimeConstants& constants); + + /** + * Generate values that must be constant during the execution. + */ + void generateRuntimeConstants(OperationContext* opCtx); + private: struct ValueAndState { ValueAndState() = default; @@ -131,8 +150,18 @@ private: void setValue(Id id, const Value& value, bool isConstant); + static auto getBuiltinVariableName(Variables::Id variable) { + for (auto & [ name, id ] : kBuiltinVarNameToId) { + if (variable == id) { + return name; + } + } + return std::string(); + } + IdGenerator _idGenerator; std::vector<ValueAndState> _valueList; + stdx::unordered_map<Id, Value> _runtimeConstants; }; /** |