Fix subtraction overflow in metrics (#14290)

This commit is contained in:
sakridge 2020-12-27 16:26:22 -08:00 committed by GitHub
parent 7b49c85aa7
commit c693ffaa08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

View File

@ -347,7 +347,7 @@ fn update_peer_stats(
) { ) {
let now = timestamp(); let now = timestamp();
let last = last_datapoint_submit.load(Ordering::Relaxed); let last = last_datapoint_submit.load(Ordering::Relaxed);
if now - last > 1000 if now.saturating_sub(last) > 1000
&& last_datapoint_submit.compare_and_swap(last, now, Ordering::Relaxed) == last && last_datapoint_submit.compare_and_swap(last, now, Ordering::Relaxed) == last
{ {
datapoint_info!( datapoint_info!(

View File

@ -117,7 +117,9 @@ fn update_retransmit_stats(
let now = timestamp(); let now = timestamp();
let last = stats.last_ts.load(Ordering::Relaxed); let last = stats.last_ts.load(Ordering::Relaxed);
if now - last > 2000 && stats.last_ts.compare_and_swap(last, now, Ordering::Relaxed) == last { if now.saturating_sub(last) > 2000
&& stats.last_ts.compare_and_swap(last, now, Ordering::Relaxed) == last
{
datapoint_info!("retransmit-num_nodes", ("count", peers_len, i64)); datapoint_info!("retransmit-num_nodes", ("count", peers_len, i64));
datapoint_info!( datapoint_info!(
"retransmit-stage", "retransmit-stage",
@ -288,7 +290,8 @@ fn retransmit(
let now = timestamp(); let now = timestamp();
let last = last_peer_update.load(Ordering::Relaxed); let last = last_peer_update.load(Ordering::Relaxed);
if now - last > 1000 && last_peer_update.compare_and_swap(last, now, Ordering::Relaxed) == last if now.saturating_sub(last) > 1000
&& last_peer_update.compare_and_swap(last, now, Ordering::Relaxed) == last
{ {
drop(r_epoch_stakes_cache); drop(r_epoch_stakes_cache);
let mut w_epoch_stakes_cache = epoch_stakes_cache.write().unwrap(); let mut w_epoch_stakes_cache = epoch_stakes_cache.write().unwrap();

View File

@ -2723,7 +2723,7 @@ impl AccountsDB {
fn report_store_timings(&self) { fn report_store_timings(&self) {
let last = self.stats.last_store_report.load(Ordering::Relaxed); let last = self.stats.last_store_report.load(Ordering::Relaxed);
let now = solana_sdk::timing::timestamp(); let now = solana_sdk::timing::timestamp();
if now - last > 1000 if now.saturating_sub(last) > 1000
&& self && self
.stats .stats
.last_store_report .last_store_report