From 8e2b0ccc273d18f5d744807b990f80f014ca16f6 Mon Sep 17 00:00:00 2001 From: Lauren Schaefer Date: Wed, 12 Jan 2022 10:35:48 -0500 Subject: [PATCH] fix(NODE-3792): remove offensive language throughout the codebase (#3091) --- src/bulk/common.ts | 9 +-- src/change_stream.ts | 6 +- src/cmap/auth/mongo_credentials.ts | 18 ++--- src/cmap/command_monitoring_events.ts | 3 +- src/cmap/connect.ts | 34 ++++---- src/cmap/connection.ts | 22 ++--- src/cmap/wire_protocol/compression.ts | 3 +- src/constants.ts | 6 ++ src/operations/add_user.ts | 2 +- src/sdam/events.ts | 8 +- src/sdam/monitor.ts | 34 ++++---- src/sdam/server.ts | 2 +- src/sdam/server_description.ts | 81 +++++++++---------- src/sdam/topology.ts | 16 ++-- src/sdam/topology_description.ts | 2 +- src/utils.ts | 12 +-- .../unit-sdam/server_selection/spec.test.js | 3 +- test/functional/unit-sdam/topology.test.js | 3 +- test/manual/socks5.test.ts | 3 +- test/unit/_MISC_optional_require.test.js | 12 +-- test/unit/cmap/connection.test.js | 3 +- 21 files changed, 140 insertions(+), 142 deletions(-) diff --git a/src/bulk/common.ts b/src/bulk/common.ts index 487fef3a8c..8364e72706 100644 --- a/src/bulk/common.ts +++ b/src/bulk/common.ts @@ -940,7 +940,7 @@ export abstract class BulkOperationBase { const topology = getTopology(collection); options = options == null ? {} : options; - // TODO Bring from driver information in isMaster + // TODO Bring from driver information in hello // Get the namespace for the write operations const namespace = collection.s.namespace; // Used to mark operation as executed @@ -950,16 +950,15 @@ export abstract class BulkOperationBase { const currentOp = undefined; // Set max byte size - const isMaster = topology.lastIsMaster(); + const hello = topology.lastHello(); // If we have autoEncryption on, batch-splitting must be done on 2mb chunks, but single documents // over 2mb are still allowed const usingAutoEncryption = !!(topology.s.options && topology.s.options.autoEncrypter); const maxBsonObjectSize = - isMaster && isMaster.maxBsonObjectSize ? isMaster.maxBsonObjectSize : 1024 * 1024 * 16; + hello && hello.maxBsonObjectSize ? hello.maxBsonObjectSize : 1024 * 1024 * 16; const maxBatchSizeBytes = usingAutoEncryption ? 1024 * 1024 * 2 : maxBsonObjectSize; - const maxWriteBatchSize = - isMaster && isMaster.maxWriteBatchSize ? isMaster.maxWriteBatchSize : 1000; + const maxWriteBatchSize = hello && hello.maxWriteBatchSize ? hello.maxWriteBatchSize : 1000; // Calculates the largest possible size of an Array key, represented as a BSON string // element. This calculation: diff --git a/src/change_stream.ts b/src/change_stream.ts index 28fc24c536..443b663d7a 100644 --- a/src/change_stream.ts +++ b/src/change_stream.ts @@ -71,7 +71,7 @@ export interface ResumeOptions { } /** - * Represents the logical starting point for a new or resuming {@link https://docs.mongodb.com/master/changeStreams/#change-stream-resume-token| Change Stream} on the server. + * Represents the logical starting point for a new or resuming {@link https://docs.mongodb.com/manual/changeStreams/#std-label-change-stream-resume| Change Stream} on the server. * @public */ export type ResumeToken = unknown; @@ -98,9 +98,9 @@ export interface ChangeStreamOptions extends AggregateOptions { fullDocument?: string; /** The maximum amount of time for the server to wait on new documents to satisfy a change stream query. */ maxAwaitTimeMS?: number; - /** Allows you to start a changeStream after a specified event. See {@link https://docs.mongodb.com/master/changeStreams/#resumeafter-for-change-streams|ChangeStream documentation}. */ + /** Allows you to start a changeStream after a specified event. See {@link https://docs.mongodb.com/manual/changeStreams/#resumeafter-for-change-streams|ChangeStream documentation}. */ resumeAfter?: ResumeToken; - /** Similar to resumeAfter, but will allow you to start after an invalidated event. See {@link https://docs.mongodb.com/master/changeStreams/#startafter-for-change-streams|ChangeStream documentation}. */ + /** Similar to resumeAfter, but will allow you to start after an invalidated event. See {@link https://docs.mongodb.com/manual/changeStreams/#startafter-for-change-streams|ChangeStream documentation}. */ startAfter?: ResumeToken; /** Will start the changeStream after the specified operationTime. */ startAtOperationTime?: OperationTime; diff --git a/src/cmap/auth/mongo_credentials.ts b/src/cmap/auth/mongo_credentials.ts index 4e2ab95ea4..6f0e453ed3 100644 --- a/src/cmap/auth/mongo_credentials.ts +++ b/src/cmap/auth/mongo_credentials.ts @@ -5,18 +5,18 @@ import { MongoAPIError, MongoMissingCredentialsError } from '../../error'; import { AUTH_MECHS_AUTH_SRC_EXTERNAL, AuthMechanism } from './providers'; // https://github.com/mongodb/specifications/blob/master/source/auth/auth.rst -function getDefaultAuthMechanism(ismaster?: Document): AuthMechanism { - if (ismaster) { - // If ismaster contains saslSupportedMechs, use scram-sha-256 +function getDefaultAuthMechanism(hello?: Document): AuthMechanism { + if (hello) { + // If hello contains saslSupportedMechs, use scram-sha-256 // if it is available, else scram-sha-1 - if (Array.isArray(ismaster.saslSupportedMechs)) { - return ismaster.saslSupportedMechs.includes(AuthMechanism.MONGODB_SCRAM_SHA256) + if (Array.isArray(hello.saslSupportedMechs)) { + return hello.saslSupportedMechs.includes(AuthMechanism.MONGODB_SCRAM_SHA256) ? AuthMechanism.MONGODB_SCRAM_SHA256 : AuthMechanism.MONGODB_SCRAM_SHA1; } // Fallback to legacy selection method. If wire version >= 3, use scram-sha-1 - if (ismaster.maxWireVersion >= 3) { + if (hello.maxWireVersion >= 3) { return AuthMechanism.MONGODB_SCRAM_SHA1; } } @@ -107,16 +107,16 @@ export class MongoCredentials { * If the authentication mechanism is set to "default", resolves the authMechanism * based on the server version and server supported sasl mechanisms. * - * @param ismaster - An ismaster response from the server + * @param hello - A hello response from the server */ - resolveAuthMechanism(ismaster?: Document): MongoCredentials { + resolveAuthMechanism(hello?: Document): MongoCredentials { // If the mechanism is not "default", then it does not need to be resolved if (this.mechanism.match(/DEFAULT/i)) { return new MongoCredentials({ username: this.username, password: this.password, source: this.source, - mechanism: getDefaultAuthMechanism(ismaster), + mechanism: getDefaultAuthMechanism(hello), mechanismProperties: this.mechanismProperties }); } diff --git a/src/cmap/command_monitoring_events.ts b/src/cmap/command_monitoring_events.ts index e3fd504d58..dcf05632e8 100644 --- a/src/cmap/command_monitoring_events.ts +++ b/src/cmap/command_monitoring_events.ts @@ -1,4 +1,5 @@ import type { Document, ObjectId } from '../bson'; +import { LEGACY_HELLO_COMMAND, LEGACY_HELLO_COMMAND_CAMEL_CASE } from '../constants'; import { calculateDurationInMs, deepCopy } from '../utils'; import { GetMore, KillCursor, Msg, WriteProtocolMessageType } from './commands'; import type { Connection } from './connection'; @@ -161,7 +162,7 @@ const SENSITIVE_COMMANDS = new Set([ 'copydb' ]); -const HELLO_COMMANDS = new Set(['hello', 'ismaster', 'isMaster']); +const HELLO_COMMANDS = new Set(['hello', LEGACY_HELLO_COMMAND, LEGACY_HELLO_COMMAND_CAMEL_CASE]); // helper methods const extractCommandName = (commandDoc: Document) => Object.keys(commandDoc)[0]; diff --git a/src/cmap/connect.ts b/src/cmap/connect.ts index 622fd391ec..04e7ed38e7 100644 --- a/src/cmap/connect.ts +++ b/src/cmap/connect.ts @@ -6,6 +6,7 @@ import * as tls from 'tls'; import type { Document } from '../bson'; import { Int32 } from '../bson'; +import { LEGACY_HELLO_COMMAND } from '../constants'; import { AnyError, MongoCompatibilityError, @@ -70,15 +71,15 @@ export function connect(options: ConnectionOptions, callback: Callback= MIN_SUPPORTED_WIRE_VERSION; + hello && + (typeof hello.maxWireVersion === 'number' || hello.maxWireVersion instanceof Int32) && + hello.maxWireVersion >= MIN_SUPPORTED_WIRE_VERSION; const serverVersionLowEnough = - ismaster && - (typeof ismaster.minWireVersion === 'number' || ismaster.minWireVersion instanceof Int32) && - ismaster.minWireVersion <= MAX_SUPPORTED_WIRE_VERSION; + hello && + (typeof hello.minWireVersion === 'number' || hello.minWireVersion instanceof Int32) && + hello.minWireVersion <= MAX_SUPPORTED_WIRE_VERSION; if (serverVersionHighEnough) { if (serverVersionLowEnough) { @@ -86,13 +87,13 @@ function checkSupportedServer(ismaster: Document, options: ConnectionOptions) { } const message = `Server at ${options.hostAddress} reports minimum wire version ${JSON.stringify( - ismaster.minWireVersion + hello.minWireVersion )}, but this version of the Node.js Driver requires at most ${MAX_SUPPORTED_WIRE_VERSION} (MongoDB ${MAX_SUPPORTED_SERVER_VERSION})`; return new MongoCompatibilityError(message); } const message = `Server at ${options.hostAddress} reports maximum wire version ${ - JSON.stringify(ismaster.maxWireVersion) ?? 0 + JSON.stringify(hello.maxWireVersion) ?? 0 }, but this version of the Node.js Driver requires at least ${MIN_SUPPORTED_WIRE_VERSION} (MongoDB ${MIN_SUPPORTED_SERVER_VERSION})`; return new MongoCompatibilityError(message); } @@ -146,9 +147,9 @@ function performInitialHandshake( return; } - if ('isWritablePrimary' in response) { - // Provide pre-hello-style response document. - response.ismaster = response.isWritablePrimary; + if (!('isWritablePrimary' in response)) { + // Provide hello-style response document. + response.isWritablePrimary = response[LEGACY_HELLO_COMMAND]; } if (response.helloOk) { @@ -179,8 +180,8 @@ function performInitialHandshake( // NOTE: This is metadata attached to the connection while porting away from // handshake being done in the `Server` class. Likely, it should be // relocated, or at very least restructured. - conn.ismaster = response; - conn.lastIsMasterMS = new Date().getTime() - start; + conn.hello = response; + conn.lastHelloMS = new Date().getTime() - start; if (!response.arbiterOnly && credentials) { // store the response on auth context @@ -209,6 +210,9 @@ function performInitialHandshake( } export interface HandshakeDocument extends Document { + /** + * @deprecated Use hello instead + */ ismaster?: boolean; hello?: boolean; helloOk?: boolean; @@ -224,7 +228,7 @@ function prepareHandshakeDocument(authContext: AuthContext, callback: Callback { monitorCommands: boolean; closed: boolean; destroyed: boolean; - lastIsMasterMS?: number; + lastHelloMS?: number; serverApi?: ServerApi; helloOk?: boolean; /** @internal */ @@ -201,7 +201,7 @@ export class Connection extends TypedEventEmitter { /** @internal */ [kStream]: Stream; /** @internal */ - [kIsMaster]: Document; + [kHello]: Document; /** @internal */ [kClusterTime]: Document; @@ -240,7 +240,7 @@ export class Connection extends TypedEventEmitter { this[kQueue] = new Map(); this[kMessageStream] = new MessageStream({ ...options, - maxBsonMessageSize: this.ismaster?.maxBsonMessageSize + maxBsonMessageSize: this.hello?.maxBsonMessageSize }); this[kMessageStream].on('message', messageHandler(this)); this[kStream] = stream; @@ -261,21 +261,21 @@ export class Connection extends TypedEventEmitter { return this[kDescription]; } - get ismaster(): Document { - return this[kIsMaster]; + get hello(): Document { + return this[kHello]; } - // the `connect` method stores the result of the handshake ismaster on the connection - set ismaster(response: Document) { + // the `connect` method stores the result of the handshake hello on the connection + set hello(response: Document) { this[kDescription].receiveResponse(response); this[kDescription] = Object.freeze(this[kDescription]); // TODO: remove this, and only use the `StreamDescription` in the future - this[kIsMaster] = response; + this[kHello] = response; } get serviceId(): ObjectId | undefined { - return this.ismaster?.serviceId; + return this.hello?.serviceId; } get loadBalanced(): boolean { @@ -321,7 +321,7 @@ export class Connection extends TypedEventEmitter { if (issue.isTimeout) { op.cb( new MongoNetworkTimeoutError(`connection ${this.id} to ${this.address} timed out`, { - beforeHandshake: this.ismaster == null + beforeHandshake: this.hello == null }) ); } else if (issue.isClose) { diff --git a/src/cmap/wire_protocol/compression.ts b/src/cmap/wire_protocol/compression.ts index 91cab88a05..556f7412f3 100644 --- a/src/cmap/wire_protocol/compression.ts +++ b/src/cmap/wire_protocol/compression.ts @@ -1,5 +1,6 @@ import * as zlib from 'zlib'; +import { LEGACY_HELLO_COMMAND } from '../../constants'; import { PKG_VERSION, Snappy } from '../../deps'; import { MongoDecompressionError, MongoInvalidArgumentError } from '../../error'; import type { Callback } from '../../utils'; @@ -19,7 +20,7 @@ export type Compressor = typeof Compressor[CompressorName]; export type CompressorName = keyof typeof Compressor; export const uncompressibleCommands = new Set([ - 'ismaster', + LEGACY_HELLO_COMMAND, 'saslStart', 'saslContinue', 'getnonce', diff --git a/src/constants.ts b/src/constants.ts index d3d38d3aa7..3b47d81b19 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -120,3 +120,9 @@ export const MONGO_CLIENT_EVENTS = Object.freeze([ * The legacy hello command that was deprecated in MongoDB 5.0. */ export const LEGACY_HELLO_COMMAND = 'ismaster'; + +/** + * @internal + * The legacy hello command that was deprecated in MongoDB 5.0. + */ +export const LEGACY_HELLO_COMMAND_CAMEL_CASE = 'isMaster'; diff --git a/src/operations/add_user.ts b/src/operations/add_user.ts index 545dc31bb0..c9b4f49fa3 100644 --- a/src/operations/add_user.ts +++ b/src/operations/add_user.ts @@ -75,7 +75,7 @@ export class AddUserOperation extends CommandOperation { roles = Array.isArray(options.roles) ? options.roles : [options.roles]; } - const digestPassword = getTopology(db).lastIsMaster().maxWireVersion >= 7; + const digestPassword = getTopology(db).lastHello().maxWireVersion >= 7; let userPassword = password; diff --git a/src/sdam/events.ts b/src/sdam/events.ts index 7afb59425e..7d02d769f7 100644 --- a/src/sdam/events.ts +++ b/src/sdam/events.ts @@ -123,8 +123,8 @@ export class TopologyClosedEvent { } /** - * Emitted when the server monitor’s ismaster command is started - immediately before - * the ismaster command is serialized into raw BSON and written to the socket. + * Emitted when the server monitor’s hello command is started - immediately before + * the hello command is serialized into raw BSON and written to the socket. * * @public * @category Event @@ -140,7 +140,7 @@ export class ServerHeartbeatStartedEvent { } /** - * Emitted when the server monitor’s ismaster succeeds. + * Emitted when the server monitor’s hello succeeds. * @public * @category Event */ @@ -161,7 +161,7 @@ export class ServerHeartbeatSucceededEvent { } /** - * Emitted when the server monitor’s ismaster fails, either with an “ok: 0” or a socket exception. + * Emitted when the server monitor’s hello fails, either with an “ok: 0” or a socket exception. * @public * @category Event */ diff --git a/src/sdam/monitor.ts b/src/sdam/monitor.ts index 8c531a701c..9f7f786b3e 100644 --- a/src/sdam/monitor.ts +++ b/src/sdam/monitor.ts @@ -1,6 +1,7 @@ import { Document, Long } from '../bson'; import { connect } from '../cmap/connect'; import { Connection, ConnectionOptions } from '../cmap/connection'; +import { LEGACY_HELLO_COMMAND } from '../constants'; import { AnyError, MongoNetworkError } from '../error'; import { CancellationToken, TypedEventEmitter } from '../mongo_types'; import type { Callback, InterruptibleAsyncInterval } from '../utils'; @@ -233,7 +234,7 @@ function checkServer(monitor: Monitor, callback: Callback) { const isAwaitable = topologyVersion != null; const cmd = { - [serverApi?.version || helloOk ? 'hello' : 'ismaster']: true, + [serverApi?.version || helloOk ? 'hello' : LEGACY_HELLO_COMMAND]: true, ...(isAwaitable && topologyVersion ? { maxAwaitTimeMS, topologyVersion: makeTopologyVersion(topologyVersion) } : {}) @@ -256,14 +257,15 @@ function checkServer(monitor: Monitor, callback: Callback) { ); } - connection.command(ns('admin.$cmd'), cmd, options, (err, isMaster) => { + connection.command(ns('admin.$cmd'), cmd, options, (err, hello) => { if (err) { failureHandler(err); return; } - if ('isWritablePrimary' in isMaster) { - // Provide pre-hello-style response document. - isMaster.ismaster = isMaster.isWritablePrimary; + + if (!('isWritablePrimary' in hello)) { + // Provide hello-style response document. + hello.isWritablePrimary = hello[LEGACY_HELLO_COMMAND]; } const rttPinger = monitor[kRTTPinger]; @@ -272,12 +274,12 @@ function checkServer(monitor: Monitor, callback: Callback) { monitor.emit( Server.SERVER_HEARTBEAT_SUCCEEDED, - new ServerHeartbeatSucceededEvent(monitor.address, duration, isMaster) + new ServerHeartbeatSucceededEvent(monitor.address, duration, hello) ); // if we are using the streaming protocol then we immediately issue another `started` // event, otherwise the "check" is complete and return to the main monitor loop - if (isAwaitable && isMaster.topologyVersion) { + if (isAwaitable && hello.topologyVersion) { monitor.emit( Server.SERVER_HEARTBEAT_STARTED, new ServerHeartbeatStartedEvent(monitor.address) @@ -287,14 +289,14 @@ function checkServer(monitor: Monitor, callback: Callback) { monitor[kRTTPinger]?.close(); monitor[kRTTPinger] = undefined; - callback(undefined, isMaster); + callback(undefined, hello); } }); return; } - // connecting does an implicit `ismaster` + // connecting does an implicit `hello` connect(monitor.connectOptions, (err, conn) => { if (err) { monitor[kConnection] = undefined; @@ -317,14 +319,10 @@ function checkServer(monitor: Monitor, callback: Callback) { monitor[kConnection] = conn; monitor.emit( Server.SERVER_HEARTBEAT_SUCCEEDED, - new ServerHeartbeatSucceededEvent( - monitor.address, - calculateDurationInMs(start), - conn.ismaster - ) + new ServerHeartbeatSucceededEvent(monitor.address, calculateDurationInMs(start), conn.hello) ); - callback(undefined, conn.ismaster); + callback(undefined, conn.hello); } }); } @@ -340,7 +338,7 @@ function monitorServer(monitor: Monitor) { callback(); } - checkServer(monitor, (err, isMaster) => { + checkServer(monitor, (err, hello) => { if (err) { // otherwise an error occurred on initial discovery, also bail if (monitor[kServer].description.type === ServerType.Unknown) { @@ -350,7 +348,7 @@ function monitorServer(monitor: Monitor) { } // if the check indicates streaming is supported, immediately reschedule monitoring - if (isMaster && isMaster.topologyVersion) { + if (hello && hello.topologyVersion) { setTimeout(() => { if (!isInCloseState(monitor)) { monitor[kMonitorId]?.wake(); @@ -452,7 +450,7 @@ function measureRoundTripTime(rttPinger: RTTPinger, options: RTTPingerOptions) { return; } - connection.command(ns('admin.$cmd'), { ismaster: 1 }, undefined, err => { + connection.command(ns('admin.$cmd'), { [LEGACY_HELLO_COMMAND]: 1 }, undefined, err => { if (err) { rttPinger[kConnection] = undefined; rttPinger[kRoundTripTime] = 0; diff --git a/src/sdam/server.ts b/src/sdam/server.ts index cda973458e..9e9e1c059a 100644 --- a/src/sdam/server.ts +++ b/src/sdam/server.ts @@ -118,7 +118,7 @@ export class Server extends TypedEventEmitter { /** @internal */ s: ServerPrivate; serverApi?: ServerApi; - ismaster?: Document; + hello?: Document; [kMonitor]: Monitor; /** @event */ diff --git a/src/sdam/server_description.ts b/src/sdam/server_description.ts index 8294ea0899..5082c7cb3f 100644 --- a/src/sdam/server_description.ts +++ b/src/sdam/server_description.ts @@ -44,7 +44,7 @@ export interface ServerDescriptionOptions { } /** - * The client's view of a single server, based on the most recent ismaster outcome. + * The client's view of a single server, based on the most recent hello outcome. * * Internal type, not meant to be directly instantiated * @public @@ -81,13 +81,9 @@ export class ServerDescription { * @internal * * @param address - The address of the server - * @param ismaster - An optional ismaster response for this server + * @param hello - An optional hello response for this server */ - constructor( - address: HostAddress | string, - ismaster?: Document, - options?: ServerDescriptionOptions - ) { + constructor(address: HostAddress | string, hello?: Document, options?: ServerDescriptionOptions) { if (typeof address === 'string') { this._hostAddress = new HostAddress(address); this.address = this._hostAddress.toString(); @@ -95,53 +91,53 @@ export class ServerDescription { this._hostAddress = address; this.address = this._hostAddress.toString(); } - this.type = parseServerType(ismaster, options); - this.hosts = ismaster?.hosts?.map((host: string) => host.toLowerCase()) ?? []; - this.passives = ismaster?.passives?.map((host: string) => host.toLowerCase()) ?? []; - this.arbiters = ismaster?.arbiters?.map((host: string) => host.toLowerCase()) ?? []; - this.tags = ismaster?.tags ?? {}; - this.minWireVersion = ismaster?.minWireVersion ?? 0; - this.maxWireVersion = ismaster?.maxWireVersion ?? 0; + this.type = parseServerType(hello, options); + this.hosts = hello?.hosts?.map((host: string) => host.toLowerCase()) ?? []; + this.passives = hello?.passives?.map((host: string) => host.toLowerCase()) ?? []; + this.arbiters = hello?.arbiters?.map((host: string) => host.toLowerCase()) ?? []; + this.tags = hello?.tags ?? {}; + this.minWireVersion = hello?.minWireVersion ?? 0; + this.maxWireVersion = hello?.maxWireVersion ?? 0; this.roundTripTime = options?.roundTripTime ?? -1; this.lastUpdateTime = now(); - this.lastWriteDate = ismaster?.lastWrite?.lastWriteDate ?? 0; + this.lastWriteDate = hello?.lastWrite?.lastWriteDate ?? 0; if (options?.topologyVersion) { this.topologyVersion = options.topologyVersion; - } else if (ismaster?.topologyVersion) { - this.topologyVersion = ismaster.topologyVersion; + } else if (hello?.topologyVersion) { + this.topologyVersion = hello.topologyVersion; } if (options?.error) { this.error = options.error; } - if (ismaster?.primary) { - this.primary = ismaster.primary; + if (hello?.primary) { + this.primary = hello.primary; } - if (ismaster?.me) { - this.me = ismaster.me.toLowerCase(); + if (hello?.me) { + this.me = hello.me.toLowerCase(); } - if (ismaster?.setName) { - this.setName = ismaster.setName; + if (hello?.setName) { + this.setName = hello.setName; } - if (ismaster?.setVersion) { - this.setVersion = ismaster.setVersion; + if (hello?.setVersion) { + this.setVersion = hello.setVersion; } - if (ismaster?.electionId) { - this.electionId = ismaster.electionId; + if (hello?.electionId) { + this.electionId = hello.electionId; } - if (ismaster?.logicalSessionTimeoutMinutes) { - this.logicalSessionTimeoutMinutes = ismaster.logicalSessionTimeoutMinutes; + if (hello?.logicalSessionTimeoutMinutes) { + this.logicalSessionTimeoutMinutes = hello.logicalSessionTimeoutMinutes; } - if (ismaster?.$clusterTime) { - this.$clusterTime = ismaster.$clusterTime; + if (hello?.$clusterTime) { + this.$clusterTime = hello.$clusterTime; } } @@ -210,35 +206,32 @@ export class ServerDescription { } } -// Parses an `ismaster` message and determines the server type -export function parseServerType( - ismaster?: Document, - options?: ServerDescriptionOptions -): ServerType { +// Parses a `hello` message and determines the server type +export function parseServerType(hello?: Document, options?: ServerDescriptionOptions): ServerType { if (options?.loadBalanced) { return ServerType.LoadBalancer; } - if (!ismaster || !ismaster.ok) { + if (!hello || !hello.ok) { return ServerType.Unknown; } - if (ismaster.isreplicaset) { + if (hello.isreplicaset) { return ServerType.RSGhost; } - if (ismaster.msg && ismaster.msg === 'isdbgrid') { + if (hello.msg && hello.msg === 'isdbgrid') { return ServerType.Mongos; } - if (ismaster.setName) { - if (ismaster.hidden) { + if (hello.setName) { + if (hello.hidden) { return ServerType.RSOther; - } else if (ismaster.ismaster || ismaster.isWritablePrimary) { + } else if (hello.isWritablePrimary) { return ServerType.RSPrimary; - } else if (ismaster.secondary) { + } else if (hello.secondary) { return ServerType.RSSecondary; - } else if (ismaster.arbiterOnly) { + } else if (hello.arbiterOnly) { return ServerType.RSArbiter; } else { return ServerType.RSOther; diff --git a/src/sdam/topology.ts b/src/sdam/topology.ts index 1159ea602d..4d9a067eaa 100644 --- a/src/sdam/topology.ts +++ b/src/sdam/topology.ts @@ -198,7 +198,7 @@ export class Topology extends TypedEventEmitter { /** @internal */ [kWaitQueue]: Denque; /** @internal */ - ismaster?: Document; + hello?: Document; /** @internal */ _type?: string; @@ -403,7 +403,7 @@ export class Topology extends TypedEventEmitter { } get capabilities(): ServerCapabilities { - return new ServerCapabilities(this.lastIsMaster()); + return new ServerCapabilities(this.lastHello()); } /** Initiate server connect */ @@ -791,10 +791,10 @@ export class Topology extends TypedEventEmitter { emitWarning('`unref` is a noop and will be removed in the next major version'); } - // NOTE: There are many places in code where we explicitly check the last isMaster + // NOTE: There are many places in code where we explicitly check the last hello // to do feature support detection. This should be done any other way, but for - // now we will just return the first isMaster seen, which should suffice. - lastIsMaster(): Document { + // now we will just return the first hello seen, which should suffice. + lastHello(): Document { const serverDescriptions = Array.from(this.description.servers.values()); if (serverDescriptions.length === 0) return {}; const sd = serverDescriptions.filter( @@ -1066,9 +1066,9 @@ export class ServerCapabilities { maxWireVersion: number; minWireVersion: number; - constructor(ismaster: Document) { - this.minWireVersion = ismaster.minWireVersion || 0; - this.maxWireVersion = ismaster.maxWireVersion || 0; + constructor(hello: Document) { + this.minWireVersion = hello.minWireVersion || 0; + this.maxWireVersion = hello.maxWireVersion || 0; } get hasAggregationCursor(): boolean { diff --git a/src/sdam/topology_description.ts b/src/sdam/topology_description.ts index 685a658a60..a14df1a555 100644 --- a/src/sdam/topology_description.ts +++ b/src/sdam/topology_description.ts @@ -106,7 +106,7 @@ export class TopologyDescription { } } - // Whenever a client updates the TopologyDescription from an ismaster response, it MUST set + // Whenever a client updates the TopologyDescription from a hello response, it MUST set // TopologyDescription.logicalSessionTimeoutMinutes to the smallest logicalSessionTimeoutMinutes // value among ServerDescriptions of all data-bearing server types. If any have a null // logicalSessionTimeoutMinutes, then TopologyDescription.logicalSessionTimeoutMinutes MUST be diff --git a/src/utils.ts b/src/utils.ts index e4f8898fc8..ac787252f6 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -656,14 +656,14 @@ export function maxWireVersion(topologyOrServer?: Connection | Topology | Server // application that a feature is avaiable that is actually not. return MAX_SUPPORTED_WIRE_VERSION; } - if (topologyOrServer.ismaster) { - return topologyOrServer.ismaster.maxWireVersion; + if (topologyOrServer.hello) { + return topologyOrServer.hello.maxWireVersion; } - if ('lastIsMaster' in topologyOrServer && typeof topologyOrServer.lastIsMaster === 'function') { - const lastIsMaster = topologyOrServer.lastIsMaster(); - if (lastIsMaster) { - return lastIsMaster.maxWireVersion; + if ('lastHello' in topologyOrServer && typeof topologyOrServer.lastHello === 'function') { + const lastHello = topologyOrServer.lastHello(); + if (lastHello) { + return lastHello.maxWireVersion; } } diff --git a/test/functional/unit-sdam/server_selection/spec.test.js b/test/functional/unit-sdam/server_selection/spec.test.js index b879bed9e4..5bab601bfe 100644 --- a/test/functional/unit-sdam/server_selection/spec.test.js +++ b/test/functional/unit-sdam/server_selection/spec.test.js @@ -8,7 +8,6 @@ const { ServerDescription } = require('../../../../src/sdam/server_description') const { ReadPreference } = require('../../../../src/read_preference'); const { MongoServerSelectionError } = require('../../../../src/error'); const ServerSelectors = require('../../../../src/sdam/server_selection'); -const { LEGACY_HELLO_COMMAND } = require('../../../../src/constants'); const { EJSON } = require('bson'); @@ -168,7 +167,7 @@ function serverDescriptionFromDefinition(definition, hosts) { } if (serverType === ServerType.RSPrimary) { - fakeHello[LEGACY_HELLO_COMMAND] = true; + fakeHello.isWritablePrimary = true; } else if (serverType === ServerType.RSSecondary) { fakeHello.secondary = true; } else if (serverType === ServerType.Mongos) { diff --git a/test/functional/unit-sdam/topology.test.js b/test/functional/unit-sdam/topology.test.js index 29ef908fc1..b113eb3a81 100644 --- a/test/functional/unit-sdam/topology.test.js +++ b/test/functional/unit-sdam/topology.test.js @@ -12,6 +12,7 @@ const { TopologyDescription } = require('../../../src/sdam/topology_description' const { TopologyType } = require('../../../src/sdam/common'); const { SrvPoller, SrvPollingEvent } = require('../../../src/sdam/srv_polling'); const { getSymbolFrom } = require('../../tools/utils'); +const { LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE } = require('../../../src/error'); describe('Topology (unit)', function () { describe('client metadata', function () { @@ -227,7 +228,7 @@ describe('Topology (unit)', function () { if (isHello(doc)) { request.reply(Object.assign({}, mock.HELLO, { maxWireVersion: 9 })); } else if (doc.insert) { - request.reply({ ok: 0, message: 'not master' }); + request.reply({ ok: 0, message: LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE }); } else { request.reply({ ok: 1 }); } diff --git a/test/manual/socks5.test.ts b/test/manual/socks5.test.ts index 429d6f90d2..0a1d51b69f 100644 --- a/test/manual/socks5.test.ts +++ b/test/manual/socks5.test.ts @@ -2,6 +2,7 @@ import { expect } from 'chai'; import ConnectionString from 'mongodb-connection-string-url'; import { MongoClient } from '../../src'; +import { LEGACY_HELLO_COMMAND } from '../../src/constants'; import { MongoParseError } from '../../src/error'; /** @@ -271,7 +272,7 @@ describe('Socks5 Connectivity', function () { client.on('commandSucceeded', ev => seenCommandAddresses.add(ev.address)); await client.connect(); - await client.db('admin').command({ ismaster: 1 }); + await client.db('admin').command({ [LEGACY_HELLO_COMMAND]: 1 }); await client.close(); expect([...seenCommandAddresses]).to.deep.equal(singleConnectionString.hosts); }); diff --git a/test/unit/_MISC_optional_require.test.js b/test/unit/_MISC_optional_require.test.js index 3060b884e6..d10d020da8 100644 --- a/test/unit/_MISC_optional_require.test.js +++ b/test/unit/_MISC_optional_require.test.js @@ -9,7 +9,6 @@ const { GSSAPI } = require('../../src/cmap/auth/gssapi'); const { AuthContext } = require('../../src/cmap/auth/auth_provider'); const { MongoDBAWS } = require('../../src/cmap/auth/mongodb_aws'); const { HostAddress } = require('../../src/utils'); -const { LEGACY_HELLO_COMMAND } = require('../../src/constants'); function moduleExistsSync(moduleName) { return existsSync(resolve(__dirname, `../../node_modules/${moduleName}`)); @@ -67,13 +66,10 @@ describe('optionalRequire', function () { return this.skip(); } const mdbAWS = new MongoDBAWS(); - mdbAWS.auth( - new AuthContext({ [LEGACY_HELLO_COMMAND]: { maxWireVersion: 9 } }, true, null), - error => { - expect(error).to.exist; - expect(error.message).includes('not found'); - } - ); + mdbAWS.auth(new AuthContext({ hello: { maxWireVersion: 9 } }, true, null), error => { + expect(error).to.exist; + expect(error.message).includes('not found'); + }); }); } }); diff --git a/test/unit/cmap/connection.test.js b/test/unit/cmap/connection.test.js index 7eff1a7a49..4b2a1fa09e 100644 --- a/test/unit/cmap/connection.test.js +++ b/test/unit/cmap/connection.test.js @@ -7,7 +7,6 @@ const { expect } = require('chai'); const { Socket } = require('net'); const { ns, isHello } = require('../../../src/utils'); const { getSymbolFrom } = require('../../tools/utils'); -const { LEGACY_HELLO_COMMAND } = require('../../../src/constants'); describe('Connection - unit/cmap', function () { let server; @@ -78,7 +77,7 @@ describe('Connection - unit/cmap', function () { connect(options, (err, conn) => { expect(err).to.be.a('undefined'); expect(conn).to.be.instanceOf(Connection); - expect(conn).to.have.property(LEGACY_HELLO_COMMAND).that.is.a('object'); + expect(conn).to.have.property('hello').that.is.a('object'); conn.command(ns('$admin.cmd'), { ping: 1 }, { socketTimeoutMS: 50 }, err => { const beforeHandshakeSymbol = getSymbolFrom(err, 'beforeHandshake', false);