Skip to content

Commit a3dc79f

Browse files
committed
fix: "willRetryWrites"
1 parent ea3b615 commit a3dc79f

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

src/cmap/connection.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export interface CommandOptions extends BSONSerializeOptions {
110110
omitReadPreference?: boolean;
111111

112112
// FIXME: NODE-2802
113-
willRetryWrite?: boolean;
113+
willRetryWrites?: boolean;
114114

115115
// FIXME: NODE-2781
116116
writeConcern?: WriteConcernOptions | WriteConcern | W;

src/operations/execute_operation.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ function executeWithServerSelection(
259259
supportsRetryableReads(server) &&
260260
operation.canRetryRead;
261261

262-
const willRetryWrite =
262+
const willRetryWrites =
263263
topology.s.options.retryWrites === true &&
264264
!inTransaction &&
265265
supportsRetryableWrites(server) &&
@@ -268,9 +268,9 @@ function executeWithServerSelection(
268268
const hasReadAspect = operation.hasAspect(Aspect.READ_OPERATION);
269269
const hasWriteAspect = operation.hasAspect(Aspect.WRITE_OPERATION);
270270

271-
if ((hasReadAspect && willRetryRead) || (hasWriteAspect && willRetryWrite)) {
272-
if (hasWriteAspect && willRetryWrite) {
273-
operation.options.willRetryWrite = true;
271+
if ((hasReadAspect && willRetryRead) || (hasWriteAspect && willRetryWrites)) {
272+
if (hasWriteAspect && willRetryWrites) {
273+
operation.options.willRetryWrites = true;
274274
session.incrementTransactionNumber();
275275
}
276276

src/operations/operation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export abstract class AbstractOperation<TResult = any> {
5757
bsonOptions?: BSONSerializeOptions;
5858

5959
// TODO: Each operation defines its own options, there should be better typing here
60-
options: Document;
60+
options: OperationOptions;
6161

6262
[kSession]: ClientSession;
6363

src/sessions.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ export class ServerSessionPool {
937937
export function applySession(
938938
session: ClientSession,
939939
command: Document,
940-
options?: CommandOptions
940+
options: CommandOptions
941941
): MongoDriverError | undefined {
942942
// TODO: merge this with `assertAlive`, did not want to throw a try/catch here
943943
if (session.hasEnded) {
@@ -963,10 +963,10 @@ export function applySession(
963963
command.lsid = serverSession.id;
964964

965965
// first apply non-transaction-specific sessions data
966-
const inTransaction = session.inTransaction() || isTransactionCommand(command);
967-
const isRetryableWrite = options?.willRetryWrite || false;
966+
const inTransaction = session.inTransaction() ?? isTransactionCommand(command);
967+
const isRetryableWrite = options.willRetryWrites ?? false;
968968

969-
if (serverSession.txnNumber && (isRetryableWrite || inTransaction)) {
969+
if (isRetryableWrite || inTransaction) {
970970
command.txnNumber = Long.fromNumber(serverSession.txnNumber);
971971
}
972972

0 commit comments

Comments
 (0)