@@ -148,14 +148,13 @@ type Operation struct {
148
148
149
149
// RetryMode specifies how to retry. There are three modes that enable retry: RetryOnce,
150
150
// RetryOncePerCommand, and RetryContext. For more information about what these modes do, please
151
- // refer to their definitions. Both RetryMode and RetryType must be set for retryability to be
152
- // enabled.
151
+ // refer to their definitions. Both RetryMode and Type must be set for retryability to be enabled.
153
152
RetryMode * RetryMode
154
153
155
- // RetryType specifies the kinds of operations that can be retried . There is only one mode that
156
- // enables retry: RetryWrites. For more information about what this mode does, please refer to
157
- // it's definition. Both RetryType and RetryMode must be set for retryability to be enabled.
158
- RetryType RetryType
154
+ // Type specifies the kind of operation this is . There is only one mode that enables retry: Write.
155
+ // For more information about what this mode does, please refer to it's definition. Both Type and
156
+ // RetryMode must be set for retryability to be enabled.
157
+ Type Type
159
158
160
159
// Batches contains the documents that are split when executing a write command that potentially
161
160
// has more documents than can fit in a single command. This should only be specified for
@@ -264,7 +263,7 @@ func (op Operation) Execute(ctx context.Context, scratch []byte) error {
264
263
var retries int
265
264
// TODO(GODRIVER-617): Add support for retryable reads.
266
265
retryable := op .retryable (desc .Server )
267
- if retryable == RetryWrite && op .Client != nil && op .RetryMode != nil {
266
+ if retryable == Write && op .Client != nil && op .RetryMode != nil {
268
267
op .Client .RetryWrite = false
269
268
if * op .RetryMode > RetryNone {
270
269
op .Client .RetryWrite = true
@@ -350,7 +349,7 @@ func (op Operation) Execute(ctx context.Context, scratch []byte) error {
350
349
351
350
switch tt := err .(type ) {
352
351
case WriteCommandError :
353
- if retryable == RetryWrite && tt .Retryable () && retries != 0 {
352
+ if retryable == Write && tt .Retryable () && retries != 0 {
354
353
retries --
355
354
original , err = err , nil
356
355
conn .Close () // Avoid leaking the connection.
@@ -359,7 +358,7 @@ func (op Operation) Execute(ctx context.Context, scratch []byte) error {
359
358
return original
360
359
}
361
360
conn , err = srvr .Connection (ctx )
362
- if err != nil || conn == nil || op .retryable (conn .Description ()) != RetryWrite {
361
+ if err != nil || conn == nil || op .retryable (conn .Description ()) != Write {
363
362
if conn != nil {
364
363
conn .Close ()
365
364
}
@@ -396,7 +395,7 @@ func (op Operation) Execute(ctx context.Context, scratch []byte) error {
396
395
if tt .HasErrorLabel (TransientTransactionError ) || tt .HasErrorLabel (UnknownTransactionCommitResult ) {
397
396
op .Client .ClearPinnedServer ()
398
397
}
399
- if retryable == RetryWrite && tt .Retryable () && retries != 0 {
398
+ if retryable == Write && tt .Retryable () && retries != 0 {
400
399
retries --
401
400
original , err = err , nil
402
401
conn .Close () // Avoid leaking the connection.
@@ -405,7 +404,7 @@ func (op Operation) Execute(ctx context.Context, scratch []byte) error {
405
404
return original
406
405
}
407
406
conn , err = srvr .Connection (ctx )
408
- if err != nil || conn == nil || op .retryable (conn .Description ()) != RetryWrite {
407
+ if err != nil || conn == nil || op .retryable (conn .Description ()) != Write {
409
408
if conn != nil {
410
409
conn .Close ()
411
410
}
@@ -436,7 +435,7 @@ func (op Operation) Execute(ctx context.Context, scratch []byte) error {
436
435
}
437
436
438
437
if batching && len (op .Batches .Documents ) > 0 {
439
- if retryable == RetryWrite && op .Client != nil && op .RetryMode != nil {
438
+ if retryable == Write && op .Client != nil && op .RetryMode != nil {
440
439
if * op .RetryMode > RetryNone {
441
440
op .Client .IncrementTxnNumber ()
442
441
}
@@ -457,20 +456,20 @@ func (op Operation) Execute(ctx context.Context, scratch []byte) error {
457
456
458
457
// Retryable writes are supported if the server supports sessions, the operation is not
459
458
// within a transaction, and the write is acknowledged
460
- func (op Operation ) retryable (desc description.Server ) RetryType {
461
- switch op .RetryType {
462
- case RetryWrite :
459
+ func (op Operation ) retryable (desc description.Server ) Type {
460
+ switch op .Type {
461
+ case Write :
463
462
if op .Client != nil && (op .Client .Committing || op .Client .Aborting ) {
464
- return RetryWrite
463
+ return Write
465
464
}
466
465
if op .Deployment .SupportsRetry () &&
467
466
description .SessionsSupported (desc .WireVersion ) &&
468
467
op .Client != nil && ! (op .Client .TransactionInProgress () || op .Client .TransactionStarting ()) &&
469
468
writeconcern .AckWrite (op .WriteConcern ) {
470
- return RetryWrite
469
+ return Write
471
470
}
472
471
}
473
- return RetryType (0 )
472
+ return Type (0 )
474
473
}
475
474
476
475
// roundTrip writes a wiremessage to the connection and then reads a wiremessage. The wm parameter
@@ -811,7 +810,7 @@ func (op Operation) addSession(dst []byte, desc description.SelectedServer) ([]b
811
810
dst = bsoncore .AppendDocumentElement (dst , "lsid" , lsid )
812
811
813
812
var addedTxnNumber bool
814
- if op .RetryType == RetryWrite && client != nil && client .RetryWrite {
813
+ if op .Type == Write && client != nil && client .RetryWrite {
815
814
addedTxnNumber = true
816
815
dst = bsoncore .AppendInt64Element (dst , "txnNumber" , op .Client .TxnNumber )
817
816
}
@@ -896,11 +895,6 @@ func (op Operation) updateOperationTime(response bsoncore.Document) {
896
895
}
897
896
898
897
func (op Operation ) getReadPrefBasedOnTransaction () (* readpref.ReadPref , error ) {
899
- // don't validate read preference for write commands
900
- if op .RetryType == RetryWrite {
901
- return op .ReadPreference , nil
902
- }
903
-
904
898
if op .Client != nil && op .Client .TransactionRunning () {
905
899
// Transaction's read preference always takes priority
906
900
rp := op .Client .CurrentRp
@@ -915,7 +909,7 @@ func (op Operation) getReadPrefBasedOnTransaction() (*readpref.ReadPref, error)
915
909
}
916
910
917
911
func (op Operation ) createReadPref (serverKind description.ServerKind , topologyKind description.TopologyKind , isOpQuery bool ) (bsoncore.Document , error ) {
918
- if serverKind == description .Standalone || (isOpQuery && serverKind != description .Mongos ) {
912
+ if serverKind == description .Standalone || (isOpQuery && serverKind != description .Mongos ) || op . Type == Write {
919
913
// Don't send read preference for non-mongos when using OP_QUERY or for all standalones
920
914
return nil , nil
921
915
}
0 commit comments