summaryrefslogtreecommitdiff
path: root/src/mongo/db/update/push_node.h
diff options
context:
space:
mode:
authorJustin Seyster <justin.seyster@mongodb.com>2017-08-18 15:00:08 -0400
committerJustin Seyster <justin.seyster@mongodb.com>2017-08-18 19:13:27 -0400
commitaef10829fc71cb41c54df5838e9e7e74d41d122b (patch)
tree23916345612945a059de6798303f2f597561a1f6 /src/mongo/db/update/push_node.h
parentb3ad5d465cd2fec4983ff84be9da2cc06c1dac97 (diff)
downloadmongo-aef10829fc71cb41c54df5838e9e7e74d41d122b.tar.gz
SERVER-30401 Simplify UpdateLeafNode::apply interface
We need some simplifiction here because UpdateLeafNode::apply is responsible for so many things (a list of which is in modifier_node.h). This change puts most of those things into one function, so that the various modifier implementations can write a few small overrides to customize their functionality, rather than reimplementing all of apply() in each case. This approach extends the PathCreatingNode approach we took previously for all the modifiers. The one exception is RenameNode, which we implement by composing SetNode and UnsetNode.
Diffstat (limited to 'src/mongo/db/update/push_node.h')
-rw-r--r--src/mongo/db/update/push_node.h49
1 files changed, 31 insertions, 18 deletions
diff --git a/src/mongo/db/update/push_node.h b/src/mongo/db/update/push_node.h
index 38784dc7365..66e93d03393 100644
--- a/src/mongo/db/update/push_node.h
+++ b/src/mongo/db/update/push_node.h
@@ -32,13 +32,13 @@
#include <limits>
#include <vector>
-#include "mongo/db/update/path_creating_node.h"
+#include "mongo/db/update/modifier_node.h"
#include "mongo/db/update/push_sorter.h"
#include "mongo/stdx/memory.h"
namespace mongo {
-class PushNode final : public PathCreatingNode {
+class PushNode final : public ModifierNode {
public:
PushNode()
: _slice(std::numeric_limits<long long>::max()),
@@ -57,27 +57,40 @@ public:
}
protected:
- UpdateExistingElementResult updateExistingElement(mutablebson::Element* element,
- std::shared_ptr<FieldRef> elementPath,
- LogBuilder* logBuilder) const final;
+ ModifyResult updateExistingElement(mutablebson::Element* element,
+ std::shared_ptr<FieldRef> elementPath) const final;
void setValueForNewElement(mutablebson::Element* element) const final;
+ void logUpdate(LogBuilder* logBuilder,
+ StringData pathTaken,
+ mutablebson::Element element,
+ ModifyResult modifyResult) const final;
+
+ bool allowCreation() const final {
+ return true;
+ }
+
private:
+ // A helper for performPush().
+ static ModifyResult insertElementsWithPosition(mutablebson::Element* array,
+ long long position,
+ const std::vector<BSONElement>& valuesToPush);
+
/**
- * Used to describe the result of the PerformPush operation. Note that appending to any empty
- * array is always considered kModifyArray. That's because we want $push onto an empty to array
- * to trigger a log entry with a $set on the entire array.
+ * Inserts the elements from '_valuesToPush' in the 'element' array using '_position' to
+ * determine where to insert. This function also applies any '_slice' and or '_sort' that is
+ * specified. The return value of this function will indicate to logUpdate() what kind of oplog
+ * entries should be generated.
+ *
+ * Returns:
+ * - ModifyResult::kNoOp if '_valuesToPush' is empty and no slice or sort gets performed;
+ * - ModifyResult::kArrayAppendUpdate if the 'elements' array is initially non-empty, all
+ * inserted values are appended to the end, and no slice or sort gets performed; or
+ * - ModifyResult::kNormalUpdate if 'elements' is initially an empty array, values get
+ * inserted at the beginning or in the middle of the array, or a slice or sort gets
+ * performed.
*/
- enum class PushResult {
- kNoOp, // The array is left exactly as it was.
- kAppendToEndOfArray, // The only change to the array is items appended to the end.
- kModifyArray // Any other modification of the array.
- };
-
- static PushResult insertElementsWithPosition(mutablebson::Element* array,
- long long position,
- const std::vector<BSONElement> valuesToPush);
- PushResult performPush(mutablebson::Element* element, FieldRef* elementPath) const;
+ ModifyResult performPush(mutablebson::Element* element, FieldRef* elementPath) const;
static const StringData kEachClauseName;
static const StringData kSliceClauseName;