Skip to content

Deprecate read preference hedge options #1655

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

Merged
merged 1 commit into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions driver-core/src/main/com/mongodb/ReadPreference.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ public abstract class ReadPreference {
* @return a new ReadPreference instance with hedge options
* @since 4.1
* @mongodb.server.release 4.4
* @deprecated As of MongoDB 8.1, the server ignores the option and periodically logs a warning
*/
@Deprecated
public abstract ReadPreference withHedgeOptions(ReadPreferenceHedgeOptions hedgeOptions);

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

@Deprecated
@Override
public TaggableReadPreference withHedgeOptions(final ReadPreferenceHedgeOptions hedgeOptions) {
throw new UnsupportedOperationException("Primary read preference can not also specify hedge");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
*
* @since 4.1
* @mongodb.server.release 4.4
* @deprecated As of MongoDB 8.1, the server ignores the option and periodically logs a warning
*/
@Deprecated
@Immutable
public final class ReadPreferenceHedgeOptions {
private final boolean enabled;
Expand Down
13 changes: 13 additions & 0 deletions driver-core/src/main/com/mongodb/TaggableReadPreference.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ public abstract class TaggableReadPreference extends ReadPreference {

private final List<TagSet> tagSetList = new ArrayList<>();
private final Long maxStalenessMS;
@SuppressWarnings("deprecation")
private final ReadPreferenceHedgeOptions hedgeOptions;

TaggableReadPreference() {
this.maxStalenessMS = null;
this.hedgeOptions = null;
}

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

@Deprecated
@Override
public abstract TaggableReadPreference withHedgeOptions(ReadPreferenceHedgeOptions hedgeOptions);

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

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

@Deprecated
@Override
public TaggableReadPreference withHedgeOptions(final ReadPreferenceHedgeOptions hedgeOptions) {
return new SecondaryReadPreference(getTagSetList(), getMaxStaleness(MILLISECONDS), MILLISECONDS, hedgeOptions);
Expand Down Expand Up @@ -388,6 +395,7 @@ static class SecondaryPreferredReadPreference extends SecondaryReadPreference {
this(tagSetList, maxStaleness, timeUnit, null);
}

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

@Deprecated
@Override
public TaggableReadPreference withHedgeOptions(final ReadPreferenceHedgeOptions hedgeOptions) {
return new SecondaryPreferredReadPreference(getTagSetList(), getMaxStaleness(MILLISECONDS), MILLISECONDS, hedgeOptions);
Expand Down Expand Up @@ -441,6 +450,7 @@ static class NearestReadPreference extends TaggableReadPreference {
this(tagSetList, maxStaleness, timeUnit, null);
}

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

@Deprecated
@Override
public TaggableReadPreference withHedgeOptions(final ReadPreferenceHedgeOptions hedgeOptions) {
return new NearestReadPreference(getTagSetList(), getMaxStaleness(MILLISECONDS), MILLISECONDS, hedgeOptions);
Expand Down Expand Up @@ -503,6 +514,7 @@ static class PrimaryPreferredReadPreference extends SecondaryReadPreference {
this(tagSetList, maxStaleness, timeUnit, null);
}

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

@Deprecated
@Override
public TaggableReadPreference withHedgeOptions(final ReadPreferenceHedgeOptions hedgeOptions) {
return new PrimaryPreferredReadPreference(getTagSetList(), getMaxStaleness(MILLISECONDS), MILLISECONDS, hedgeOptions);
Expand Down