@@ -3,7 +3,6 @@ use std::{
33 borrow:: Cow ,
44 collections:: { BTreeMap , HashMap } ,
55 hash:: Hasher ,
6- str:: FromStr ,
76 sync:: Arc ,
87} ;
98
@@ -16,10 +15,10 @@ use product_config::{
1615} ;
1716use snafu:: { OptionExt , ResultExt , Snafu } ;
1817use stackable_hive_crd:: {
19- Container , DbType , HiveCluster , HiveClusterStatus , HiveRole , MetaStoreConfig , APP_NAME ,
20- CORE_SITE_XML , DB_PASSWORD_ENV , DB_USERNAME_ENV , HADOOP_HEAPSIZE , HIVE_ENV_SH , HIVE_PORT ,
21- HIVE_PORT_NAME , HIVE_SITE_XML , JVM_HEAP_FACTOR , JVM_SECURITY_PROPERTIES_FILE , METRICS_PORT ,
22- METRICS_PORT_NAME , STACKABLE_CONFIG_DIR , STACKABLE_CONFIG_DIR_NAME , STACKABLE_CONFIG_MOUNT_DIR ,
18+ Container , HiveCluster , HiveClusterStatus , HiveRole , MetaStoreConfig , APP_NAME , CORE_SITE_XML ,
19+ DB_PASSWORD_ENV , DB_USERNAME_ENV , HADOOP_HEAPSIZE , HIVE_ENV_SH , HIVE_PORT , HIVE_PORT_NAME ,
20+ HIVE_SITE_XML , JVM_HEAP_FACTOR , JVM_SECURITY_PROPERTIES_FILE , METRICS_PORT , METRICS_PORT_NAME ,
21+ STACKABLE_CONFIG_DIR , STACKABLE_CONFIG_DIR_NAME , STACKABLE_CONFIG_MOUNT_DIR ,
2322 STACKABLE_CONFIG_MOUNT_DIR_NAME , STACKABLE_LOG_CONFIG_MOUNT_DIR ,
2423 STACKABLE_LOG_CONFIG_MOUNT_DIR_NAME , STACKABLE_LOG_DIR , STACKABLE_LOG_DIR_NAME ,
2524} ;
@@ -188,12 +187,6 @@ pub enum Error {
188187 source : stackable_operator:: client:: Error ,
189188 } ,
190189
191- #[ snafu( display( "failed to parse db type {db_type}" ) ) ]
192- InvalidDbType {
193- source : strum:: ParseError ,
194- db_type : String ,
195- } ,
196-
197190 #[ snafu( display( "failed to configure S3 connection" ) ) ]
198191 ConfigureS3 { source : S3Error } ,
199192
@@ -828,36 +821,25 @@ fn build_metastore_rolegroup_statefulset(
828821 . rolegroup ( rolegroup_ref)
829822 . context ( InternalOperatorSnafu ) ?;
830823
831- let mut db_type: Option < DbType > = None ;
832824 let mut container_builder =
833825 ContainerBuilder :: new ( APP_NAME ) . context ( FailedToCreateHiveContainerSnafu {
834826 name : APP_NAME . to_string ( ) ,
835827 } ) ?;
836828
837829 for ( property_name_kind, config) in metastore_config {
838- match property_name_kind {
839- PropertyNameKind :: Env => {
840- // overrides
841- for ( property_name, property_value) in config {
842- if property_name. is_empty ( ) {
843- warn ! ( "Received empty property_name for ENV... skipping" ) ;
844- continue ;
845- }
846- container_builder. add_env_var ( property_name, property_value) ;
847- }
848- }
849- PropertyNameKind :: Cli => {
850- for ( property_name, property_value) in config {
851- if property_name == MetaStoreConfig :: DB_TYPE_CLI {
852- db_type = Some ( DbType :: from_str ( property_value) . with_context ( |_| {
853- InvalidDbTypeSnafu {
854- db_type : property_value. to_string ( ) ,
855- }
856- } ) ?) ;
857- }
830+ if property_name_kind == & PropertyNameKind :: Env {
831+ // overrides
832+ for ( property_name, property_value) in config {
833+ if property_name. is_empty ( ) {
834+ warn ! (
835+ property_name,
836+ property_value,
837+ "The env variable had an empty name, not adding it to the container"
838+ ) ;
839+ continue ;
858840 }
841+ container_builder. add_env_var ( property_name, property_value) ;
859842 }
860- _ => { }
861843 }
862844 }
863845
@@ -894,6 +876,26 @@ fn build_metastore_rolegroup_statefulset(
894876 }
895877 }
896878
879+ let db_type = hive. db_type ( ) ;
880+ let start_command = if resolved_product_image. product_version . starts_with ( "3." ) {
881+ // The schematool version in 3.1.x does *not* support the `-initOrUpgradeSchema` flag yet, so we can not use that.
882+ // As we *only* support HMS 3.1.x (or newer) since SDP release 23.11, we can safely assume we are always coming
883+ // from an existing 3.1.x installation. There is no need to upgrade the schema, we can just check if the schema
884+ // is already there and create it if it isn't.
885+ // The script `bin/start-metastore` is buggy (e.g. around version upgrades), but it's sufficient for that job :)
886+ //
887+ // TODO: Once we drop support for HMS 3.1.x we can remove this condition and very likely get rid of the
888+ // "bin/start-metastore" script.
889+ format ! ( "bin/start-metastore --config {STACKABLE_CONFIG_DIR} --db-type {db_type} --hive-bin-dir bin &" )
890+ } else {
891+ // schematool versions 4.0.x (and above) support the `-initOrUpgradeSchema`, which is exactly what we need :)
892+ // Some docs for the schemaTool can be found here: https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=34835119
893+ formatdoc ! { "
894+ bin/base --config \" {STACKABLE_CONFIG_DIR}\" --service schemaTool -dbType \" {db_type}\" -initOrUpgradeSchema
895+ bin/base --config \" {STACKABLE_CONFIG_DIR}\" --service metastore &
896+ " }
897+ } ;
898+
897899 let container_builder = container_builder
898900 . image_from_product_image ( resolved_product_image)
899901 . command ( vec ! [
@@ -905,23 +907,22 @@ fn build_metastore_rolegroup_statefulset(
905907 ] )
906908 . args ( build_container_command_args (
907909 hive,
908- formatdoc ! { "
910+ formatdoc ! { "
909911 {kerberos_container_start_commands}
910912
911913 {COMMON_BASH_TRAP_FUNCTIONS}
912914 {remove_vector_shutdown_file_command}
913915 prepare_signal_handlers
914- bin/start-metastore --config {STACKABLE_CONFIG_DIR} --db-type {db_type} --hive-bin-dir bin &
916+ {start_command}
915917 wait_for_termination $!
916918 {create_vector_shutdown_file_command}
917919 " ,
918- kerberos_container_start_commands = kerberos_container_start_commands( hive) ,
919- remove_vector_shutdown_file_command =
920- remove_vector_shutdown_file_command( STACKABLE_LOG_DIR ) ,
921- create_vector_shutdown_file_command =
922- create_vector_shutdown_file_command( STACKABLE_LOG_DIR ) ,
923- db_type = & db_type. unwrap_or_default( ) . to_string( ) ,
924- } ,
920+ kerberos_container_start_commands = kerberos_container_start_commands( hive) ,
921+ remove_vector_shutdown_file_command =
922+ remove_vector_shutdown_file_command( STACKABLE_LOG_DIR ) ,
923+ create_vector_shutdown_file_command =
924+ create_vector_shutdown_file_command( STACKABLE_LOG_DIR ) ,
925+ } ,
925926 s3_connection,
926927 ) )
927928 . add_volume_mount ( STACKABLE_CONFIG_DIR_NAME , STACKABLE_CONFIG_DIR )
0 commit comments