-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Centralize appending of maxTimeMS #1333
Conversation
JAVA-5322
JAVA-5322
JAVA-5322
@@ -319,4 +324,15 @@ public Timeout getTimeout() { | |||
return timeout; | |||
} | |||
|
|||
public void addExtraElements(final List<BsonElement> extraElements) { | |||
long maxTimeMS = maxTimeSupplier.get(); |
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.
Nit: Long maxTimeMS
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.
Done.
JAVA-5322
# Conflicts: # driver-core/src/main/com/mongodb/internal/operation/OperationHelper.java
JAVA-5322
} else if (timeoutMS == 0) { | ||
return timeoutMS; | ||
} else { | ||
return timeoutRemainingMS(); | ||
} |
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.
else if (timeoutMS == 0)
is removed due to an issue where using an original infinite timeout (timeoutMS = 0) incorrectly led to always returning 0 from TimeoutSettings
in timeoutOrAlternative
, regardless of actual computedServerSelectionTimeout
time left.
timeoutRemainingMS()
handles both infinite and finite timeouts, checking against the timeout
object itself:
For the reference:
private long timeoutRemainingMS() {
assertNotNull(timeout);
if (timeout.hasExpired()) {
throw createMongoTimeoutException("The operation timeout has expired.");
}
return timeout.isInfinite() ? 0 : timeout.remaining(MILLISECONDS);
}
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.
Note: I added timeoutRemainingMS
for review in JAVA-5351 as it can incorrectly return 0. (Nothing to fix in this ticket).
List<BsonElement> extraElements = new ArrayList<>(); | ||
if (!getSettings().isCryptd()) { |
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.
From the spec:
When sending a command to mongocryptd, drivers MUST NOT append a maxTimeMS field. This is to ensure that a maxTimeMS field can be safely appended to the command after it has been marked by mongocryptd and encrypted by libmongocrypt. To determine whether or not the server is a mongocryptd, drivers MUST check that the iscryptd field in the server's description is true.
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.
Its looking good and is much cleaner than I initially thought it would be.
Found a couple of nits but I also recommend a couple of minor changes to the API:
A):
Have TimeoutContext.getMaxTimeMS()
be the thing that consumes the supplier eg:
public Long getMaxTimeMS() {
return notNull("Should never be null", maxTimeoutSupplier.get());
}
Convert the current getMaxTimeMS
to be protected and used internally eg: rename it to defaultMaxTimeMS
.
Add a timeoutContext.resetSupplier()
that resets the supplier to the default. Rather than doing: timeoutContext.setMaxTimeSupplier(timeoutContext::getMaxTimeMS);
B):
Remove TimeoutContext#addTimeoutElements
put the logic in command message.
C):
I think CommandOperationHelper#appendMaxTimeMs
can now be removed.
What do you think?
} else if (timeoutMS == 0) { | ||
return timeoutMS; | ||
} else { | ||
return timeoutRemainingMS(); | ||
} |
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.
Note: I added timeoutRemainingMS
for review in JAVA-5351 as it can incorrectly return 0. (Nothing to fix in this ticket).
driver-core/src/main/com/mongodb/internal/connection/CommandMessage.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/internal/operation/OperationHelper.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/internal/operation/AsyncCommandBatchCursor.java
Show resolved
Hide resolved
- Introduce reset method for MaxTimeMsSupplier. JAVA-5322
Thank you for the suggestions @rozza! A) Agreed. This change will maintain consistency in the TimeoutContext API with other methods. Implemented. B) Implemented as suggested. C) Agreed and removed. |
@vbabanin I think one of the mocks needs updating as its causing all the tests to fail. |
JAVA-5322
# Conflicts: # driver-core/src/main/com/mongodb/internal/TimeoutContext.java # driver-core/src/test/unit/com/mongodb/internal/TimeoutContextTest.java
driver-core/src/main/com/mongodb/internal/operation/CountOperation.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/connection/ServerDescription.java
Outdated
Show resolved
Hide resolved
driver-core/src/test/unit/com/mongodb/internal/TimeoutContextTest.java
Outdated
Show resolved
Hide resolved
driver-core/src/test/unit/com/mongodb/internal/connection/CommandMessageSpecification.groovy
Outdated
Show resolved
Hide resolved
driver-core/src/test/unit/com/mongodb/internal/connection/CommandMessageTest.java
Outdated
Show resolved
Hide resolved
driver-core/src/test/unit/com/mongodb/internal/connection/CommandMessageTest.java
Outdated
Show resolved
Hide resolved
...nctional/com/mongodb/client/csot/AbstractClientSideOperationsEncryptionTimeoutProseTest.java
Show resolved
Hide resolved
…est.java Co-authored-by: Valentin Kovalenko <valentin.male.kovalenko@gmail.com>
…andMessageTest.java Co-authored-by: Valentin Kovalenko <valentin.male.kovalenko@gmail.com>
…andMessageTest.java Co-authored-by: Valentin Kovalenko <valentin.male.kovalenko@gmail.com>
JAVA-5322
JAVA-5322
JAVA-5322
Description:
This PR tackles the challenge identified in JAVA-4055 related to the handling of maxTimeMS in the context of Client-Side Field Level Encryption (CSFLE) by moving appending of maxTimeMS to a centralized and lower level within the driver, specifically to the CommandMessage.
Implementation details
Operations handle maxTimeMS differently:
Therefore, this PR introduces
MaxTimeMsSupplier
inTimeoutContext
. This ensuresCommandMessage
remains agnostic to the operation's logic, allowing operations to dictate it.JAVA-5322
JAVA-5327