-
Notifications
You must be signed in to change notification settings - Fork 231
Health check delay #118
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
Merged
Merged
Health check delay #118
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c5ca61f
initial commit of server check delay implementation
zainkabani d999c93
fmt
zainkabani d3c9d62
spelling
zainkabani 4641a57
Update name to last_healthcheck and some comments
zainkabani 49883fb
Moved server tested stat to after require_healthcheck check
zainkabani bc67a79
Make health check delay configurable
zainkabani 5381e59
Rename to last_activity
zainkabani db6fa6c
Fix typo
zainkabani d1d5465
Add debug log for healthcheck
zainkabani f56a636
Add address to debug log
zainkabani 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -251,7 +251,7 @@ impl ConnectionPool { | |
|
||
/// Get a connection from the pool. | ||
pub async fn get( | ||
&mut self, | ||
&self, | ||
shard: usize, // shard number | ||
role: Option<Role>, // primary or replica | ||
process_id: i32, // client id | ||
|
@@ -283,6 +283,9 @@ impl ConnectionPool { | |
return Err(Error::BadConfig); | ||
} | ||
|
||
let healthcheck_timeout = get_config().general.healthcheck_timeout; | ||
let healthcheck_delay = get_config().general.healthcheck_delay as u128; | ||
|
||
while allowed_attempts > 0 { | ||
// Round-robin replicas. | ||
round_robin += 1; | ||
|
@@ -312,7 +315,7 @@ impl ConnectionPool { | |
Ok(conn) => conn, | ||
Err(err) => { | ||
error!("Banning replica {}, error: {:?}", index, err); | ||
self.ban(address, shard); | ||
self.ban(address, shard, process_id); | ||
self.stats.client_disconnecting(process_id, address.id); | ||
self.stats | ||
.checkout_time(now.elapsed().as_micros(), process_id, address.id); | ||
|
@@ -322,8 +325,19 @@ impl ConnectionPool { | |
|
||
// // Check if this server is alive with a health check. | ||
let server = &mut *conn; | ||
let healthcheck_timeout = get_config().general.healthcheck_timeout; | ||
|
||
// Will return error if timestamp is greater than current system time, which it should never be set to | ||
let require_healthcheck = | ||
server.last_activity().elapsed().unwrap().as_millis() > healthcheck_delay; | ||
|
||
if !require_healthcheck { | ||
self.stats | ||
.checkout_time(now.elapsed().as_micros(), process_id, address.id); | ||
self.stats.server_idle(conn.process_id(), address.id); | ||
return Ok((conn, address.clone())); | ||
} | ||
|
||
debug!("Running health check for replica {}, {:?}", index, address); | ||
self.stats.server_tested(server.process_id(), address.id); | ||
|
||
match tokio::time::timeout( | ||
|
@@ -348,10 +362,7 @@ impl ConnectionPool { | |
// Don't leave a bad connection in the pool. | ||
server.mark_bad(); | ||
|
||
self.ban(address, shard); | ||
self.stats.client_disconnecting(process_id, address.id); | ||
self.stats | ||
.checkout_time(now.elapsed().as_micros(), process_id, address.id); | ||
self.ban(address, shard, process_id); | ||
continue; | ||
} | ||
}, | ||
|
@@ -362,10 +373,7 @@ impl ConnectionPool { | |
// Don't leave a bad connection in the pool. | ||
server.mark_bad(); | ||
|
||
self.ban(address, shard); | ||
self.stats.client_disconnecting(process_id, address.id); | ||
self.stats | ||
.checkout_time(now.elapsed().as_micros(), process_id, address.id); | ||
self.ban(address, shard, process_id); | ||
continue; | ||
} | ||
} | ||
|
@@ -377,7 +385,11 @@ impl ConnectionPool { | |
/// Ban an address (i.e. replica). It no longer will serve | ||
/// traffic for any new transactions. Existing transactions on that replica | ||
/// will finish successfully or error out to the clients. | ||
pub fn ban(&self, address: &Address, shard: usize) { | ||
pub fn ban(&self, address: &Address, shard: usize, process_id: i32) { | ||
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. It's hard to explain why |
||
self.stats.client_disconnecting(process_id, address.id); | ||
self.stats | ||
.checkout_time(Instant::now().elapsed().as_micros(), process_id, address.id); | ||
|
||
error!("Banning {:?}", address); | ||
let now = chrono::offset::Utc::now().naive_utc(); | ||
let mut guard = self.banlist.write(); | ||
|
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.
Could you add a
debug!
a little bit above so we know that the health check is still being performed? It's nice to trace the execution of things when debugging things. I tend to organize the log levels as follows:info
: good to know under normal operations, e.g. client connected, client disconnected, etc.warn
: need to know, something might be wrong.debug
: good to know if I'm trying to understand what's really happening underneath.trace
: I need to see almost every interaction and byte going through because I think something is terribly wrong.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.
So right above it there's already an error! log which says the replica is being banned. Does that work?
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 was referring to the health check being issued, not the ban, but GitHub doesn't let me comment on random file lines i think.
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.
Now that we don't always health check i think it's important to log when we do.