diff options
Diffstat (limited to 'src/mongo/db/repl')
-rw-r--r-- | src/mongo/db/repl/SConscript | 3 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog_entry.cpp | 38 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog_entry.h | 10 |
3 files changed, 50 insertions, 1 deletions
diff --git a/src/mongo/db/repl/SConscript b/src/mongo/db/repl/SConscript index 4b672142624..391f09637df 100644 --- a/src/mongo/db/repl/SConscript +++ b/src/mongo/db/repl/SConscript @@ -179,11 +179,11 @@ env.Library( LIBDEPS=[ '$BUILD_DIR/mongo/base', '$BUILD_DIR/mongo/idl/idl_parser', - '$BUILD_DIR/mongo/db/catalog/collection_options', '$BUILD_DIR/mongo/db/catalog/health_log', '$BUILD_DIR/mongo/db/db_raii', ], LIBDEPS_PRIVATE=[ + '$BUILD_DIR/mongo/db/catalog/collection_options', '$BUILD_DIR/mongo/db/query_exec', '$BUILD_DIR/mongo/util/md5', ], @@ -488,6 +488,7 @@ env.Library( 'optime_and_wall_time_base', '$BUILD_DIR/mongo/base', '$BUILD_DIR/mongo/db/logical_session_id', + '$BUILD_DIR/mongo/db/catalog/collection_options', '$BUILD_DIR/mongo/idl/idl_parser', ], ) diff --git a/src/mongo/db/repl/oplog_entry.cpp b/src/mongo/db/repl/oplog_entry.cpp index 4da5afdc4dc..787e54f0384 100644 --- a/src/mongo/db/repl/oplog_entry.cpp +++ b/src/mongo/db/repl/oplog_entry.cpp @@ -33,6 +33,7 @@ #include "mongo/db/repl/oplog_entry.h" +#include "mongo/db/index/index_descriptor.h" #include "mongo/db/namespace_string.h" #include "mongo/util/log.h" #include "mongo/util/time_support.h" @@ -164,6 +165,31 @@ ReplOperation MutableOplogEntry::makeInsertOperation(const NamespaceString& nss, return op; } +BSONObj MutableOplogEntry::makeCreateCollCmdObj(const NamespaceString& collectionName, + const CollectionOptions& options, + const BSONObj& idIndex) { + BSONObjBuilder b; + b.append("create", collectionName.coll().toString()); + { + // Don't store the UUID as part of the options, but instead only at the top level + CollectionOptions optionsToStore = options; + optionsToStore.uuid.reset(); + b.appendElements(optionsToStore.toBSON()); + } + + // Include the full _id index spec in the oplog for index versions >= 2. + if (!idIndex.isEmpty()) { + auto versionElem = idIndex[IndexDescriptor::kIndexVersionFieldName]; + invariant(versionElem.isNumber()); + if (IndexDescriptor::IndexVersion::kV2 <= + static_cast<IndexDescriptor::IndexVersion>(versionElem.numberInt())) { + b.append("idIndex", idIndex); + } + } + + return b.obj(); +} + ReplOperation MutableOplogEntry::makeUpdateOperation(const NamespaceString nss, boost::optional<UUID> uuid, const BSONObj& update, @@ -177,6 +203,18 @@ ReplOperation MutableOplogEntry::makeUpdateOperation(const NamespaceString nss, return op; } +ReplOperation MutableOplogEntry::makeCreateCommand(const NamespaceString nss, + const CollectionOptions& options, + const BSONObj& idIndex) { + + ReplOperation op; + op.setOpType(OpTypeEnum::kCommand); + op.setNss(nss.getCommandNS()); + op.setUuid(options.uuid); + op.setObject(makeCreateCollCmdObj(nss, options, idIndex)); + return op; +} + ReplOperation MutableOplogEntry::makeDeleteOperation(const NamespaceString& nss, boost::optional<UUID> uuid, const BSONObj& docToDelete) { diff --git a/src/mongo/db/repl/oplog_entry.h b/src/mongo/db/repl/oplog_entry.h index c01b2766d1b..b1678b37267 100644 --- a/src/mongo/db/repl/oplog_entry.h +++ b/src/mongo/db/repl/oplog_entry.h @@ -31,6 +31,7 @@ #include "mongo/bson/bsonobj.h" #include "mongo/bson/simple_bsonobj_comparator.h" +#include "mongo/db/catalog/collection_options.h" #include "mongo/db/logical_session_id.h" #include "mongo/db/repl/apply_ops_gen.h" #include "mongo/db/repl/oplog_entry_gen.h" @@ -90,6 +91,14 @@ public: boost::optional<UUID> uuid, const BSONObj& docToDelete); + static ReplOperation makeCreateCommand(const NamespaceString nss, + const mongo::CollectionOptions& options, + const BSONObj& idIndex); + + static BSONObj makeCreateCollCmdObj(const NamespaceString& collectionName, + const mongo::CollectionOptions& options, + const BSONObj& idIndex); + static StatusWith<MutableOplogEntry> parse(const BSONObj& object); MutableOplogEntry() : OplogEntryBase() {} @@ -213,6 +222,7 @@ public: // Make helper functions accessible. using MutableOplogEntry::getOpTime; + using MutableOplogEntry::makeCreateCommand; using MutableOplogEntry::makeDeleteOperation; using MutableOplogEntry::makeInsertOperation; using MutableOplogEntry::makeUpdateOperation; |