Skip to content

Commit

Permalink
Merge branch 'main' into clickhouse-native-qorb-pool
Browse files Browse the repository at this point in the history
  • Loading branch information
bnaecker committed Oct 17, 2024
2 parents 2f30751 + b21c915 commit 824291e
Show file tree
Hide file tree
Showing 18 changed files with 685 additions and 83 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ update-engine = { path = "update-engine" }
url = "2.5.2"
usdt = "0.5.0"
uuid = { version = "1.10.0", features = ["serde", "v4"] }
uzers = "0.11"
uzers = "0.12"
walkdir = "2.5"
whoami = "1.5"
wicket = { path = "wicket" }
Expand Down
6 changes: 5 additions & 1 deletion gateway-test-utils/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ pub async fn test_setup_with_config(
future::ready(result)
},
&Duration::from_millis(100),
&Duration::from_secs(1),
// This seems like a pretty long time to wait for MGS to discover the
// simulated SPs, but we've seen tests fail due to timeouts here in the
// past, so we may as well be generous:
// https://github.com/oxidecomputer/omicron/issues/6877
&Duration::from_secs(30),
)
.await
.unwrap();
Expand Down
111 changes: 111 additions & 0 deletions nexus/db-model/src/clickhouse_policy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! Database representation of a clickhouse deployment policy
use super::impl_enum_type;
use crate::SqlU32;
use crate::{schema::clickhouse_policy, SqlU8};
use chrono::{DateTime, Utc};
use nexus_types::deployment;
use serde::{Deserialize, Serialize};

impl_enum_type!(
#[derive(Clone, SqlType, Debug, QueryId)]
#[diesel(postgres_type(name = "clickhouse_mode", schema = "public"))]
pub struct ClickhouseModeEnum;

#[derive(Clone, Copy, Debug, AsExpression, FromSqlRow, Serialize, Deserialize, PartialEq)]
#[diesel(sql_type = ClickhouseModeEnum)]
pub enum DbClickhouseMode;

// Enum values
SingleNodeOnly => b"single_node_only"
ClusterOnly => b"cluster_only"
Both => b"both"
);

#[derive(Queryable, Clone, Debug, Selectable, Insertable)]
#[diesel(table_name = clickhouse_policy)]
pub struct ClickhousePolicy {
pub version: SqlU32,
pub clickhouse_mode: DbClickhouseMode,
pub clickhouse_cluster_target_servers: SqlU8,
pub clickhouse_cluster_target_keepers: SqlU8,
pub time_created: DateTime<Utc>,
}

impl From<&deployment::ClickhouseMode> for DbClickhouseMode {
fn from(value: &deployment::ClickhouseMode) -> Self {
match value {
deployment::ClickhouseMode::SingleNodeOnly => {
DbClickhouseMode::SingleNodeOnly
}
deployment::ClickhouseMode::ClusterOnly { .. } => {
DbClickhouseMode::ClusterOnly
}
deployment::ClickhouseMode::Both { .. } => DbClickhouseMode::Both,
}
}
}

impl From<ClickhousePolicy> for deployment::ClickhousePolicy {
fn from(value: ClickhousePolicy) -> Self {
let mode = match value.clickhouse_mode {
DbClickhouseMode::SingleNodeOnly => {
deployment::ClickhouseMode::SingleNodeOnly
}
DbClickhouseMode::ClusterOnly => {
deployment::ClickhouseMode::ClusterOnly {
target_servers: value.clickhouse_cluster_target_servers.0,
target_keepers: value.clickhouse_cluster_target_keepers.0,
}
}
DbClickhouseMode::Both => deployment::ClickhouseMode::Both {
target_servers: value.clickhouse_cluster_target_servers.0,
target_keepers: value.clickhouse_cluster_target_keepers.0,
},
};

deployment::ClickhousePolicy {
version: value.version.0,
mode,
time_created: value.time_created,
}
}
}

impl From<deployment::ClickhousePolicy> for ClickhousePolicy {
fn from(value: deployment::ClickhousePolicy) -> Self {
match value.mode {
deployment::ClickhouseMode::SingleNodeOnly => ClickhousePolicy {
version: value.version.into(),
clickhouse_mode: DbClickhouseMode::SingleNodeOnly,
clickhouse_cluster_target_servers: 0.into(),
clickhouse_cluster_target_keepers: 0.into(),
time_created: value.time_created,
},
deployment::ClickhouseMode::ClusterOnly {
target_servers,
target_keepers,
} => ClickhousePolicy {
version: value.version.into(),
clickhouse_mode: DbClickhouseMode::ClusterOnly,
clickhouse_cluster_target_servers: target_servers.into(),
clickhouse_cluster_target_keepers: target_keepers.into(),
time_created: value.time_created,
},
deployment::ClickhouseMode::Both {
target_servers,
target_keepers,
} => ClickhousePolicy {
version: value.version.into(),
clickhouse_mode: DbClickhouseMode::Both,
clickhouse_cluster_target_servers: target_servers.into(),
clickhouse_cluster_target_keepers: target_keepers.into(),
time_created: value.time_created,
},
}
}
}
2 changes: 2 additions & 0 deletions nexus/db-model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod block_size;
mod bootstore;
mod bytecount;
mod certificate;
mod clickhouse_policy;
mod cockroachdb_node_id;
mod collection;
mod console_session;
Expand Down Expand Up @@ -133,6 +134,7 @@ pub use block_size::*;
pub use bootstore::*;
pub use bytecount::*;
pub use certificate::*;
pub use clickhouse_policy::*;
pub use cockroachdb_node_id::*;
pub use collection::*;
pub use console_session::*;
Expand Down
10 changes: 10 additions & 0 deletions nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,16 @@ table! {
}
}

table! {
clickhouse_policy (version) {
version -> Int8,
clickhouse_mode -> crate::clickhouse_policy::ClickhouseModeEnum,
clickhouse_cluster_target_servers -> Int2,
clickhouse_cluster_target_keepers -> Int2,
time_created -> Timestamptz,
}
}

table! {
rack (id) {
id -> Uuid,
Expand Down
3 changes: 2 additions & 1 deletion nexus/db-model/src/schema_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::collections::BTreeMap;
///
/// This must be updated when you change the database schema. Refer to
/// schema/crdb/README.adoc in the root of this repository for details.
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(109, 0, 0);
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(110, 0, 0);

/// List of all past database schema versions, in *reverse* order
///
Expand All @@ -29,6 +29,7 @@ static KNOWN_VERSIONS: Lazy<Vec<KnownVersion>> = Lazy::new(|| {
// | leaving the first copy as an example for the next person.
// v
// KnownVersion::new(next_int, "unique-dirname-with-the-sql-files"),
KnownVersion::new(110, "clickhouse-policy"),
KnownVersion::new(109, "inv-clickhouse-keeper-membership"),
KnownVersion::new(108, "internet-gateway"),
KnownVersion::new(107, "add-instance-boot-disk"),
Expand Down
Loading

0 comments on commit 824291e

Please sign in to comment.