Skip to content

Commit

Permalink
fix(NODE-3792): remove offensive language throughout the codebase (#3091
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ljhaywar committed Jan 12, 2022
1 parent c3256c4 commit 8e2b0cc
Show file tree
Hide file tree
Showing 21 changed files with 140 additions and 142 deletions.
9 changes: 4 additions & 5 deletions src/bulk/common.ts
Expand Up @@ -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
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions src/change_stream.ts
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions src/cmap/auth/mongo_credentials.ts
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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
});
}
Expand Down
3 changes: 2 additions & 1 deletion 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';
Expand Down Expand Up @@ -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];
Expand Down
34 changes: 19 additions & 15 deletions src/cmap/connect.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -70,29 +71,29 @@ export function connect(options: ConnectionOptions, callback: Callback<Connectio
});
}

function checkSupportedServer(ismaster: Document, options: ConnectionOptions) {
function checkSupportedServer(hello: Document, options: ConnectionOptions) {
const serverVersionHighEnough =
ismaster &&
(typeof ismaster.maxWireVersion === 'number' || ismaster.maxWireVersion instanceof Int32) &&
ismaster.maxWireVersion >= 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) {
return null;
}

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);
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -209,6 +210,9 @@ function performInitialHandshake(
}

export interface HandshakeDocument extends Document {
/**
* @deprecated Use hello instead
*/
ismaster?: boolean;
hello?: boolean;
helloOk?: boolean;
Expand All @@ -224,7 +228,7 @@ function prepareHandshakeDocument(authContext: AuthContext, callback: Callback<H
const { serverApi } = authContext.connection;

const handshakeDoc: HandshakeDocument = {
[serverApi?.version ? 'hello' : 'ismaster']: true,
[serverApi?.version ? 'hello' : LEGACY_HELLO_COMMAND]: true,
helloOk: true,
client: options.metadata || makeClientMetadata(options),
compression: compressors,
Expand Down
22 changes: 11 additions & 11 deletions src/cmap/connection.ts
Expand Up @@ -70,7 +70,7 @@ const kClusterTime = Symbol('clusterTime');
/** @internal */
const kDescription = Symbol('description');
/** @internal */
const kIsMaster = Symbol('ismaster');
const kHello = Symbol('hello');
/** @internal */
const kAutoEncrypter = Symbol('autoEncrypter');
/** @internal */
Expand Down Expand Up @@ -185,7 +185,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
monitorCommands: boolean;
closed: boolean;
destroyed: boolean;
lastIsMasterMS?: number;
lastHelloMS?: number;
serverApi?: ServerApi;
helloOk?: boolean;
/** @internal */
Expand All @@ -201,7 +201,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
/** @internal */
[kStream]: Stream;
/** @internal */
[kIsMaster]: Document;
[kHello]: Document;
/** @internal */
[kClusterTime]: Document;

Expand Down Expand Up @@ -240,7 +240,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
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;
Expand All @@ -261,21 +261,21 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
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 {
Expand Down Expand Up @@ -321,7 +321,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
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) {
Expand Down
3 changes: 2 additions & 1 deletion 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';
Expand All @@ -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',
Expand Down
6 changes: 6 additions & 0 deletions src/constants.ts
Expand Up @@ -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';
2 changes: 1 addition & 1 deletion src/operations/add_user.ts
Expand Up @@ -75,7 +75,7 @@ export class AddUserOperation extends CommandOperation<Document> {
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;

Expand Down
8 changes: 4 additions & 4 deletions src/sdam/events.ts
Expand Up @@ -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
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand Down

0 comments on commit 8e2b0cc

Please sign in to comment.