Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NODE-3380): perform retryable write checks against server #2861

Merged
merged 3 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/core/sdam/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ class Server extends EventEmitter {
return this.s.description;
}

get supportsRetryableWrites() {
return supportsRetryableWrites(this);
}

get name() {
return this.s.description.address;
}
Expand Down
38 changes: 24 additions & 14 deletions lib/core/sdam/topology.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const events = require('./events');
const Server = require('./server').Server;
const relayEvents = require('../utils').relayEvents;
const ReadPreference = require('../topologies/read_preference');
const isRetryableWritesSupported = require('../topologies/shared').isRetryableWritesSupported;
const CoreCursor = require('../cursor').CoreCursor;
const deprecate = require('util').deprecate;
const BSON = require('../connection/utils').retrieveBSON();
Expand Down Expand Up @@ -669,12 +668,17 @@ class Topology extends EventEmitter {
return;
}

const notAlreadyRetrying = !options.retrying;
const retryWrites = !!options.retryWrites;
const hasSession = !!options.session;
const supportsRetryableWrites = server.supportsRetryableWrites;
const notInTransaction = !options.session.inTransaction();
const willRetryWrite =
!options.retrying &&
!!options.retryWrites &&
options.session &&
isRetryableWritesSupported(this) &&
!options.session.inTransaction() &&
notAlreadyRetrying &&
retryWrites &&
hasSession &&
supportsRetryableWrites &&
notInTransaction &&
isWriteCommand(cmd);

const cb = (err, result) => {
Expand Down Expand Up @@ -925,20 +929,26 @@ function executeWriteOperation(args, options, callback) {
const ns = args.ns;
const ops = args.ops;

const willRetryWrite =
!args.retrying &&
!!options.retryWrites &&
options.session &&
isRetryableWritesSupported(topology) &&
!options.session.inTransaction() &&
options.explain === undefined;

topology.selectServer(writableServerSelector(), options, (err, server) => {
if (err) {
callback(err, null);
return;
}

const notAlreadyRetrying = !args.retrying;
const retryWrites = !!options.retryWrites;
const hasSession = !!options.session;
const supportsRetryableWrites = server.supportsRetryableWrites;
const notInTransaction = !options.session.inTransaction();
const notExplaining = options.explain === undefined;
const willRetryWrite =
nbbeeken marked this conversation as resolved.
Show resolved Hide resolved
notAlreadyRetrying &&
retryWrites &&
hasSession &&
supportsRetryableWrites &&
notInTransaction &&
notExplaining;

const handler = (err, result) => {
if (!err) return callback(null, result);
if (!shouldRetryOperation(err)) {
Expand Down