Skip to content
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

Obtain waitQueue and connection timeouts from OperationContext #1228

Merged
merged 1 commit into from
Oct 30, 2023

Conversation

katcharov
Copy link
Contributor

@katcharov katcharov requested a review from rozza October 23, 2023 17:24
}

public int getConnectTimeoutMs() {
return (int) getTimeoutSettings().getConnectTimeoutMS();
Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

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.)

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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The 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.
We should eventually make this constructor private or annotate visibility test only.

OPERATION_CONTEXT.getSessionContext(),
new TimeoutContext(new TimeoutSettings(30_000, 10_000, 0, null, 0)),
OPERATION_CONTEXT.getServerApi());
connections.add(provider.get(operationContextWithZeroMaxWait));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this constructs a new operation context, as before with a 0 wait time (which I believe is intentional in this test), rather than just using OPERATION_CONTEXT.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

@@ -41,6 +44,24 @@ public OperationContext(final RequestContext requestContext, final SessionContex
this(NEXT_ID.incrementAndGet(), requestContext, sessionContext, timeoutContext, serverApi);
}


public static OperationContext todoOperationContext() {
// TODO (CSOT) should be removed; used at locations that require an OC, but which do not yet have one available
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These TODOs are intentional, and would get merged into the CSOT branch (which we would check for TODOs before merging, as per a comment there).

I left this open, because I think this would be more appropriate to supply during the crypt work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK

Comment on lines +53 to +56
public static OperationContext nonUserOperationContext(final MongoClientSettings settings) {
// TODO (CSOT) below is placeholder, validate correctness (serverApi/timeoutSettings might
// TODO (CSOT) need to be passed in instead)
TimeoutSettings timeoutSettings = TimeoutSettings.create(settings);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR does not implement provision of non-user operation contexts (for example, monitoring, etc.), and usages pass in null. I believe how this should be handled would be easier to determine once we have labelled all such locations (by using the this method). If others feel that this is best done in this PR, I do not feel strongly about this, just erring on the side of less work per PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack - good plan

Copy link
Member

@rozza rozza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}

public int getConnectTimeoutMs() {
return (int) getTimeoutSettings().getConnectTimeoutMS();
Copy link
Member

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

private final long readTimeoutMS;
// Deprecated configuration timeout options
private final long readTimeoutMS; // aka socketTimeoutMS
private final long maxWaitTimeMS; // aka waitQueueTimeoutMS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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);
Copy link
Member

Choose a reason for hiding this comment

The 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.
We should eventually make this constructor private or annotate visibility test only.

@@ -41,6 +44,24 @@ public OperationContext(final RequestContext requestContext, final SessionContex
this(NEXT_ID.incrementAndGet(), requestContext, sessionContext, timeoutContext, serverApi);
}


public static OperationContext todoOperationContext() {
// TODO (CSOT) should be removed; used at locations that require an OC, but which do not yet have one available
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK

Comment on lines +53 to +56
public static OperationContext nonUserOperationContext(final MongoClientSettings settings) {
// TODO (CSOT) below is placeholder, validate correctness (serverApi/timeoutSettings might
// TODO (CSOT) need to be passed in instead)
TimeoutSettings timeoutSettings = TimeoutSettings.create(settings);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack - good plan

OPERATION_CONTEXT.getSessionContext(),
new TimeoutContext(new TimeoutSettings(30_000, 10_000, 0, null, 0)),
OPERATION_CONTEXT.getServerApi());
connections.add(provider.get(operationContextWithZeroMaxWait));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

@katcharov katcharov merged commit ea6c37c into CSOT Oct 30, 2023
@katcharov katcharov deleted the JAVA-5212 branch October 30, 2023 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants