-
Notifications
You must be signed in to change notification settings - Fork 167
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
RUST-1631 Always use polling monitoring when running in a FaaS environment #1030
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c85cb29
allow streaming hello to be disabled
abr-egn dde79b2
disable dedicated rtt monitor when streaming is disabled
abr-egn 64c0140
disable dedicated rtt monitor when streaming is unsupported
abr-egn 96aa9ad
expose server monitoring mode in options/uri
abr-egn 404e6ed
sdam tests
abr-egn ad5026b
uri tests
abr-egn 82b77f2
lambda test
abr-egn d181481
revert unrelated readme change
abr-egn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ use super::{ | |
TopologyWatcher, | ||
}; | ||
use crate::{ | ||
client::options::ServerMonitoringMode, | ||
cmap::{establish::ConnectionEstablisher, Connection}, | ||
error::{Error, Result}, | ||
event::sdam::{ | ||
|
@@ -48,11 +49,15 @@ pub(crate) struct Monitor { | |
sdam_event_emitter: Option<SdamEventEmitter>, | ||
client_options: ClientOptions, | ||
|
||
/// Whether this monitor is allowed to use the streaming protocol. | ||
allow_streaming: bool, | ||
|
||
/// The most recent topology version returned by the server in a hello response. | ||
/// If some, indicates that this monitor should use the streaming protocol. If none, it should | ||
/// use the polling protocol. | ||
topology_version: Option<TopologyVersion>, | ||
|
||
/// The RTT monitor; once it's started this is None. | ||
pending_rtt_monitor: Option<RttMonitor>, | ||
|
||
/// Handle to the RTT monitor, used to get the latest known round trip time for a given server | ||
/// and to reset the RTT when the monitor disconnects from the server. | ||
rtt_monitor_handle: RttMonitorHandle, | ||
|
@@ -79,21 +84,31 @@ impl Monitor { | |
connection_establisher.clone(), | ||
client_options.clone(), | ||
); | ||
let allow_streaming = match client_options | ||
.server_monitoring_mode | ||
.clone() | ||
.unwrap_or(ServerMonitoringMode::Auto) | ||
{ | ||
ServerMonitoringMode::Stream => true, | ||
ServerMonitoringMode::Poll => false, | ||
ServerMonitoringMode::Auto => !crate::cmap::is_faas(), | ||
}; | ||
let monitor = Self { | ||
address, | ||
client_options, | ||
connection_establisher, | ||
topology_updater, | ||
topology_watcher, | ||
sdam_event_emitter, | ||
pending_rtt_monitor: Some(rtt_monitor), | ||
rtt_monitor_handle, | ||
request_receiver: manager_receiver, | ||
connection: None, | ||
allow_streaming, | ||
topology_version: None, | ||
}; | ||
|
||
runtime::execute(monitor.execute()); | ||
runtime::execute(rtt_monitor.execute()); | ||
} | ||
|
||
async fn execute(mut self) { | ||
|
@@ -102,13 +117,19 @@ impl Monitor { | |
while self.is_alive() { | ||
let check_succeeded = self.check_server().await; | ||
|
||
if self.topology_version.is_some() && self.allow_streaming { | ||
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. The spec changed from allowing drivers to use a dedicated RTT monitor even when polling to requiring that one not be used when polling, so starting up that task had to be deferred to the point where we know whether polling is happening or not. |
||
if let Some(rtt_monitor) = self.pending_rtt_monitor.take() { | ||
runtime::execute(rtt_monitor.execute()); | ||
} | ||
} | ||
|
||
// In the streaming protocol, we read from the socket continuously | ||
// rather than polling at specific intervals, unless the most recent check | ||
// failed. | ||
// | ||
// We only go to sleep when using the polling protocol (i.e. server never returned a | ||
// topologyVersion) or when the most recent check failed. | ||
if self.topology_version.is_none() || !check_succeeded { | ||
if self.topology_version.is_none() || !check_succeeded || !self.allow_streaming { | ||
self.request_receiver | ||
.wait_for_check_request( | ||
self.client_options.min_heartbeat_frequency(), | ||
|
@@ -180,7 +201,7 @@ impl Monitor { | |
self.emit_event(|| { | ||
SdamEvent::ServerHeartbeatStarted(ServerHeartbeatStartedEvent { | ||
server_address: self.address.clone(), | ||
awaited: self.topology_version.is_some(), | ||
awaited: self.topology_version.is_some() && self.allow_streaming, | ||
driver_connection_id, | ||
server_connection_id: self.connection.as_ref().and_then(|c| c.server_id), | ||
}) | ||
|
@@ -213,10 +234,14 @@ impl Monitor { | |
} else { | ||
// If the initial handshake returned a topology version, send it back to the | ||
// server to begin streaming responses. | ||
let opts = self.topology_version.map(|tv| AwaitableHelloOptions { | ||
topology_version: tv, | ||
max_await_time: heartbeat_frequency, | ||
}); | ||
let opts = if self.allow_streaming { | ||
self.topology_version.map(|tv| AwaitableHelloOptions { | ||
topology_version: tv, | ||
max_await_time: heartbeat_frequency, | ||
}) | ||
} else { | ||
None | ||
}; | ||
|
||
let command = hello_command( | ||
self.client_options.server_api.as_ref(), | ||
|
@@ -266,8 +291,12 @@ impl Monitor { | |
}; | ||
let duration = start.elapsed(); | ||
|
||
let awaited = self.topology_version.is_some() && self.allow_streaming; | ||
match result { | ||
HelloResult::Ok(ref r) => { | ||
if !awaited { | ||
self.rtt_monitor_handle.add_sample(duration); | ||
} | ||
self.emit_event(|| { | ||
let mut reply = r | ||
.raw_command_response | ||
|
@@ -280,7 +309,7 @@ impl Monitor { | |
duration, | ||
reply, | ||
server_address: self.address.clone(), | ||
awaited: self.topology_version.is_some(), | ||
awaited, | ||
driver_connection_id, | ||
server_connection_id: self.connection.as_ref().and_then(|c| c.server_id), | ||
}) | ||
|
@@ -296,7 +325,7 @@ impl Monitor { | |
duration, | ||
failure: e.clone(), | ||
server_address: self.address.clone(), | ||
awaited: self.topology_version.is_some(), | ||
awaited, | ||
driver_connection_id, | ||
server_connection_id: self.connection.as_ref().and_then(|c| c.server_id), | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Rather than setting
patchable: true
so this is included in the evergreen runs and then (forget to) change it back before submitting, I just did an independent run for that.