SERVER-125120 Remove unused connecting to random secondaries in testing (#52421)

GitOrigin-RevId: a321dfd75c10adb2786329c6d89d9a0dc21c186a
This commit is contained in:
Jan 2026-04-23 09:12:25 +02:00 committed by MongoDB Bot
parent 432be8c0d2
commit 22fa3bed65
4 changed files with 0 additions and 138 deletions

View File

@ -113,12 +113,6 @@ Specify any of the following as the `hooks` in your
collection validation against test servers while a test is running.
- This will run on all collections in all databases on every stand-alone node, primary replica-set
node, or primary shard node.
- [`ValidateDirectSecondaryReads`](./validate_direct_secondary_reads.py) - Only supported in suites
that use `ReplicaSetFixture`.
- To be used with `set_read_preference_secondary.js` and `implicit_enable_profiler.js` in suites
that read directly from secondaries in a replica set. Check the profiler collections of all
databases at the end of the suite to verify that each secondary only ran the read commands it
got directly from the shell.
- [`WaitForReplication`](./wait_for_replication.py) - Wait for replication to complete.
## Interfaces

View File

@ -1,23 +0,0 @@
import os.path
from buildscripts.resmokelib.testing.hooks import jsfile
class ValidateDirectSecondaryReads(jsfile.PerClusterDataConsistencyHook):
"""Only supported in suites that use ReplicaSetFixture.
To be used with set_read_preference_secondary.js and implicit_enable_profiler.js in suites
that read directly from secondaries in a replica set. Check the profiler collections of all
databases at the end of the suite to verify that each secondary only ran the read commands it
got directly from the shell.
"""
IS_BACKGROUND = False
def __init__(self, hook_logger, fixture, shell_options=None):
"""Initialize ValidateDirectSecondaryReads."""
description = "Validate direct secondary reads"
js_filename = os.path.join("jstests", "hooks", "run_validate_direct_secondary_reads.js")
jsfile.JSHook.__init__(
self, hook_logger, fixture, js_filename, description, shell_options=shell_options
)

View File

@ -1,31 +0,0 @@
// To be used with set_read_preference_secondary.js and implicit_enable_profiler.js in suites
// that read directly from secondaries in a replica set. Check the profiler collections of all
// databases at the end of the suite to verify that each secondary only ran the read commands it
// got directly from the shell.
import {DiscoverTopology, Topology} from "jstests/libs/discover_topology.js";
import {
getTotalNumProfilerDocs,
validateProfilerCollections,
} from "jstests/noPassthrough/rs_endpoint/lib/validate_direct_secondary_reads.js";
assert(TestData.connectDirectlyToRandomSubsetOfSecondaries);
assert.eq(typeof db, "object", "Invalid `db` object, is the shell connected to a mongod?");
const topology = DiscoverTopology.findConnectedNodes(db.getMongo());
if (topology.type !== Topology.kReplicaSet) {
throw new Error("Unrecognized topology format:" + tojsononeline(topology));
}
const hostColl = db.getSiblingDB("config").connectDirectlyToSecondaries.hosts;
const hostDocs = hostColl.find().toArray();
assert.gt(hostDocs.length, 0, "Could not find information about direct secondary reads");
print("Validating profiler collections on hosts " + tojsononeline(hostDocs));
// Count the number of profiler docs to verify that that profiling is enabled.
const numProfilerDocsPerHost = {};
hostDocs.forEach((hostDoc) => {
validateProfilerCollections(hostDoc, hostDocs, numProfilerDocsPerHost);
});
jsTest.log("Finished validating profiler collections on hosts " + tojsononeline({numProfilerDocsPerHost}));
assert.gt(getTotalNumProfilerDocs(numProfilerDocsPerHost), 0);

View File

@ -51,59 +51,6 @@ function getRandomElement(arr) {
return arr[getRandInteger(0, arr.length - 1)];
}
const kSecondariesToConnectDirectlyTo = [];
if (TestData.connectDirectlyToRandomSubsetOfSecondaries) {
const hostColl = db.getSiblingDB("config").connectDirectlyToSecondaries.hosts;
hostColl.find().forEach((doc) => {
if (doc.isSecondary && !doc.isExcluded) {
kSecondariesToConnectDirectlyTo.push({host: doc.host, comment: doc.comment});
}
});
if (kSecondariesToConnectDirectlyTo.length == 0) {
// This is the first time this file is loaded. Choose the secondaries to connect
// directly to.
const helloRes = assert.commandWorked(db.adminCommand({hello: 1}));
if (!helloRes.hasOwnProperty("setName")) {
throw new Error(
"Cannot connect directly to a secondary since this is not a replica set. " +
"Unrecognized topology format:" +
tojson(helloRes),
);
}
assert.gt(helloRes.passives.length, 0, {
msg: "Cannot definitively determine which nodes are secondaries since all nodes " + "are electable",
helloRes,
});
assert.gt(helloRes.passives.length, 1, {
msg: "Cannot connect to only a subset of secondaries since there is only one secondary",
helloRes,
});
jsTest.log("Choosing secondaries to reads directly from");
assert.commandWorked(
hostColl.insert({
host: helloRes.primary,
isPrimary: true,
}),
);
const secondaryToExclude = helloRes.passives[getRandInteger(0, helloRes.passives.length - 1)];
helloRes.passives.forEach((host) => {
if (host == secondaryToExclude) {
assert.commandWorked(hostColl.insert({host, isSecondary: true, isExcluded: true}));
} else {
const comment = extractUUIDFromObject(UUID());
kSecondariesToConnectDirectlyTo.push({host, comment});
assert.commandWorked(hostColl.insert({host, isSecondary: true, comment}));
}
});
}
}
jsTest.log(
"Forcing reads to go directly to the following secondaries: " + tojsononeline(kSecondariesToConnectDirectlyTo),
);
function runCommandWithReadPreferenceSecondary(conn, dbName, commandName, commandObj, func, makeFuncArgs) {
if (typeof commandObj !== "object" || commandObj === null) {
return func.apply(conn, makeFuncArgs(commandObj));
@ -208,31 +155,6 @@ function runCommandWithReadPreferenceSecondary(conn, dbName, commandName, comman
} else if (!commandObj.hasOwnProperty("$readPreference")) {
commandObj.$readPreference = kReadPreferenceToUse;
}
if (TestData.connectDirectlyToRandomSubsetOfSecondaries) {
const randomSecondary = getRandomElement(kSecondariesToConnectDirectlyTo);
const newConn = new Mongo("mongodb://" + randomSecondary.host + "/?directConnection=true");
if (conn.isAutoEncryptionEnabled()) {
const clientSideFLEOptions = conn.getAutoEncryptionOptions();
assert(newConn.setAutoEncryption(clientSideFLEOptions));
newConn.toggleAutoEncryption(true);
}
// To guarantee causal consistency, wait for the operationTime on the original
// connection.
const currentClusterTime = conn.getClusterTime();
assert.soon(() => {
const res = assert.commandWorked(newConn.adminCommand({"ping": 1}));
return timestampCmp(res.operationTime, currentClusterTime.clusterTime) >= 0;
});
if (!commandObj.hasOwnProperty("comment")) {
// If this command already has the "comment" field, do not overwrite it since that
// could cause the test to fail.
commandObj.comment = randomSecondary.comment;
}
conn = newConn;
}
}
const serverResponse = func.apply(conn, makeFuncArgs(commandObj));