Skip to content

Commit

Permalink
fix: "willRetryWrites"
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Mar 12, 2022
1 parent ea3b615 commit a3dc79f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/cmap/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export interface CommandOptions extends BSONSerializeOptions {
omitReadPreference?: boolean;

// FIXME: NODE-2802
willRetryWrite?: boolean;
willRetryWrites?: boolean;

// FIXME: NODE-2781
writeConcern?: WriteConcernOptions | WriteConcern | W;
Expand Down
8 changes: 4 additions & 4 deletions src/operations/execute_operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ function executeWithServerSelection(
supportsRetryableReads(server) &&
operation.canRetryRead;

const willRetryWrite =
const willRetryWrites =
topology.s.options.retryWrites === true &&
!inTransaction &&
supportsRetryableWrites(server) &&
Expand All @@ -268,9 +268,9 @@ function executeWithServerSelection(
const hasReadAspect = operation.hasAspect(Aspect.READ_OPERATION);
const hasWriteAspect = operation.hasAspect(Aspect.WRITE_OPERATION);

if ((hasReadAspect && willRetryRead) || (hasWriteAspect && willRetryWrite)) {
if (hasWriteAspect && willRetryWrite) {
operation.options.willRetryWrite = true;
if ((hasReadAspect && willRetryRead) || (hasWriteAspect && willRetryWrites)) {
if (hasWriteAspect && willRetryWrites) {
operation.options.willRetryWrites = true;
session.incrementTransactionNumber();
}

Expand Down
2 changes: 1 addition & 1 deletion src/operations/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export abstract class AbstractOperation<TResult = any> {
bsonOptions?: BSONSerializeOptions;

// TODO: Each operation defines its own options, there should be better typing here
options: Document;
options: OperationOptions;

[kSession]: ClientSession;

Expand Down
8 changes: 4 additions & 4 deletions src/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ export class ServerSessionPool {
export function applySession(
session: ClientSession,
command: Document,
options?: CommandOptions
options: CommandOptions
): MongoDriverError | undefined {
// TODO: merge this with `assertAlive`, did not want to throw a try/catch here
if (session.hasEnded) {
Expand All @@ -963,10 +963,10 @@ export function applySession(
command.lsid = serverSession.id;

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

if (serverSession.txnNumber && (isRetryableWrite || inTransaction)) {
if (isRetryableWrite || inTransaction) {
command.txnNumber = Long.fromNumber(serverSession.txnNumber);
}

Expand Down

0 comments on commit a3dc79f

Please sign in to comment.