-
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
Allow configuring the monitoring protocol to use; use the polling protocol in a FaaS environment by default #1313
Conversation
This change was supposed to be done as part of mongodb@c8b028a JAVA-4936
Note that despite this commit marking 1.16 as supported, it actually is not. The existing practice is to mark as supported all the versions up to the one that is either fully or partially supported, despite them being likely not actually supported. When someone discovers that a feature is used in a test, but is not implemented, then he implements that feature. JAVA-4936
This change is with accordance to source/faas-automated-testing/faas-automated-testing.rst JAVA-4936
931f6e0
to
cdd3af9
Compare
This change is in accordance with source/uri-options/uri-options.rst. JAVA-4936
This change is in accordance with source/server-discovery-and-monitoring/server-monitoring.rst. JAVA-4936
This change is in accordance with source/server-discovery-and-monitoring/server-monitoring.rst. JAVA-4936
private final RoundTripTimeRunnable roundTripTimeMonitor; | ||
private final ServerMonitor monitor; | ||
/** | ||
* Must be guarded by {@link #lock}. | ||
*/ | ||
@Nullable | ||
private RoundTripTimeMonitor roundTripTimeMonitor; | ||
private final ExponentiallyWeightedMovingAverage averageRoundTripTime = new ExponentiallyWeightedMovingAverage(0.2); | ||
private final Thread roundTripTimeMonitorThread; |
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.
The changes required both roundTripTimeMonitor
& roundTripTimeMonitorThread
to become null
-able. I simplified that by replacing these two fields with a single field. However, this change lead to an inconsistent code having a single field roundTripTimeMonitor
and two coupled fields monitor
& monitorThread
. To avoid such inconsistency, I also replaced the latter with a single field.
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.
Thank you, the code looks cleaner now 👍
public static void skipTests(final BsonDocument definition) { | ||
String description = definition.getString("description", new BsonString("")).getValue(); | ||
assumeFalse("Skipping because our server monitoring events behave differently for now", | ||
description.equals("connect with serverMonitoringMode=auto >=4.4")); | ||
assumeFalse("Skipping because our server monitoring events behave differently for now", | ||
description.equals("connect with serverMonitoringMode=stream >=4.4")); | ||
} |
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.
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.
driver-core/src/main/com/mongodb/connection/ServerMonitoringMode.java
Outdated
Show resolved
Hide resolved
@@ -165,8 +192,7 @@ public void run() { | |||
logStateChange(previousServerDescription, currentServerDescription); | |||
sdamProvider.get().update(currentServerDescription); | |||
|
|||
if (((connection == null || shouldStreamResponses(currentServerDescription)) |
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.
is this check "connection == null" not needed anymore?
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.
I thought I had proven to myself that the check was redundant by transforming to
boolean shouldStream = currentServerDescription.getTopologyVersion() != null;
if (((connection == null || shouldStream)
&& shouldStream && currentServerDescription.getType() != UNKNOWN)
|| (connection != null && connection.hasMoreToCome())
|| (currentServerDescription.getException() instanceof MongoSocketException
&& previousServerDescription.getType() != UNKNOWN)) {
continue;
}
and then allowing Intellij to simplify the expression, but when I tried it again IntelliJ didn't offer the simplification.
This is a truly horrible conditional, and has been the source of at least one bug that I remember.
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.
is this check "connection == null" not needed anymore?
It had no effect, so I removed it. The following demonstrates why the connection == null
expression had no effect.
Here is the original conditional, but reformatted to simplify perception:
(
(connection == null || shouldStreamResponses(currentServerDescription))
&& currentServerDescription.getTopologyVersion() != null
&& currentServerDescription.getType() != UNKNOWN
)
||
(connection != null && connection.hasMoreToCome())
||
(
currentServerDescription.getException() instanceof MongoSocketException
&& previousServerDescription.getType() != UNKNOWN
)
It consists of three Boolean expressions ORed (||
) together. Only the first one of those is modified in the PR.
- Let's alias the
connection == null
expression asx
. - Note that the expressions
shouldStreamResponses(currentServerDescription)
andcurrentServerDescription.getTopologyVersion() != null
are equivalent (well, were equivalent at the time of the commit that simplified the expression). Let's alias them ass
.
Now the first ORed Boolean expression can be written as
(
(x || s)
&& s
&& currentServerDescription.getType() != UNKNOWN
)
If s
is false
, this expression evaluates to false
. If s
is true
, this expression evaluates to the same value as currentServerDescription.getType() != UNKNOWN
. As you can see, x
affects the outcome is neither case, and the expression can be simplified to
(
s
&& currentServerDescription.getType() != UNKNOWN
)
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.
Thanks for the clarification, @stIncMale. Now i see, It is indeed redundant check.
i am curious about the original purpose of this check, given it wasn't functional. My assumption was that it might have aimed to bypass waitForNext()
on lookup failure as connection is nullified in lookup method. However, the presence of (currentServerDescription.getException() instanceof MongoSocketException && previousServerDescription.getType() != UNKNOWN)
seems to cover scenario aligning with the spec, which mandates immediate retry on network errors when the server was previously in a known state.
#. If this was a network error and the server was in a known state before the error, the client MUST NOT sleep and MUST begin the next check immediately.
Feel free to resolve the conversation if @jyemin has no further comments.
driver-core/src/main/com/mongodb/internal/connection/DefaultServerMonitor.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/connection/ServerMonitoringMode.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/internal/connection/DefaultClusterableServerFactory.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/internal/connection/DefaultServerMonitor.java
Show resolved
Hide resolved
@@ -165,8 +192,7 @@ public void run() { | |||
logStateChange(previousServerDescription, currentServerDescription); | |||
sdamProvider.get().update(currentServerDescription); | |||
|
|||
if (((connection == null || shouldStreamResponses(currentServerDescription)) |
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.
I thought I had proven to myself that the check was redundant by transforming to
boolean shouldStream = currentServerDescription.getTopologyVersion() != null;
if (((connection == null || shouldStream)
&& shouldStream && currentServerDescription.getType() != UNKNOWN)
|| (connection != null && connection.hasMoreToCome())
|| (currentServerDescription.getException() instanceof MongoSocketException
&& previousServerDescription.getType() != UNKNOWN)) {
continue;
}
and then allowing Intellij to simplify the expression, but when I tried it again IntelliJ didn't offer the simplification.
This is a truly horrible conditional, and has been the source of at least one bug that I remember.
…de.java Co-authored-by: Viacheslav Babanin <frest0512@gmail.com>
driver-core/src/main/com/mongodb/connection/ServerMonitoringMode.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/com/mongodb/internal/connection/ServerMonitoringModeUtil.java
Show resolved
Hide resolved
…de.java Co-authored-by: Jeff Yemin <jeff.yemin@mongodb.com>
…itoringModeUtil.java Co-authored-by: Jeff Yemin <jeff.yemin@mongodb.com>
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.
LGTM!
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.
LGTM!
Reviewers:
The initial 6 commits are organized in such a way that a reviewer may review them one by one. They don't step on each other's toes, and represent separate work items.
JAVA-4936