Skip to content

Commit 4cadad6

Browse files
committed
Improve CSOT API discoverability and document its effect on retrying
- Add timeout hierarchy list to getTimeout/withTimeout Javadoc across all driver modules (sync, reactive-streams, Kotlin sync/coroutine, Scala) to improve discoverability - Document the effect of operation timeout on retrying in retryWrites/retryReads and timeout methods on MongoClientSettings - Add cross-references between paired getter/setter methods via @see tags JAVA-6122
1 parent 9ae84c9 commit 4cadad6

16 files changed

Lines changed: 483 additions & 7 deletions

File tree

driver-core/src/main/com/mongodb/MongoClientSettings.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,13 @@ public Builder writeConcern(final WriteConcern writeConcern) {
432432
*
433433
* <p>Starting with the 3.11.0 release, the default value is true</p>
434434
*
435+
* <p>If a {@linkplain #timeout(long, TimeUnit) timeout} is set, the driver may retry
436+
* multiple times until the timeout expires. Otherwise, at most one retry attempt is made.
437+
*
435438
* @param retryWrites sets if writes should be retried if they fail due to a network error.
436439
* @return this
437440
* @see #getRetryWrites()
441+
* @see #timeout(long, TimeUnit)
438442
* @mongodb.server.release 3.6
439443
*/
440444
public Builder retryWrites(final boolean retryWrites) {
@@ -445,9 +449,13 @@ public Builder retryWrites(final boolean retryWrites) {
445449
/**
446450
* Sets whether reads should be retried if they fail due to a network error.
447451
*
452+
* <p>If a {@linkplain #timeout(long, TimeUnit) timeout} is set, the driver may retry
453+
* multiple times until the timeout expires. Otherwise, at most one retry attempt is made.
454+
*
448455
* @param retryReads sets if reads should be retried if they fail due to a network error.
449456
* @return this
450457
* @see #getRetryReads()
458+
* @see #timeout(long, TimeUnit)
451459
* @since 3.11
452460
* @mongodb.server.release 3.6
453461
*/
@@ -716,11 +724,25 @@ public Builder inetAddressResolver(@Nullable final InetAddressResolver inetAddre
716724
* <li>{@code > 0} The time limit to use for the full execution of an operation.</li>
717725
* </ul>
718726
*
727+
* <p>The timeout can be set at the following levels (ordered by lowest precedence):
728+
* <ul>
729+
* <li>{@link #timeout(long, TimeUnit) MongoClientSettings} (current)</li>
730+
* <li>{@code MongoCluster.withTimeout}</li>
731+
* <li>{@code MongoDatabase.withTimeout}</li>
732+
* <li>{@code MongoCollection.withTimeout}</li>
733+
* <li>{@link ClientSessionOptions.Builder#defaultTimeout(long, TimeUnit) ClientSessionOptions}</li>
734+
* <li>{@link TransactionOptions.Builder#timeout(Long, TimeUnit) TransactionOptions}</li>
735+
* </ul>
736+
* If not set at a given level, the timeout is inherited from the level above.
737+
*
738+
* <p>If {@linkplain #retryWrites(boolean) write} or {@linkplain #retryReads(boolean) read} retries are enabled,
739+
* the driver may retry multiple times until the timeout expires.
740+
*
719741
* @param timeout the timeout
720742
* @param timeUnit the time unit
721743
* @return this
722744
* @since 5.2
723-
* @see #getTimeout
745+
* @see #getTimeout(TimeUnit)
724746
*/
725747
@Alpha(Reason.CLIENT)
726748
public Builder timeout(final long timeout, final TimeUnit timeUnit) {
@@ -789,7 +811,11 @@ public WriteConcern getWriteConcern() {
789811
*
790812
* <p>Starting with the 3.11.0 release, the default value is true</p>
791813
*
814+
* <p>If a {@linkplain #getTimeout(TimeUnit) timeout} is set, the driver may retry
815+
* multiple times until the timeout expires. Otherwise, at most one retry attempt is made.
816+
*
792817
* @return the retryWrites value
818+
* @see #getTimeout(TimeUnit)
793819
* @mongodb.server.release 3.6
794820
*/
795821
public boolean getRetryWrites() {
@@ -799,7 +825,11 @@ public boolean getRetryWrites() {
799825
/**
800826
* Returns true if reads should be retried if they fail due to a network error or other retryable error. The default value is true.
801827
*
828+
* <p>If a {@linkplain #getTimeout(TimeUnit) timeout} is set, the driver may retry
829+
* multiple times until the timeout expires. Otherwise, at most one retry attempt is made.
830+
*
802831
* @return the retryReads value
832+
* @see #getTimeout(TimeUnit)
803833
* @since 3.11
804834
* @mongodb.server.release 3.6
805835
*/
@@ -931,9 +961,23 @@ public ServerApi getServerApi() {
931961
* <li>{@code > 0} The time limit to use for the full execution of an operation.</li>
932962
* </ul>
933963
*
964+
* <p>The timeout can also be set at the following levels (ordered by lowest precedence):
965+
* <ul>
966+
* <li>{@code MongoCluster.getTimeout}</li>
967+
* <li>{@code MongoDatabase.getTimeout}</li>
968+
* <li>{@code MongoCollection.getTimeout}</li>
969+
* <li>{@link ClientSessionOptions.Builder#defaultTimeout(long, TimeUnit) ClientSessionOptions}</li>
970+
* <li>{@link TransactionOptions.Builder#timeout(Long, TimeUnit) TransactionOptions}</li>
971+
* </ul>
972+
* If not set at a given level, the timeout is inherited from the level above.
973+
*
974+
* <p>If {@linkplain #getRetryWrites() write} or {@linkplain #getRetryReads() read} retries are enabled,
975+
* the driver may retry multiple times until the timeout expires. Otherwise, at most one retry attempt is made.
976+
*
934977
* @param timeUnit the time unit
935978
* @return the timeout in the given time unit
936979
* @since 5.2
980+
* @see Builder#timeout(long, TimeUnit)
937981
*/
938982
@Alpha(Reason.CLIENT)
939983
@Nullable

driver-kotlin-coroutine/src/main/kotlin/com/mongodb/kotlin/client/coroutine/MongoCluster.kt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,21 @@ public open class MongoCluster protected constructor(private val wrapped: JMongo
8181
* - `0` means infinite timeout.
8282
* - `> 0` The time limit to use for the full execution of an operation.
8383
*
84+
* The timeout can be set at the following levels (ordered by lowest precedence):
85+
* - [MongoClientSettings.Builder.timeout]
86+
* - [MongoCluster.withTimeout] (current)
87+
* - [MongoDatabase.withTimeout]
88+
* - [MongoCollection.withTimeout]
89+
* - [com.mongodb.ClientSessionOptions.Builder.defaultTimeout]
90+
* - [com.mongodb.TransactionOptions.Builder.timeout]
91+
*
92+
* If not set at a given level, the timeout is inherited from the level above.
93+
*
94+
* If [write][MongoClientSettings.Builder.retryWrites] or [read][MongoClientSettings.Builder.retryReads] retries are
95+
* enabled, the driver may retry multiple times until the timeout expires.
96+
*
8497
* @return the optional timeout duration
98+
* @see [withTimeout]
8599
*/
86100
@Alpha(Reason.CLIENT)
87101
public fun timeout(timeUnit: TimeUnit = TimeUnit.MILLISECONDS): Long? = wrapped.getTimeout(timeUnit)
@@ -134,10 +148,23 @@ public open class MongoCluster protected constructor(private val wrapped: JMongo
134148
* - `0` means an infinite timeout
135149
* - `> 0` The time limit to use for the full execution of an operation.
136150
*
151+
* The timeout can be set at the following levels (ordered by lowest precedence):
152+
* - [MongoClientSettings.Builder.timeout]
153+
* - [MongoCluster.withTimeout] (current)
154+
* - [MongoDatabase.withTimeout]
155+
* - [MongoCollection.withTimeout]
156+
* - [com.mongodb.ClientSessionOptions.Builder.defaultTimeout]
157+
* - [com.mongodb.TransactionOptions.Builder.timeout]
158+
*
159+
* If not set at a given level, the timeout is inherited from the level above.
160+
*
161+
* If [write][MongoClientSettings.Builder.retryWrites] or [read][MongoClientSettings.Builder.retryReads] retries are
162+
* enabled, the driver may retry multiple times until the timeout expires.
163+
*
137164
* @param timeout the timeout, which must be greater than or equal to 0
138165
* @param timeUnit the time unit, defaults to Milliseconds
139166
* @return a new MongoCluster instance with the set time limit for operations
140-
* @see [MongoDatabase.timeout]
167+
* @see [timeout]
141168
* @since 5.2
142169
*/
143170
@Alpha(Reason.CLIENT)

driver-kotlin-coroutine/src/main/kotlin/com/mongodb/kotlin/client/coroutine/MongoCollection.kt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,21 @@ public class MongoCollection<T : Any>(private val wrapped: JMongoCollection<T>)
105105
* - `0` means infinite timeout.
106106
* - `> 0` The time limit to use for the full execution of an operation.
107107
*
108+
* The timeout can be set at the following levels (ordered by lowest precedence):
109+
* - [MongoClientSettings.Builder.timeout]
110+
* - [MongoCluster.withTimeout]
111+
* - [MongoDatabase.withTimeout]
112+
* - [MongoCollection.withTimeout] (current)
113+
* - [com.mongodb.ClientSessionOptions.Builder.defaultTimeout]
114+
* - [com.mongodb.TransactionOptions.Builder.timeout]
115+
*
116+
* If not set at a given level, the timeout is inherited from the level above.
117+
*
118+
* If [write][MongoClientSettings.Builder.retryWrites] or [read][MongoClientSettings.Builder.retryReads] retries are
119+
* enabled, the driver may retry multiple times until the timeout expires.
120+
*
108121
* @return the optional timeout duration
122+
* @see [withTimeout]
109123
* @since 5.2
110124
*/
111125
@Alpha(Reason.CLIENT)
@@ -179,10 +193,23 @@ public class MongoCollection<T : Any>(private val wrapped: JMongoCollection<T>)
179193
* - `0` means an infinite timeout
180194
* - `> 0` The time limit to use for the full execution of an operation.
181195
*
196+
* The timeout can be set at the following levels (ordered by lowest precedence):
197+
* - [MongoClientSettings.Builder.timeout]
198+
* - [MongoCluster.withTimeout]
199+
* - [MongoDatabase.withTimeout]
200+
* - [MongoCollection.withTimeout] (current)
201+
* - [com.mongodb.ClientSessionOptions.Builder.defaultTimeout]
202+
* - [com.mongodb.TransactionOptions.Builder.timeout]
203+
*
204+
* If not set at a given level, the timeout is inherited from the level above.
205+
*
206+
* If [write][MongoClientSettings.Builder.retryWrites] or [read][MongoClientSettings.Builder.retryReads] retries are
207+
* enabled, the driver may retry multiple times until the timeout expires.
208+
*
182209
* @param timeout the timeout, which must be greater than or equal to 0
183210
* @param timeUnit the time unit, defaults to Milliseconds
184211
* @return a new MongoCollection instance with the set time limit for operations
185-
* @see [MongoCollection.timeout]
212+
* @see [timeout]
186213
* @since 5.2
187214
*/
188215
@Alpha(Reason.CLIENT)

driver-kotlin-coroutine/src/main/kotlin/com/mongodb/kotlin/client/coroutine/MongoDatabase.kt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,21 @@ public class MongoDatabase(private val wrapped: JMongoDatabase) {
7373
* - `0` means infinite timeout.
7474
* - `> 0` The time limit to use for the full execution of an operation.
7575
*
76+
* The timeout can be set at the following levels (ordered by lowest precedence):
77+
* - [MongoClientSettings.Builder.timeout]
78+
* - [MongoCluster.withTimeout]
79+
* - [MongoDatabase.withTimeout] (current)
80+
* - [MongoCollection.withTimeout]
81+
* - [com.mongodb.ClientSessionOptions.Builder.defaultTimeout]
82+
* - [com.mongodb.TransactionOptions.Builder.timeout]
83+
*
84+
* If not set at a given level, the timeout is inherited from the level above.
85+
*
86+
* If [write][MongoClientSettings.Builder.retryWrites] or [read][MongoClientSettings.Builder.retryReads] retries are
87+
* enabled, the driver may retry multiple times until the timeout expires.
88+
*
7689
* @return the optional timeout duration
90+
* @see [withTimeout]
7791
* @since 5.2
7892
*/
7993
@Alpha(Reason.CLIENT)
@@ -127,10 +141,23 @@ public class MongoDatabase(private val wrapped: JMongoDatabase) {
127141
* - `0` means an infinite timeout
128142
* - `> 0` The time limit to use for the full execution of an operation.
129143
*
144+
* The timeout can be set at the following levels (ordered by lowest precedence):
145+
* - [MongoClientSettings.Builder.timeout]
146+
* - [MongoCluster.withTimeout]
147+
* - [MongoDatabase.withTimeout] (current)
148+
* - [MongoCollection.withTimeout]
149+
* - [com.mongodb.ClientSessionOptions.Builder.defaultTimeout]
150+
* - [com.mongodb.TransactionOptions.Builder.timeout]
151+
*
152+
* If not set at a given level, the timeout is inherited from the level above.
153+
*
154+
* If [write][MongoClientSettings.Builder.retryWrites] or [read][MongoClientSettings.Builder.retryReads] retries are
155+
* enabled, the driver may retry multiple times until the timeout expires.
156+
*
130157
* @param timeout the timeout, which must be greater than or equal to 0
131158
* @param timeUnit the time unit, defaults to Milliseconds
132159
* @return a new MongoDatabase instance with the set time limit for operations
133-
* @see [MongoDatabase.timeout]
160+
* @see [timeout]
134161
* @since 5.2
135162
*/
136163
@Alpha(Reason.CLIENT)

driver-kotlin-sync/src/main/kotlin/com/mongodb/kotlin/client/MongoCluster.kt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,21 @@ public open class MongoCluster protected constructor(private val wrapped: JMongo
7878
* - `0` means infinite timeout.
7979
* - `> 0` The time limit to use for the full execution of an operation.
8080
*
81+
* The timeout can be set at the following levels (ordered by lowest precedence):
82+
* - [MongoClientSettings.Builder.timeout]
83+
* - [MongoCluster.withTimeout] (current)
84+
* - [MongoDatabase.withTimeout]
85+
* - [MongoCollection.withTimeout]
86+
* - [com.mongodb.ClientSessionOptions.Builder.defaultTimeout]
87+
* - [com.mongodb.TransactionOptions.Builder.timeout]
88+
*
89+
* If not set at a given level, the timeout is inherited from the level above.
90+
*
91+
* If [write][MongoClientSettings.Builder.retryWrites] or [read][MongoClientSettings.Builder.retryReads] retries are
92+
* enabled, the driver may retry multiple times until the timeout expires.
93+
*
8194
* @return the optional timeout duration
95+
* @see [withTimeout]
8296
*/
8397
@Alpha(Reason.CLIENT)
8498
public fun timeout(timeUnit: TimeUnit = TimeUnit.MILLISECONDS): Long? = wrapped.getTimeout(timeUnit)
@@ -131,10 +145,23 @@ public open class MongoCluster protected constructor(private val wrapped: JMongo
131145
* - `0` means an infinite timeout
132146
* - `> 0` The time limit to use for the full execution of an operation.
133147
*
148+
* The timeout can be set at the following levels (ordered by lowest precedence):
149+
* - [MongoClientSettings.Builder.timeout]
150+
* - [MongoCluster.withTimeout] (current)
151+
* - [MongoDatabase.withTimeout]
152+
* - [MongoCollection.withTimeout]
153+
* - [com.mongodb.ClientSessionOptions.Builder.defaultTimeout]
154+
* - [com.mongodb.TransactionOptions.Builder.timeout]
155+
*
156+
* If not set at a given level, the timeout is inherited from the level above.
157+
*
158+
* If [write][MongoClientSettings.Builder.retryWrites] or [read][MongoClientSettings.Builder.retryReads] retries are
159+
* enabled, the driver may retry multiple times until the timeout expires.
160+
*
134161
* @param timeout the timeout, which must be greater than or equal to 0
135162
* @param timeUnit the time unit, defaults to Milliseconds
136163
* @return a new MongoCluster instance with the set time limit for operations
137-
* @see [MongoDatabase.timeout]
164+
* @see [timeout]
138165
* @since 5.2
139166
*/
140167
@Alpha(Reason.CLIENT)

driver-kotlin-sync/src/main/kotlin/com/mongodb/kotlin/client/MongoCollection.kt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,21 @@ public class MongoCollection<T : Any>(private val wrapped: JMongoCollection<T>)
102102
* - `0` means infinite timeout.
103103
* - `> 0` The time limit to use for the full execution of an operation.
104104
*
105+
* The timeout can be set at the following levels (ordered by lowest precedence):
106+
* - [MongoClientSettings.Builder.timeout]
107+
* - [MongoCluster.withTimeout]
108+
* - [MongoDatabase.withTimeout]
109+
* - [MongoCollection.withTimeout] (current)
110+
* - [com.mongodb.ClientSessionOptions.Builder.defaultTimeout]
111+
* - [com.mongodb.TransactionOptions.Builder.timeout]
112+
*
113+
* If not set at a given level, the timeout is inherited from the level above.
114+
*
115+
* If [write][MongoClientSettings.Builder.retryWrites] or [read][MongoClientSettings.Builder.retryReads] retries are
116+
* enabled, the driver may retry multiple times until the timeout expires.
117+
*
105118
* @return the optional timeout duration
119+
* @see [withTimeout]
106120
* @since 5.2
107121
*/
108122
@Alpha(Reason.CLIENT)
@@ -176,10 +190,23 @@ public class MongoCollection<T : Any>(private val wrapped: JMongoCollection<T>)
176190
* - `0` means an infinite timeout
177191
* - `> 0` The time limit to use for the full execution of an operation.
178192
*
193+
* The timeout can be set at the following levels (ordered by lowest precedence):
194+
* - [MongoClientSettings.Builder.timeout]
195+
* - [MongoCluster.withTimeout]
196+
* - [MongoDatabase.withTimeout]
197+
* - [MongoCollection.withTimeout] (current)
198+
* - [com.mongodb.ClientSessionOptions.Builder.defaultTimeout]
199+
* - [com.mongodb.TransactionOptions.Builder.timeout]
200+
*
201+
* If not set at a given level, the timeout is inherited from the level above.
202+
*
203+
* If [write][MongoClientSettings.Builder.retryWrites] or [read][MongoClientSettings.Builder.retryReads] retries are
204+
* enabled, the driver may retry multiple times until the timeout expires.
205+
*
179206
* @param timeout the timeout, which must be greater than or equal to 0
180207
* @param timeUnit the time unit, defaults to Milliseconds
181208
* @return a new MongoCollection instance with the set time limit for operations
182-
* @see [MongoCollection.timeout]
209+
* @see [timeout]
183210
* @since 5.2
184211
*/
185212
@Alpha(Reason.CLIENT)

driver-kotlin-sync/src/main/kotlin/com/mongodb/kotlin/client/MongoDatabase.kt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,21 @@ public class MongoDatabase(private val wrapped: JMongoDatabase) {
7171
* - `0` means infinite timeout.
7272
* - `> 0` The time limit to use for the full execution of an operation.
7373
*
74+
* The timeout can be set at the following levels (ordered by lowest precedence):
75+
* - [MongoClientSettings.Builder.timeout]
76+
* - [MongoCluster.withTimeout]
77+
* - [MongoDatabase.withTimeout] (current)
78+
* - [MongoCollection.withTimeout]
79+
* - [com.mongodb.ClientSessionOptions.Builder.defaultTimeout]
80+
* - [com.mongodb.TransactionOptions.Builder.timeout]
81+
*
82+
* If not set at a given level, the timeout is inherited from the level above.
83+
*
84+
* If [write][MongoClientSettings.Builder.retryWrites] or [read][MongoClientSettings.Builder.retryReads] retries are
85+
* enabled, the driver may retry multiple times until the timeout expires.
86+
*
7487
* @return the optional timeout duration
88+
* @see [withTimeout]
7589
* @since 5.2
7690
*/
7791
@Alpha(Reason.CLIENT)
@@ -125,10 +139,23 @@ public class MongoDatabase(private val wrapped: JMongoDatabase) {
125139
* - `0` means an infinite timeout
126140
* - `> 0` The time limit to use for the full execution of an operation.
127141
*
142+
* The timeout can be set at the following levels (ordered by lowest precedence):
143+
* - [MongoClientSettings.Builder.timeout]
144+
* - [MongoCluster.withTimeout]
145+
* - [MongoDatabase.withTimeout] (current)
146+
* - [MongoCollection.withTimeout]
147+
* - [com.mongodb.ClientSessionOptions.Builder.defaultTimeout]
148+
* - [com.mongodb.TransactionOptions.Builder.timeout]
149+
*
150+
* If not set at a given level, the timeout is inherited from the level above.
151+
*
152+
* If [write][MongoClientSettings.Builder.retryWrites] or [read][MongoClientSettings.Builder.retryReads] retries are
153+
* enabled, the driver may retry multiple times until the timeout expires.
154+
*
128155
* @param timeout the timeout, which must be greater than or equal to 0
129156
* @param timeUnit the time unit, defaults to Milliseconds
130157
* @return a new MongoDatabase instance with the set time limit for operations
131-
* @see [MongoDatabase.timeout]
158+
* @see [timeout]
132159
* @since 5.2
133160
*/
134161
@Alpha(Reason.CLIENT)

0 commit comments

Comments
 (0)