summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2019-03-29 21:52:05 -0400
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2019-04-09 13:26:49 -0400
commit8cdc51e7810f7fd8898a4c60b935e389f04659ee (patch)
tree054f0b5edf0b462cfed30288ef12d5716f16be3d /src/mongo/db/repl
parentba963c9a88eda87942926e6b17901f8c00bd46d0 (diff)
downloadmongo-8cdc51e7810f7fd8898a4c60b935e389f04659ee.tar.gz
SERVER-40508 Remove hash from OplogSlot and make OplogSlot an alias for OpTime.r4.1.10
Diffstat (limited to 'src/mongo/db/repl')
-rw-r--r--src/mongo/db/repl/oplog.cpp32
-rw-r--r--src/mongo/db/repl/oplog.h9
2 files changed, 16 insertions, 25 deletions
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index f421603e99f..129f7ab16db 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -137,9 +137,6 @@ struct LocalOplogInfo {
// Synchronizes the section where a new Timestamp is generated and when it is registered in the
// storage engine.
stdx::mutex newOpMutex;
-
- // Used to generate "h" fields in pv0. Synchronized by newOpMutex.
- PseudoRandom hashGenerator{std::unique_ptr<SecureRandom>(SecureRandom::create())->nextInt64()};
};
const auto localOplogInfo = ServiceContext::declareDecoration<LocalOplogInfo>();
@@ -185,8 +182,7 @@ void _getNextOpTimes(OperationContext* opCtx,
}
for (std::size_t i = 0; i < count; i++) {
- slotsOut[i].opTime = {Timestamp(ts.asULL() + i), term};
- slotsOut[i].hash = oplogInfo.hashGenerator.nextInt64();
+ slotsOut[i] = {Timestamp(ts.asULL() + i), term};
}
}
@@ -449,7 +445,6 @@ OplogDocWriter _logOpWriter(OperationContext* opCtx,
const BSONObj* o2,
bool fromMigrate,
OpTime optime,
- long long hashNew,
Date_t wallTime,
const OperationSessionInfo& sessionInfo,
StmtId statementId,
@@ -461,7 +456,10 @@ OplogDocWriter _logOpWriter(OperationContext* opCtx,
b.append("ts", optime.getTimestamp());
if (optime.getTerm() != -1)
b.append("t", optime.getTerm());
- b.append("h", hashNew);
+
+ // Always write zero hash instead of using FCV to gate this for retryable writes
+ // and change stream, who expect to be able to read oplog across FCV's.
+ b.append("h", 0LL);
b.append("v", OplogEntry::kOplogVersion);
b.append("op", opstr);
b.append("ns", nss.ns());
@@ -608,7 +606,7 @@ OpTime logOp(OperationContext* opCtx,
auto const oplog = oplogInfo.oplog;
OplogSlot slot;
WriteUnitOfWork wuow(opCtx);
- if (oplogSlot.opTime.isNull()) {
+ if (oplogSlot.isNull()) {
_getNextOpTimes(opCtx, oplog, 1, &slot);
} else {
slot = oplogSlot;
@@ -621,8 +619,7 @@ OpTime logOp(OperationContext* opCtx,
obj,
o2,
fromMigrate,
- slot.opTime,
- slot.hash,
+ slot,
wallClockTime,
sessionInfo,
statementId,
@@ -630,10 +627,10 @@ OpTime logOp(OperationContext* opCtx,
prepare,
inTxn);
const DocWriter* basePtr = &writer;
- auto timestamp = slot.opTime.getTimestamp();
- _logOpsInner(opCtx, nss, &basePtr, &timestamp, 1, oplog, slot.opTime, wallClockTime);
+ auto timestamp = slot.getTimestamp();
+ _logOpsInner(opCtx, nss, &basePtr, &timestamp, 1, oplog, slot, wallClockTime);
wuow.commit();
- return slot.opTime;
+ return slot;
}
std::vector<OpTime> logInsertOps(OperationContext* opCtx,
@@ -686,7 +683,7 @@ std::vector<OpTime> logInsertOps(OperationContext* opCtx,
// Make a mutable copy.
auto insertStatementOplogSlot = begin[i].oplogSlot;
// Fetch optime now, if not already fetched.
- if (insertStatementOplogSlot.opTime.isNull()) {
+ if (insertStatementOplogSlot.isNull()) {
_getNextOpTimes(opCtx, oplog, 1, &insertStatementOplogSlot);
}
// Only 'applyOps' oplog entries can be prepared.
@@ -698,17 +695,16 @@ std::vector<OpTime> logInsertOps(OperationContext* opCtx,
begin[i].doc,
NULL,
fromMigrate,
- insertStatementOplogSlot.opTime,
- insertStatementOplogSlot.hash,
+ insertStatementOplogSlot,
wallClockTime,
sessionInfo,
begin[i].stmtId,
oplogLink,
prepare,
false /* inTxn */));
- oplogLink.prevOpTime = insertStatementOplogSlot.opTime;
+ oplogLink.prevOpTime = insertStatementOplogSlot;
timestamps[i] = oplogLink.prevOpTime.getTimestamp();
- opTimes.push_back(insertStatementOplogSlot.opTime);
+ opTimes.push_back(insertStatementOplogSlot);
}
MONGO_FAIL_POINT_BLOCK(sleepBetweenInsertOpTimeGenerationAndLogOp, customWait) {
diff --git a/src/mongo/db/repl/oplog.h b/src/mongo/db/repl/oplog.h
index 694d5c38152..d9fa2c8bf74 100644
--- a/src/mongo/db/repl/oplog.h
+++ b/src/mongo/db/repl/oplog.h
@@ -51,12 +51,7 @@ class OperationContext;
class OperationSessionInfo;
class Session;
-struct OplogSlot {
- OplogSlot() {}
- OplogSlot(repl::OpTime opTime, std::int64_t hash) : opTime(opTime), hash(hash) {}
- repl::OpTime opTime;
- std::int64_t hash = 0;
-};
+using OplogSlot = repl::OpTime;
struct InsertStatement {
public:
@@ -67,7 +62,7 @@ public:
InsertStatement(StmtId statementId, BSONObj toInsert, OplogSlot os)
: stmtId(statementId), oplogSlot(os), doc(toInsert) {}
InsertStatement(BSONObj toInsert, Timestamp ts, long long term)
- : oplogSlot(repl::OpTime(ts, term), 0), doc(toInsert) {}
+ : oplogSlot(repl::OpTime(ts, term)), doc(toInsert) {}
StmtId stmtId = kUninitializedStmtId;
OplogSlot oplogSlot;