summaryrefslogtreecommitdiff
path: root/src/mongo/db/ops/write_ops.h
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-06-07 13:56:30 +0300
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-07-06 18:05:57 -0400
commite09a21c0d849878792e647d2326d6fde865ac458 (patch)
treeb3cd6c002db115e73fa8151609467a4ec7ce3d0d /src/mongo/db/ops/write_ops.h
parent1447d3db59804752e6c2882a6a8a4a14d7ae71ad (diff)
downloadmongo-e09a21c0d849878792e647d2326d6fde865ac458.tar.gz
SERVER-28752 Use IDL for write commands parsing
Diffstat (limited to 'src/mongo/db/ops/write_ops.h')
-rw-r--r--src/mongo/db/ops/write_ops.h128
1 files changed, 55 insertions, 73 deletions
diff --git a/src/mongo/db/ops/write_ops.h b/src/mongo/db/ops/write_ops.h
index 3ea1c91a4a5..556f8c6a09a 100644
--- a/src/mongo/db/ops/write_ops.h
+++ b/src/mongo/db/ops/write_ops.h
@@ -28,89 +28,71 @@
#pragma once
-#include <boost/optional.hpp>
-#include <vector>
-
-#include "mongo/db/jsobj.h"
-#include "mongo/db/namespace_string.h"
+#include "mongo/db/ops/write_ops_gen.h"
+#include "mongo/util/net/message.h"
+#include "mongo/util/net/op_msg.h"
namespace mongo {
-/**
- * The base structure for all fields that are common for all write operations.
- *
- * Unlike ParsedUpdate and UpdateRequest (and the Delete counterparts), types deriving from this are
- * intended to represent entire operations that may consist of multiple sub-operations.
- */
-struct ParsedWriteOp {
- NamespaceString ns;
- bool bypassDocumentValidation = false;
- bool continueOnError = false;
+class InsertOp : public write_ops::Insert {
+public:
+ using Insert::Insert;
+
+ static InsertOp parse(const OpMsgRequest& request);
+ static InsertOp parseLegacy(const Message& msg);
+
+private:
+ InsertOp(Insert&& other) : Insert(other) {}
};
-/**
- * A parsed insert insert operation.
- */
-struct InsertOp : ParsedWriteOp {
- std::vector<BSONObj> documents;
+class UpdateOp : public write_ops::Update {
+public:
+ using Update::Update;
+
+ static UpdateOp parse(const OpMsgRequest& request);
+ static UpdateOp parseLegacy(const Message& msg);
+
+private:
+ UpdateOp(Update&& other) : Update(other) {}
};
-/**
- * A parsed update operation.
- */
-struct UpdateOp : ParsedWriteOp {
- struct SingleUpdate {
- BSONObj toBSON() const {
- BSONObjBuilder builder;
- builder << "q" << query;
- builder << "u" << update;
- builder << "multi" << multi;
- builder << "upsert" << upsert;
- if (!collation.isEmpty()) {
- builder << "collation" << collation;
- }
- if (!arrayFilters.empty()) {
- BSONArrayBuilder arrayBuilder(builder.subarrayStart("arrayFilters"));
- for (auto arrayFilter : arrayFilters) {
- arrayBuilder.append(arrayFilter);
- }
- arrayBuilder.doneFast();
- }
- return builder.obj();
- }
-
- BSONObj query;
- BSONObj update;
- BSONObj collation;
- std::vector<BSONObj> arrayFilters;
- bool multi = false;
- bool upsert = false;
- };
-
- std::vector<SingleUpdate> updates;
+class DeleteOp : public write_ops::Delete {
+public:
+ using Delete::Delete;
+
+ static DeleteOp parse(const OpMsgRequest& request);
+ static DeleteOp parseLegacy(const Message& msg);
+
+private:
+ DeleteOp(Delete&& other) : Delete(other) {}
};
+namespace write_ops {
+
/**
- * A parsed Delete operation.
+ * Retrieves the statement id for the write at the specified position in the write batch entries
+ * array.
*/
-struct DeleteOp : ParsedWriteOp {
- struct SingleDelete {
- BSONObj toBSON() const {
- BSONObjBuilder builder;
- builder << "q" << query;
- builder << "limit" << (multi ? 0 : 1);
- if (!collation.isEmpty()) {
- builder << "collation" << collation;
- }
- return builder.obj();
- }
-
- BSONObj query;
- BSONObj collation;
- bool multi = true;
- };
-
- std::vector<SingleDelete> deletes;
-};
+int32_t getStmtIdForWriteAt(const WriteCommandBase& writeCommandBase, size_t writePos);
+
+template <class T>
+int32_t getStmtIdForWriteAt(const T& op, size_t writePos) {
+ return getStmtIdForWriteAt(op.getWriteCommandBase(), writePos);
+}
+
+// TODO: Delete this getter once IDL supports defaults for object and array fields
+template <class T>
+const BSONObj& collationOf(const T& opEntry) {
+ static const BSONObj emptyBSON{};
+ return opEntry.getCollation().get_value_or(emptyBSON);
+}
+
+// TODO: Delete this getter once IDL supports defaults for object and array fields
+template <class T>
+const std::vector<BSONObj>& arrayFiltersOf(const T& opEntry) {
+ static const std::vector<BSONObj> emptyBSONArray{};
+ return opEntry.getArrayFilters().get_value_or(emptyBSONArray);
+}
+} // namespace write_ops
} // namespace mongo