88use crate :: inventory:: ZoneType ;
99use crate :: omicron_zone_config:: { self , OmicronZoneNic } ;
1010use crate :: schema:: {
11- blueprint, bp_omicron_physical_disk, bp_omicron_zone, bp_omicron_zone_nic,
12- bp_sled_omicron_physical_disks, bp_sled_omicron_zones, bp_sled_state,
13- bp_target,
11+ blueprint, bp_clickhouse_cluster_config,
12+ bp_clickhouse_keeper_zone_id_to_node_id,
13+ bp_clickhouse_server_zone_id_to_node_id, bp_omicron_physical_disk,
14+ bp_omicron_zone, bp_omicron_zone_nic, bp_sled_omicron_physical_disks,
15+ bp_sled_omicron_zones, bp_sled_state, bp_target,
1416} ;
1517use crate :: typed_uuid:: DbTypedUuid ;
1618use crate :: {
@@ -19,6 +21,7 @@ use crate::{
1921} ;
2022use anyhow:: { anyhow, bail, Context , Result } ;
2123use chrono:: { DateTime , Utc } ;
24+ use clickhouse_admin_types:: { KeeperId , ServerId } ;
2225use ipnetwork:: IpNetwork ;
2326use nexus_sled_agent_shared:: inventory:: OmicronZoneDataset ;
2427use nexus_types:: deployment:: BlueprintTarget ;
@@ -27,7 +30,7 @@ use nexus_types::deployment::BlueprintZoneDisposition;
2730use nexus_types:: deployment:: BlueprintZonesConfig ;
2831use nexus_types:: deployment:: CockroachDbPreserveDowngrade ;
2932use nexus_types:: deployment:: {
30- blueprint_zone_type, BlueprintPhysicalDisksConfig ,
33+ blueprint_zone_type, BlueprintPhysicalDisksConfig , ClickhouseClusterConfig ,
3134} ;
3235use nexus_types:: deployment:: { BlueprintPhysicalDiskConfig , BlueprintZoneType } ;
3336use nexus_types:: deployment:: {
@@ -37,10 +40,10 @@ use nexus_types::deployment::{
3740use omicron_common:: api:: internal:: shared:: NetworkInterface ;
3841use omicron_common:: disk:: DiskIdentity ;
3942use omicron_common:: zpool_name:: ZpoolName ;
40- use omicron_uuid_kinds:: SledUuid ;
4143use omicron_uuid_kinds:: ZpoolUuid ;
4244use omicron_uuid_kinds:: { ExternalIpKind , SledKind , ZpoolKind } ;
4345use omicron_uuid_kinds:: { ExternalIpUuid , GenericUuid , OmicronZoneUuid } ;
46+ use omicron_uuid_kinds:: { OmicronZoneKind , SledUuid } ;
4447use std:: net:: { IpAddr , SocketAddrV6 } ;
4548use uuid:: Uuid ;
4649
@@ -803,6 +806,96 @@ impl From<BpOmicronZoneNic> for OmicronZoneNic {
803806 }
804807}
805808
809+ #[ derive( Queryable , Clone , Debug , Selectable , Insertable ) ]
810+ #[ diesel( table_name = bp_clickhouse_cluster_config) ]
811+ pub struct BpClickhouseClusterConfig {
812+ pub blueprint_id : Uuid ,
813+ pub generation : Generation ,
814+ pub max_used_server_id : i64 ,
815+ pub max_used_keeper_id : i64 ,
816+ pub cluster_name : String ,
817+ pub cluster_secret : String ,
818+ pub highest_seen_keeper_leader_committed_log_index : i64 ,
819+ }
820+
821+ impl BpClickhouseClusterConfig {
822+ pub fn new (
823+ blueprint_id : Uuid ,
824+ config : & ClickhouseClusterConfig ,
825+ ) -> anyhow:: Result < BpClickhouseClusterConfig > {
826+ Ok ( BpClickhouseClusterConfig {
827+ blueprint_id,
828+ generation : Generation ( config. generation ) ,
829+ max_used_server_id : config
830+ . max_used_server_id
831+ . 0
832+ . try_into ( )
833+ . context ( "more than 2^63 IDs in use" ) ?,
834+ max_used_keeper_id : config
835+ . max_used_keeper_id
836+ . 0
837+ . try_into ( )
838+ . context ( "more than 2^63 IDs in use" ) ?,
839+ cluster_name : config. cluster_name . clone ( ) ,
840+ cluster_secret : config. cluster_secret . clone ( ) ,
841+ highest_seen_keeper_leader_committed_log_index : config
842+ . highest_seen_keeper_leader_committed_log_index
843+ . try_into ( )
844+ . context ( "more than 2^63 IDs in use" ) ?,
845+ } )
846+ }
847+ }
848+
849+ #[ derive( Queryable , Clone , Debug , Selectable , Insertable ) ]
850+ #[ diesel( table_name = bp_clickhouse_keeper_zone_id_to_node_id) ]
851+ pub struct BpClickhouseKeeperZoneIdToNodeId {
852+ pub blueprint_id : Uuid ,
853+ pub omicron_zone_id : DbTypedUuid < OmicronZoneKind > ,
854+ pub keeper_id : i64 ,
855+ }
856+
857+ impl BpClickhouseKeeperZoneIdToNodeId {
858+ pub fn new (
859+ blueprint_id : Uuid ,
860+ omicron_zone_id : OmicronZoneUuid ,
861+ keeper_id : KeeperId ,
862+ ) -> anyhow:: Result < BpClickhouseKeeperZoneIdToNodeId > {
863+ Ok ( BpClickhouseKeeperZoneIdToNodeId {
864+ blueprint_id,
865+ omicron_zone_id : omicron_zone_id. into ( ) ,
866+ keeper_id : keeper_id
867+ . 0
868+ . try_into ( )
869+ . context ( "more than 2^63 IDs in use" ) ?,
870+ } )
871+ }
872+ }
873+
874+ #[ derive( Queryable , Clone , Debug , Selectable , Insertable ) ]
875+ #[ diesel( table_name = bp_clickhouse_server_zone_id_to_node_id) ]
876+ pub struct BpClickhouseServerZoneIdToNodeId {
877+ pub blueprint_id : Uuid ,
878+ pub omicron_zone_id : DbTypedUuid < OmicronZoneKind > ,
879+ pub server_id : i64 ,
880+ }
881+
882+ impl BpClickhouseServerZoneIdToNodeId {
883+ pub fn new (
884+ blueprint_id : Uuid ,
885+ omicron_zone_id : OmicronZoneUuid ,
886+ server_id : ServerId ,
887+ ) -> anyhow:: Result < BpClickhouseServerZoneIdToNodeId > {
888+ Ok ( BpClickhouseServerZoneIdToNodeId {
889+ blueprint_id,
890+ omicron_zone_id : omicron_zone_id. into ( ) ,
891+ server_id : server_id
892+ . 0
893+ . try_into ( )
894+ . context ( "more than 2^63 IDs in use" ) ?,
895+ } )
896+ }
897+ }
898+
806899mod diesel_util {
807900 use crate :: {
808901 schema:: bp_omicron_zone:: disposition, to_db_bp_zone_disposition,
0 commit comments