Skip to content

Commit

Permalink
remove stray only
Browse files Browse the repository at this point in the history
clear up logic

lint fix

clean up

lint fix 2
  • Loading branch information
aditi-khare-mongoDB committed Jul 9, 2024
1 parent 440bac7 commit ad5b150
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/cmap/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
MIN_SUPPORTED_SERVER_VERSION,
MIN_SUPPORTED_WIRE_VERSION
} from './wire_protocol/constants';
import { isSharded } from './wire_protocol/shared';

/** @public */
export type Stream = Socket | TLSSocket;
Expand Down Expand Up @@ -165,7 +164,7 @@ export async function performInitialHandshake(
} catch (error) {
if (error instanceof MongoError) {
error.addErrorLabel(MongoErrorLabel.HandshakeError);
if (needsRetryableWriteLabel(error, response.maxWireVersion, isSharded(conn))) {
if (needsRetryableWriteLabel(error, response.maxWireVersion, conn.description.type)) {
error.addErrorLabel(MongoErrorLabel.RetryableWriteError);
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Document } from './bson';
import type { ServerType } from './sdam/common';
import type { TopologyVersion } from './sdam/server_description';
import type { TopologyDescription } from './sdam/topology_description';

Expand Down Expand Up @@ -1220,7 +1221,7 @@ const RETRYABLE_WRITE_ERROR_CODES = RETRYABLE_READ_ERROR_CODES;
export function needsRetryableWriteLabel(
error: Error,
maxWireVersion: number,
isSharded: boolean
serverType: ServerType
): boolean {
// pre-4.4 server, then the driver adds an error label for every valid case
// execute operation will only inspect the label, code/message logic is handled here
Expand All @@ -1241,13 +1242,13 @@ export function needsRetryableWriteLabel(
}

if (error instanceof MongoWriteConcernError) {
return isSharded && maxWireVersion < 9
return serverType === 'Mongos' && maxWireVersion < 9
? false
: RETRYABLE_WRITE_ERROR_CODES.has(error.result?.code ?? error.code ?? 0);
: RETRYABLE_WRITE_ERROR_CODES.has(error.result?.code ?? Number(error.code) ?? 0);
}

if (error instanceof MongoError && typeof error.code === 'number') {
return RETRYABLE_WRITE_ERROR_CODES.has(error.code);
return RETRYABLE_WRITE_ERROR_CODES.has(Number(error.code));
}

const isNotWritablePrimaryError = LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE.test(error.message);
Expand Down
3 changes: 1 addition & 2 deletions src/sdam/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
} from '../cmap/connection_pool';
import { PoolClearedError } from '../cmap/errors';
import { type MongoDBResponseConstructor } from '../cmap/wire_protocol/responses';
import { isSharded } from '../cmap/wire_protocol/shared';
import {
APM_EVENTS,
CLOSED,
Expand Down Expand Up @@ -454,7 +453,7 @@ export class Server extends TypedEventEmitter<ServerEvents> {
} else {
if (
(isRetryableWritesEnabled(this.topology) || isTransactionCommand(cmd)) &&
needsRetryableWriteLabel(error, maxWireVersion(this), isSharded(this)) &&
needsRetryableWriteLabel(error, maxWireVersion(this), this.description.type) &&
!inActiveTransaction(session, cmd)
) {
error.addErrorLabel(MongoErrorLabel.RetryableWriteError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface RetryableWriteTestContext {
failPointName?: any;
}

describe.only('Legacy Retryable Writes Specs', function () {
describe('Legacy Retryable Writes Specs', function () {
let ctx: RetryableWriteTestContext = {};

const retryableWrites = loadSpecTests('retryable-writes', 'legacy');
Expand Down Expand Up @@ -229,6 +229,6 @@ async function turnOffFailPoint(client, name) {
});
}

describe.only('Retryable Writes (unified)', function () {
describe('Retryable Writes (unified)', function () {
runUnifiedSuite(loadSpecTests(path.join('retryable-writes', 'unified')));
});

0 comments on commit ad5b150

Please sign in to comment.