Skip to content

Commit

Permalink
fix: dual mode needs its own spawn_sweeper (#658)
Browse files Browse the repository at this point in the history
Issue: SYNC-4176
  • Loading branch information
pjenvey committed Mar 18, 2024
1 parent 293ff3a commit 1b4d5a9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 5 additions & 1 deletion autoconnect/autoconnect-settings/src/app_state.rs
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion autoendpoint/src/server.rs
Expand Up @@ -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(
Expand Down
8 changes: 6 additions & 2 deletions autopush-common/src/db/dual/mod.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1b4d5a9

Please sign in to comment.