-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Obtain waitQueue and connection timeouts from OperationContext #1228
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,35 +37,38 @@ public class TimeoutSettings { | |
@Nullable | ||
private final Long defaultTimeoutMS; | ||
|
||
private final long maxAwaitTimeMS; | ||
|
||
// Deprecated timeouts | ||
private final long readTimeoutMS; | ||
// Deprecated configuration timeout options | ||
private final long readTimeoutMS; // aka socketTimeoutMS | ||
private final long maxWaitTimeMS; // aka waitQueueTimeoutMS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
@Nullable | ||
private final Long wTimeoutMS; | ||
|
||
// Deprecated options for CRUD methods | ||
private final long maxTimeMS; | ||
|
||
private final long maxAwaitTimeMS; | ||
private final long maxCommitTimeMS; | ||
@Nullable | ||
private final Long wTimeoutMS; | ||
|
||
public static final TimeoutSettings DEFAULT = create(MongoClientSettings.builder().build()); | ||
|
||
public static TimeoutSettings create(final MongoClientSettings settings) { | ||
return new TimeoutSettings(settings.getClusterSettings().getServerSelectionTimeout(TimeUnit.MILLISECONDS), | ||
return new TimeoutSettings( | ||
settings.getClusterSettings().getServerSelectionTimeout(TimeUnit.MILLISECONDS), | ||
settings.getSocketSettings().getConnectTimeout(TimeUnit.MILLISECONDS), | ||
settings.getSocketSettings().getReadTimeout(TimeUnit.MILLISECONDS), | ||
settings.getTimeout(TimeUnit.MILLISECONDS)); | ||
settings.getTimeout(TimeUnit.MILLISECONDS), | ||
settings.getConnectionPoolSettings().getMaxWaitTime(TimeUnit.MILLISECONDS)); | ||
} | ||
|
||
public TimeoutSettings( | ||
final long serverSelectionTimeoutMS, final long connectTimeoutMS, final long readTimeoutMS, @Nullable final Long timeoutMS) { | ||
this(timeoutMS, null, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, 0, 0, 0, null); | ||
final long serverSelectionTimeoutMS, final long connectTimeoutMS, final long readTimeoutMS, | ||
@Nullable final Long timeoutMS, final long maxWaitTimeMS) { | ||
this(timeoutMS, null, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, 0, 0, 0, null, maxWaitTimeMS); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added maxWaitTimeMS, in a way that seemed consistent with readTimeoutMS, but I was also not sure whether we intended to pass these in, since both were deprecated. Should these really be passed in, or should they be set using one of the "with" methods below? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its needed in the constructor, so it can be copied via the with methods. |
||
} | ||
|
||
TimeoutSettings( | ||
@Nullable final Long timeoutMS, @Nullable final Long defaultTimeoutMS, final long serverSelectionTimeoutMS, | ||
final long connectTimeoutMS, final long readTimeoutMS, final long maxAwaitTimeMS, final long maxTimeMS, | ||
final long maxCommitTimeMS, @Nullable final Long wTimeoutMS) { | ||
final long maxCommitTimeMS, @Nullable final Long wTimeoutMS, final long maxWaitTimeMS) { | ||
isTrueArgument("timeoutMS must be >= 0", timeoutMS == null || timeoutMS >= 0); | ||
this.serverSelectionTimeoutMS = serverSelectionTimeoutMS; | ||
this.connectTimeoutMS = connectTimeoutMS; | ||
|
@@ -76,45 +79,46 @@ public TimeoutSettings( | |
this.maxTimeMS = maxTimeMS; | ||
this.maxCommitTimeMS = maxCommitTimeMS; | ||
this.wTimeoutMS = wTimeoutMS; | ||
this.maxWaitTimeMS = maxWaitTimeMS; | ||
} | ||
|
||
public TimeoutSettings connectionOnly() { | ||
return new TimeoutSettings(serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, null); | ||
return new TimeoutSettings(serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, null, 0); | ||
} | ||
|
||
public TimeoutSettings withTimeoutMS(final long timeoutMS) { | ||
return new TimeoutSettings(timeoutMS, defaultTimeoutMS, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS, | ||
maxTimeMS, maxCommitTimeMS, wTimeoutMS); | ||
maxTimeMS, maxCommitTimeMS, wTimeoutMS, maxWaitTimeMS); | ||
} | ||
|
||
public TimeoutSettings withDefaultTimeoutMS(final long defaultTimeoutMS) { | ||
return new TimeoutSettings(timeoutMS, defaultTimeoutMS, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS, | ||
maxTimeMS, maxCommitTimeMS, wTimeoutMS); | ||
maxTimeMS, maxCommitTimeMS, wTimeoutMS, maxWaitTimeMS); | ||
} | ||
|
||
public TimeoutSettings withMaxTimeMS(final long maxTimeMS) { | ||
return new TimeoutSettings(timeoutMS, defaultTimeoutMS, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS, | ||
maxTimeMS, maxCommitTimeMS, wTimeoutMS); | ||
maxTimeMS, maxCommitTimeMS, wTimeoutMS, maxWaitTimeMS); | ||
} | ||
|
||
public TimeoutSettings withMaxAwaitTimeMS(final long maxAwaitTimeMS) { | ||
return new TimeoutSettings(timeoutMS, defaultTimeoutMS, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS, | ||
maxTimeMS, maxCommitTimeMS, wTimeoutMS); | ||
maxTimeMS, maxCommitTimeMS, wTimeoutMS, maxWaitTimeMS); | ||
} | ||
|
||
public TimeoutSettings withMaxTimeAndMaxAwaitTimeMS(final long maxTimeMS, final long maxAwaitTimeMS) { | ||
return new TimeoutSettings(timeoutMS, defaultTimeoutMS, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS, | ||
maxTimeMS, maxCommitTimeMS, wTimeoutMS); | ||
maxTimeMS, maxCommitTimeMS, wTimeoutMS, maxWaitTimeMS); | ||
} | ||
|
||
public TimeoutSettings withMaxCommitMS(final long maxCommitTimeMS) { | ||
return new TimeoutSettings(timeoutMS, defaultTimeoutMS, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS, | ||
maxTimeMS, maxCommitTimeMS, wTimeoutMS); | ||
maxTimeMS, maxCommitTimeMS, wTimeoutMS, maxWaitTimeMS); | ||
} | ||
|
||
public TimeoutSettings withWTimeoutMS(@Nullable final Long wTimeoutMS) { | ||
return new TimeoutSettings(timeoutMS, defaultTimeoutMS, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS, | ||
maxTimeMS, maxCommitTimeMS, wTimeoutMS); | ||
maxTimeMS, maxCommitTimeMS, wTimeoutMS, maxWaitTimeMS); | ||
} | ||
|
||
public long getServerSelectionTimeoutMS() { | ||
|
@@ -156,6 +160,10 @@ public Long getWTimeoutMS() { | |
return wTimeoutMS; | ||
} | ||
|
||
public long getMaxWaitTimeMS() { | ||
return maxWaitTimeMS; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "TimeoutSettings{" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This returns an int. I think it would be more consistent to return a Timeout, but it was used in a way where 0 indicated infinite timeout (rather than the usual negative is infinite, see above). I could not find what the user should use to indicate infinite connect timeout specified in our docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because with Java sockets a timeout cannot be negative and 0 means infinite. See: socket.connect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, though I think that we should probably say the same in our own docs. (I didn't confirm that all paths used an API where 0 meant infinite, but I think this must be the case.)