mirror of https://github.com/mongodb/mongo
SERVER-115345 Avoid unconditionally constructing error message for replicated record ids (#45157)
GitOrigin-RevId: 0527c551cc2c26bbf539a34aa6d56b8197bd2998
This commit is contained in:
parent
388e48f1dd
commit
062636c20e
|
|
@ -1511,28 +1511,32 @@ Status applyOperation_inlock(OperationContext* opCtx,
|
||||||
|
|
||||||
const CollectionPtr& collection = collectionAcquisition.getCollectionPtr();
|
const CollectionPtr& collection = collectionAcquisition.getCollectionPtr();
|
||||||
|
|
||||||
|
constexpr auto rridErrMsg =
|
||||||
|
"Unexpected recordId value for collection with ns: '{}', uuid: '{}', recordIdsReplicated: "
|
||||||
|
"'{}' when applying oplog entry: '{}'";
|
||||||
if (collection &&
|
if (collection &&
|
||||||
(opType == OpTypeEnum::kInsert || opType == OpTypeEnum::kUpdate ||
|
(opType == OpTypeEnum::kInsert || opType == OpTypeEnum::kUpdate ||
|
||||||
opType == OpTypeEnum::kDelete)) {
|
opType == OpTypeEnum::kDelete)) {
|
||||||
auto rridErrMsg = fmt::format(
|
|
||||||
"Unexpected recordId value for collection with ns: '{}', uuid: '{}', "
|
|
||||||
"recordIdsReplicated: '{}' when applying oplog entry: '{}'",
|
|
||||||
collection->ns().toStringForErrorMsg(),
|
|
||||||
collection->uuid().toString(),
|
|
||||||
collection->areRecordIdsReplicated(),
|
|
||||||
redact(opOrGroupedInserts.toBSON()).toString());
|
|
||||||
if (mode == repl::OplogApplication::Mode::kApplyOpsCmd) {
|
if (mode == repl::OplogApplication::Mode::kApplyOpsCmd) {
|
||||||
// Only disallow applying an operation with 'rid' field on a collection not using
|
// Only disallow applying an operation with 'rid' field on a collection not using
|
||||||
// replicated record ids.
|
// replicated record ids.
|
||||||
tassert(11454700,
|
tassert(11454700,
|
||||||
rridErrMsg,
|
fmt::format(rridErrMsg,
|
||||||
|
collection->ns().toStringForErrorMsg(),
|
||||||
|
collection->uuid().toString(),
|
||||||
|
collection->areRecordIdsReplicated(),
|
||||||
|
redact(opOrGroupedInserts.toBSON()).toString()),
|
||||||
!op.getDurableReplOperation().getRecordId().has_value() ||
|
!op.getDurableReplOperation().getRecordId().has_value() ||
|
||||||
collection->areRecordIdsReplicated());
|
collection->areRecordIdsReplicated());
|
||||||
} else {
|
} else {
|
||||||
// Check that the operation's 'rid' field is consistent with whether the collection is
|
// Check that the operation's 'rid' field is consistent with whether the collection is
|
||||||
// using replicated record ids.
|
// using replicated record ids.
|
||||||
tassert(11454701,
|
tassert(11454701,
|
||||||
rridErrMsg,
|
fmt::format(rridErrMsg,
|
||||||
|
collection->ns().toStringForErrorMsg(),
|
||||||
|
collection->uuid().toString(),
|
||||||
|
collection->areRecordIdsReplicated(),
|
||||||
|
redact(opOrGroupedInserts.toBSON()).toString()),
|
||||||
op.getDurableReplOperation().getRecordId().has_value() ==
|
op.getDurableReplOperation().getRecordId().has_value() ==
|
||||||
collection->areRecordIdsReplicated());
|
collection->areRecordIdsReplicated());
|
||||||
}
|
}
|
||||||
|
|
@ -1626,24 +1630,27 @@ Status applyOperation_inlock(OperationContext* opCtx,
|
||||||
// which is intentional.
|
// which is intentional.
|
||||||
for (size_t i = 0; i < insertObjs.size(); i++) {
|
for (size_t i = 0; i < insertObjs.size(); i++) {
|
||||||
auto optRid = insertOps[i]->getDurableReplOperation().getRecordId();
|
auto optRid = insertOps[i]->getDurableReplOperation().getRecordId();
|
||||||
auto errMsg = fmt::format(
|
|
||||||
"Unexpected recordId value for collection with ns: '{}', uuid: '{}', "
|
|
||||||
"recordIdsReplicated: '{}' when applying oplog entry: '{}'",
|
|
||||||
collection->ns().toStringForErrorMsg(),
|
|
||||||
collection->uuid().toString(),
|
|
||||||
collection->areRecordIdsReplicated(),
|
|
||||||
redact(insertOps[i]->getDurableReplOperation().toBSON()).toString());
|
|
||||||
if (mode == repl::OplogApplication::Mode::kApplyOpsCmd) {
|
if (mode == repl::OplogApplication::Mode::kApplyOpsCmd) {
|
||||||
// Only disallow applying an operation with 'rid' field on a collection not
|
// Only disallow applying an operation with 'rid' field on a collection not
|
||||||
// using replicated record ids.
|
// using replicated record ids.
|
||||||
tassert(11454702,
|
tassert(11454702,
|
||||||
errMsg,
|
fmt::format(rridErrMsg,
|
||||||
|
collection->ns().toStringForErrorMsg(),
|
||||||
|
collection->uuid().toString(),
|
||||||
|
collection->areRecordIdsReplicated(),
|
||||||
|
redact(insertOps[i]->getDurableReplOperation().toBSON())
|
||||||
|
.toString()),
|
||||||
!optRid.has_value() || collection->areRecordIdsReplicated());
|
!optRid.has_value() || collection->areRecordIdsReplicated());
|
||||||
} else {
|
} else {
|
||||||
// Check that the operation's 'rid' field is consistent with whether the
|
// Check that the operation's 'rid' field is consistent with whether the
|
||||||
// collection is using replicated record ids.
|
// collection is using replicated record ids.
|
||||||
tassert(11454703,
|
tassert(11454703,
|
||||||
errMsg,
|
fmt::format(rridErrMsg,
|
||||||
|
collection->ns().toStringForErrorMsg(),
|
||||||
|
collection->uuid().toString(),
|
||||||
|
collection->areRecordIdsReplicated(),
|
||||||
|
redact(insertOps[i]->getDurableReplOperation().toBSON())
|
||||||
|
.toString()),
|
||||||
optRid.has_value() == collection->areRecordIdsReplicated());
|
optRid.has_value() == collection->areRecordIdsReplicated());
|
||||||
}
|
}
|
||||||
if (optRid) {
|
if (optRid) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue