Skip to content

Commit

Permalink
feat: support dual mode data storage (#369)
Browse files Browse the repository at this point in the history
* feat: support dual mode data storage

Allow for dual mode, where data is written to the primary, but the
secondary is read in order to 'back fill'. For simplicity, Dual presumes
that the primary data store is Bigtable and the secondary is DynamoDb.

This presumes that the `db_settings` contains serialized settings for
both data stores.

* add flag to write to secondary (default true)

This flag makes writing to the secondary an active feature. This is
required due to the potential for clients to be arbitrarily assigned to
the dual mode storage or the older single mode storage. This flag is set
to `true` as the default since we want both data stores active until we
have sufficient cross coverage.


Closes: SYNC-3452
  • Loading branch information
jrconlin authored Dec 2, 2023
1 parent 53b6f03 commit 6624a19
Show file tree
Hide file tree
Showing 11 changed files with 377 additions and 60 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
audit:
docker:
# NOTE: update version for all # RUST_VER
- image: rust:1.72
- image: rust:1.73
auth:
username: $DOCKER_USER
password: $DOCKER_PASS
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
apt install build-essential curl libstdc++6 libstdc++-10-dev libssl-dev pkg-config -y
apt install cmake -y
# RUST_VER
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain 1.72 -y
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain 1.73 -y
export PATH=$PATH:$HOME/.cargo/bin
echo 'export PATH=$PATH:$HOME/.cargo/bin' >> $BASH_ENV
rustc --version
Expand Down
62 changes: 31 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ edition = "2021"
# ideally, this would contain any crates that are shared between crates.
# there are some lingering code interdependencies that prevent that, but it should
# remain a goal for the overall refactor.

actix = "0.13"
actix-cors = "0.6"
actix-http = "3.2"
Expand Down Expand Up @@ -112,7 +113,10 @@ autoconnect_settings = { path = "./autoconnect/autoconnect-settings" }
autoconnect_web = { path = "./autoconnect/autoconnect-web" }
autoconnect_ws = { path = "./autoconnect/autoconnect-ws" }
autoconnect_ws_clientsm = { path = "./autoconnect/autoconnect-ws/autoconnect-ws-clientsm" }
autopush_common = { path = "./autopush-common", features = ["bigtable"] }
autopush_common = { path = "./autopush-common", features = [
"dynamodb",
"bigtable",
] }

[profile.release]
debug = 1
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# NOTE: Ensure builder's Rust version matches CI's in .circleci/config.yml
FROM rust:1.72-buster as builder
FROM rust:1.73-buster as builder
ARG CRATE

ADD . /app
Expand Down
10 changes: 8 additions & 2 deletions autoendpoint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ tokio.workspace = true
url.workspace = true
uuid.workspace = true

a2 = {version = "0.8", git = "https://github.com/mozilla-services/a2", branch="master"}
a2 = { version = "0.8", git = "https://github.com/mozilla-services/a2", branch = "master" }
bytebuffer = "2.1"
again = { version = "0.1.2", default-features = false, features = ["log", "rand"] }
again = { version = "0.1.2", default-features = false, features = [
"log",
"rand",
] }
async-trait = "0.1"
autopush_common = { path = "../autopush-common" }
jsonwebtoken = "8.0"
Expand All @@ -64,5 +67,8 @@ tempfile = "3.2.0"
tokio = { workspace = true, features = ["fs", "macros"] }

[features]
default = ["dynamodb"]
dynamodb = ["autopush_common/dynamodb"]
emulator = ["bigtable"]
dual = ["bigtable", "dynamodb"]
bigtable = ["autopush_common/bigtable"]
10 changes: 9 additions & 1 deletion autoendpoint/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ use actix_web::{
};
#[cfg(feature = "bigtable")]
use autopush_common::db::bigtable::BigTableClientImpl;
#[cfg(feature = "dual")]
use autopush_common::db::dual::DualClientImpl;
use cadence::StatsdClient;
use fernet::MultiFernet;
use serde_json::json;

#[cfg(feature = "dynamodb")]
use autopush_common::db::dynamodb::DdbClientImpl;

use autopush_common::{
db::{client::DbClient, dynamodb::DdbClientImpl, DbSettings, StorageType},
db::{client::DbClient, DbSettings, StorageType},
middleware::sentry::SentryWrapper,
};

Expand Down Expand Up @@ -63,6 +68,7 @@ impl Server {
},
};
let db: Box<dyn DbClient> = match StorageType::from_dsn(&db_settings.dsn) {
#[cfg(feature = "dynamodb")]
StorageType::DynamoDb => {
debug!("Using Dynamodb");
Box::new(DdbClientImpl::new(metrics.clone(), &db_settings)?)
Expand All @@ -72,6 +78,8 @@ impl Server {
debug!("Using BigTable");
Box::new(BigTableClientImpl::new(metrics.clone(), &db_settings)?)
}
#[cfg(all(feature = "bigtable", feature = "dual"))]
StorageType::Dual => Box::new(DualClientImpl::new(metrics.clone(), &db_settings)?),
_ => {
debug!("No idea what {:?} is", &db_settings.dsn);
return Err(ApiErrorKind::General(
Expand Down
Loading

0 comments on commit 6624a19

Please sign in to comment.