SERVER-122042 Report raw BSON for mismatched oplog entries found by oplog consistency check (#49931)
GitOrigin-RevId: bf03d488d0aa7da785384af62e751faa3fa2ae8d
This commit is contained in:
parent
2ac9406a15
commit
bfa405c08d
@ -250,6 +250,7 @@ export default [
|
||||
// src/mongo/scripting/mozjs/bson.d.ts
|
||||
bsonBinaryEqual: true,
|
||||
bsonObjToArray: true,
|
||||
bsonToBase64: true,
|
||||
bsonUnorderedFieldsCompare: true,
|
||||
bsonWoCompare: true,
|
||||
|
||||
|
||||
@ -89,6 +89,7 @@ const expectedGlobalVars = [
|
||||
"assert",
|
||||
"bsonBinaryEqual",
|
||||
"bsonObjToArray",
|
||||
"bsonToBase64",
|
||||
"bsonUnorderedFieldsCompare",
|
||||
"bsonWoCompare",
|
||||
"buildInfo",
|
||||
|
||||
@ -4096,17 +4096,15 @@ function checkOplogs(rst, msgPrefix = "checkOplogs", secondaries) {
|
||||
if (!bsonBinaryEqual(oplogEntry0, oplogEntry1)) {
|
||||
const query = prevOplogEntry ? {ts: {$lte: prevOplogEntry.ts}} : {};
|
||||
rst.nodes.forEach((node) => rst.dumpOplog(node, query, 100));
|
||||
const log =
|
||||
msgPrefix +
|
||||
", non-matching oplog entries for the following nodes: \n" +
|
||||
reader0.mongo.host +
|
||||
": " +
|
||||
tojsononeline(oplogEntry0) +
|
||||
"\n" +
|
||||
reader1.mongo.host +
|
||||
": " +
|
||||
tojsononeline(oplogEntry1);
|
||||
assert(false, log);
|
||||
const logLines = [
|
||||
`${msgPrefix}, non-matching oplog entries for the following nodes:`,
|
||||
`${reader0.mongo.host}: ${tojsononeline(oplogEntry0)}`,
|
||||
`${reader1.mongo.host}: ${tojsononeline(oplogEntry1)}`,
|
||||
`non-matching oplog entries base64-encoded raw BSON:`,
|
||||
`${reader0.mongo.host}: ${bsonToBase64(oplogEntry0)}`,
|
||||
`${reader1.mongo.host}: ${bsonToBase64(oplogEntry1)}`,
|
||||
];
|
||||
assert(false, logLines.join("\n"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -47,6 +47,7 @@
|
||||
#include "mongo/scripting/mozjs/common/valuereader.h"
|
||||
#include "mongo/scripting/mozjs/common/valuewriter.h"
|
||||
#include "mongo/util/assert_util.h"
|
||||
#include "mongo/util/base64.h"
|
||||
#include "mongo/util/string_map.h"
|
||||
|
||||
#include <cstddef>
|
||||
@ -73,11 +74,12 @@ namespace mozjs {
|
||||
|
||||
const char* const BSONInfo::className = "BSON";
|
||||
|
||||
const JSFunctionSpec BSONInfo::freeFunctions[5] = {
|
||||
const JSFunctionSpec BSONInfo::freeFunctions[6] = {
|
||||
MONGO_ATTACH_JS_FUNCTION(bsonWoCompare),
|
||||
MONGO_ATTACH_JS_FUNCTION(bsonUnorderedFieldsCompare),
|
||||
MONGO_ATTACH_JS_FUNCTION(bsonBinaryEqual),
|
||||
MONGO_ATTACH_JS_FUNCTION(bsonObjToArray),
|
||||
MONGO_ATTACH_JS_FUNCTION(bsonToBase64),
|
||||
JS_FS_END,
|
||||
};
|
||||
|
||||
@ -390,6 +392,18 @@ void BSONInfo::Functions::bsonBinaryEqual::call(JSContext* cx, JS::CallArgs args
|
||||
args.rval().setBoolean(bsonObject1.binaryEqual(bsonObject2));
|
||||
}
|
||||
|
||||
void BSONInfo::Functions::bsonToBase64::call(JSContext* cx, JS::CallArgs args) {
|
||||
if (args.length() != 1)
|
||||
uasserted(ErrorCodes::BadValue, "bsonToBase64 needs 1 argument");
|
||||
|
||||
auto* runtime = getCommonRuntime(cx);
|
||||
bool isBSON = getProto<BSONInfo>(runtime).instanceOf(args.get(0));
|
||||
BSONObj bsonObject = getBSONFromArg(cx, args.get(0), isBSON);
|
||||
|
||||
auto encoded = mongo::base64::encode(StringData(bsonObject.objdata(), bsonObject.objsize()));
|
||||
ValueReader(cx, args.rval()).fromStringData(encoded);
|
||||
}
|
||||
|
||||
void BSONInfo::postInstall(JSContext* cx, JS::HandleObject global, JS::HandleObject proto) {
|
||||
JS::RootedValue value(cx);
|
||||
value.setBoolean(true);
|
||||
|
||||
@ -4,3 +4,4 @@ declare function bsonWoCompare(a, b): number;
|
||||
declare function bsonUnorderedFieldsCompare(a, b): number;
|
||||
declare function bsonBinaryEqual(a, b): number;
|
||||
declare function bsonObjToArray(a, b): number;
|
||||
declare function bsonToBase64(a): string;
|
||||
|
||||
@ -84,9 +84,10 @@ struct BSONInfo : public BaseInfo {
|
||||
MONGO_DECLARE_JS_FUNCTION(bsonUnorderedFieldsCompare);
|
||||
MONGO_DECLARE_JS_FUNCTION(bsonBinaryEqual);
|
||||
MONGO_DECLARE_JS_FUNCTION(bsonObjToArray);
|
||||
MONGO_DECLARE_JS_FUNCTION(bsonToBase64);
|
||||
};
|
||||
|
||||
static const JSFunctionSpec freeFunctions[5];
|
||||
static const JSFunctionSpec freeFunctions[6];
|
||||
|
||||
static std::tuple<BSONObj*, bool> originalBSON(JSContext* cx, JS::HandleObject obj);
|
||||
static void make(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user