Skip to content

Commit ace6104

Browse files
authored
Deprecate read preference hedge options (mongodb#1655)
JAVA-5804
1 parent 38b12b5 commit ace6104

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ public abstract class ReadPreference {
9898
* @return a new ReadPreference instance with hedge options
9999
* @since 4.1
100100
* @mongodb.server.release 4.4
101+
* @deprecated As of MongoDB 8.1, the server ignores the option and periodically logs a warning
101102
*/
103+
@Deprecated
102104
public abstract ReadPreference withHedgeOptions(ReadPreferenceHedgeOptions hedgeOptions);
103105

104106
/**
@@ -682,6 +684,7 @@ public TaggableReadPreference withMaxStalenessMS(final Long maxStalenessMS, fina
682684
throw new UnsupportedOperationException("Primary read preference can not also specify max staleness");
683685
}
684686

687+
@Deprecated
685688
@Override
686689
public TaggableReadPreference withHedgeOptions(final ReadPreferenceHedgeOptions hedgeOptions) {
687690
throw new UnsupportedOperationException("Primary read preference can not also specify hedge");

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
*
2626
* @since 4.1
2727
* @mongodb.server.release 4.4
28+
* @deprecated As of MongoDB 8.1, the server ignores the option and periodically logs a warning
2829
*/
30+
@Deprecated
2931
@Immutable
3032
public final class ReadPreferenceHedgeOptions {
3133
private final boolean enabled;

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ public abstract class TaggableReadPreference extends ReadPreference {
5454

5555
private final List<TagSet> tagSetList = new ArrayList<>();
5656
private final Long maxStalenessMS;
57+
@SuppressWarnings("deprecation")
5758
private final ReadPreferenceHedgeOptions hedgeOptions;
5859

5960
TaggableReadPreference() {
6061
this.maxStalenessMS = null;
6162
this.hedgeOptions = null;
6263
}
6364

65+
@SuppressWarnings("deprecation")
6466
TaggableReadPreference(final List<TagSet> tagSetList, @Nullable final Long maxStaleness, final TimeUnit timeUnit,
6567
@Nullable final ReadPreferenceHedgeOptions hedgeOptions) {
6668
notNull("tagSetList", tagSetList);
@@ -80,6 +82,7 @@ public abstract class TaggableReadPreference extends ReadPreference {
8082
@Override
8183
public abstract TaggableReadPreference withMaxStalenessMS(Long maxStalenessMS, TimeUnit timeUnit);
8284

85+
@Deprecated
8386
@Override
8487
public abstract TaggableReadPreference withHedgeOptions(ReadPreferenceHedgeOptions hedgeOptions);
8588

@@ -146,7 +149,9 @@ public Long getMaxStaleness(final TimeUnit timeUnit) {
146149
* @return the hedge options
147150
* @mongodb.server.release 4.4
148151
* @since 4.1
152+
* @deprecated As of MongoDB 8.1, the server ignores the option and periodically logs a warning
149153
*/
154+
@Deprecated
150155
@Nullable
151156
public ReadPreferenceHedgeOptions getHedgeOptions() {
152157
return hedgeOptions;
@@ -327,6 +332,7 @@ static class SecondaryReadPreference extends TaggableReadPreference {
327332
this(tagSetList, maxStaleness, timeUnit, null);
328333
}
329334

335+
@SuppressWarnings("deprecation")
330336
SecondaryReadPreference(final List<TagSet> tagSetList, @Nullable final Long maxStaleness, final TimeUnit timeUnit,
331337
@Nullable final ReadPreferenceHedgeOptions hedgeOptions) {
332338
super(tagSetList, maxStaleness, timeUnit, hedgeOptions);
@@ -349,6 +355,7 @@ public TaggableReadPreference withMaxStalenessMS(@Nullable final Long maxStalene
349355
return new SecondaryReadPreference(getTagSetList(), maxStaleness, timeUnit, getHedgeOptions());
350356
}
351357

358+
@Deprecated
352359
@Override
353360
public TaggableReadPreference withHedgeOptions(final ReadPreferenceHedgeOptions hedgeOptions) {
354361
return new SecondaryReadPreference(getTagSetList(), getMaxStaleness(MILLISECONDS), MILLISECONDS, hedgeOptions);
@@ -388,6 +395,7 @@ static class SecondaryPreferredReadPreference extends SecondaryReadPreference {
388395
this(tagSetList, maxStaleness, timeUnit, null);
389396
}
390397

398+
@SuppressWarnings("deprecation")
391399
SecondaryPreferredReadPreference(final List<TagSet> tagSetList, @Nullable final Long maxStaleness, final TimeUnit timeUnit,
392400
@Nullable final ReadPreferenceHedgeOptions hedgeOptions) {
393401
super(tagSetList, maxStaleness, timeUnit, hedgeOptions);
@@ -410,6 +418,7 @@ public TaggableReadPreference withMaxStalenessMS(@Nullable final Long maxStalene
410418
return new SecondaryPreferredReadPreference(getTagSetList(), maxStaleness, timeUnit, getHedgeOptions());
411419
}
412420

421+
@Deprecated
413422
@Override
414423
public TaggableReadPreference withHedgeOptions(final ReadPreferenceHedgeOptions hedgeOptions) {
415424
return new SecondaryPreferredReadPreference(getTagSetList(), getMaxStaleness(MILLISECONDS), MILLISECONDS, hedgeOptions);
@@ -441,6 +450,7 @@ static class NearestReadPreference extends TaggableReadPreference {
441450
this(tagSetList, maxStaleness, timeUnit, null);
442451
}
443452

453+
@SuppressWarnings("deprecation")
444454
NearestReadPreference(final List<TagSet> tagSetList, @Nullable final Long maxStaleness, final TimeUnit timeUnit,
445455
@Nullable final ReadPreferenceHedgeOptions hedgeOptions) {
446456
super(tagSetList, maxStaleness, timeUnit, hedgeOptions);
@@ -463,6 +473,7 @@ public TaggableReadPreference withMaxStalenessMS(@Nullable final Long maxStalene
463473
return new NearestReadPreference(getTagSetList(), maxStaleness, timeUnit, getHedgeOptions());
464474
}
465475

476+
@Deprecated
466477
@Override
467478
public TaggableReadPreference withHedgeOptions(final ReadPreferenceHedgeOptions hedgeOptions) {
468479
return new NearestReadPreference(getTagSetList(), getMaxStaleness(MILLISECONDS), MILLISECONDS, hedgeOptions);
@@ -503,6 +514,7 @@ static class PrimaryPreferredReadPreference extends SecondaryReadPreference {
503514
this(tagSetList, maxStaleness, timeUnit, null);
504515
}
505516

517+
@SuppressWarnings("deprecation")
506518
PrimaryPreferredReadPreference(final List<TagSet> tagSetList, @Nullable final Long maxStaleness, final TimeUnit timeUnit,
507519
@Nullable final ReadPreferenceHedgeOptions hedgeOptions) {
508520
super(tagSetList, maxStaleness, timeUnit, hedgeOptions);
@@ -525,6 +537,7 @@ public TaggableReadPreference withMaxStalenessMS(@Nullable final Long maxStalene
525537
return new PrimaryPreferredReadPreference(getTagSetList(), maxStaleness, timeUnit, getHedgeOptions());
526538
}
527539

540+
@Deprecated
528541
@Override
529542
public TaggableReadPreference withHedgeOptions(final ReadPreferenceHedgeOptions hedgeOptions) {
530543
return new PrimaryPreferredReadPreference(getTagSetList(), getMaxStaleness(MILLISECONDS), MILLISECONDS, hedgeOptions);

0 commit comments

Comments
 (0)