From 1b4d5a9afa2535f0b7c9edd19756efe4b5f16622 Mon Sep 17 00:00:00 2001 From: Philip Jenvey Date: Mon, 18 Mar 2024 16:12:24 -0700 Subject: [PATCH] fix: dual mode needs its own spawn_sweeper (#658) Issue: SYNC-4176 --- autoconnect/autoconnect-settings/src/app_state.rs | 6 +++++- autoendpoint/src/server.rs | 6 +++++- autopush-common/src/db/dual/mod.rs | 8 ++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/autoconnect/autoconnect-settings/src/app_state.rs b/autoconnect/autoconnect-settings/src/app_state.rs index c91315dc..67c902f1 100644 --- a/autoconnect/autoconnect-settings/src/app_state.rs +++ b/autoconnect/autoconnect-settings/src/app_state.rs @@ -86,7 +86,11 @@ impl AppState { Box::new(client) } #[cfg(all(feature = "bigtable", feature = "dynamodb"))] - StorageType::Dual => Box::new(DualClientImpl::new(metrics.clone(), &db_settings)?), + StorageType::Dual => { + let client = DualClientImpl::new(metrics.clone(), &db_settings)?; + client.spawn_sweeper(Duration::from_secs(30)); + Box::new(client) + } _ => panic!( "Invalid Storage type {:?}. Check {}__DB_DSN.", storage_type, diff --git a/autoendpoint/src/server.rs b/autoendpoint/src/server.rs index 5c51a9f3..75a9f40d 100644 --- a/autoendpoint/src/server.rs +++ b/autoendpoint/src/server.rs @@ -80,7 +80,11 @@ impl Server { Box::new(client) } #[cfg(all(feature = "bigtable", feature = "dual"))] - StorageType::Dual => Box::new(DualClientImpl::new(metrics.clone(), &db_settings)?), + StorageType::Dual => { + let client = DualClientImpl::new(metrics.clone(), &db_settings)?; + client.spawn_sweeper(Duration::from_secs(30)); + Box::new(client) + } _ => { debug!("No idea what {:?} is", &db_settings.dsn); return Err(ApiErrorKind::General( diff --git a/autopush-common/src/db/dual/mod.rs b/autopush-common/src/db/dual/mod.rs index 3fd104e9..accc8c6c 100644 --- a/autopush-common/src/db/dual/mod.rs +++ b/autopush-common/src/db/dual/mod.rs @@ -6,8 +6,7 @@ //! //! This requires both the `dynamodb` and `bigtable` features. //! -use std::collections::HashSet; -use std::sync::Arc; +use std::{collections::HashSet, sync::Arc, time::Duration}; use async_trait::async_trait; use cadence::{CountedExt, StatsdClient, Timed}; @@ -114,6 +113,11 @@ impl DualClientImpl { metrics, }) } + + /// Spawn a task to periodically evict idle Bigtable connections + pub fn spawn_sweeper(&self, interval: Duration) { + self.primary.spawn_sweeper(interval); + } } /// Wrapper functions to allow us to change which data store system actually manages the