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

Allow configuring the monitoring protocol to use; use the polling protocol in a FaaS environment by default #1313

Merged
merged 15 commits into from
Feb 29, 2024

Conversation

stIncMale
Copy link
Member

@stIncMale stIncMale commented Feb 21, 2024

Reviewers:

  • @vbabanin picked up automatically via @mongodb/dbx-java.
  • @jyemin picked up manually as @mongodb/dbx-java does not work twice.

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

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
@stIncMale stIncMale force-pushed the JAVA-4936 branch 2 times, most recently from 931f6e0 to cdd3af9 Compare February 22, 2024 17:11
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
Comment on lines -84 to -86
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;
Copy link
Member Author

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.

Copy link
Member

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 👍

@stIncMale stIncMale marked this pull request as ready for review February 22, 2024 22:42
@stIncMale stIncMale requested review from a team, vbabanin and jyemin and removed request for a team February 22, 2024 22:42
Comment on lines +51 to +57
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"));
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -165,8 +192,7 @@ public void run() {
logStateChange(previousServerDescription, currentServerDescription);
sdamProvider.get().update(currentServerDescription);

if (((connection == null || shouldStreamResponses(currentServerDescription))
Copy link
Member

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?

Copy link
Contributor

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.

Copy link
Member Author

@stIncMale stIncMale Feb 28, 2024

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.

  1. Let's alias the connection == null expression as x.
  2. Note that the expressions shouldStreamResponses(currentServerDescription) and currentServerDescription.getTopologyVersion() != null are equivalent (well, were equivalent at the time of the commit that simplified the expression). Let's alias them as s.

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
)

Copy link
Member

@vbabanin vbabanin Feb 29, 2024

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/ConnectionString.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))
Copy link
Contributor

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.

stIncMale and others added 2 commits February 28, 2024 17:49
…de.java

Co-authored-by: Jeff Yemin <jeff.yemin@mongodb.com>
…itoringModeUtil.java

Co-authored-by: Jeff Yemin <jeff.yemin@mongodb.com>
Copy link
Member

@vbabanin vbabanin left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@jyemin jyemin left a comment

Choose a reason for hiding this comment

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

LGTM!

@stIncMale stIncMale merged commit 7295322 into mongodb:master Feb 29, 2024
56 checks passed
@stIncMale stIncMale deleted the JAVA-4936 branch February 29, 2024 15:29
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.

3 participants