66import traceback
77from collections import defaultdict
88from pathlib import Path
9+ import uuid
910
1011from ci .praktika import Secret
1112from ci .praktika .info import Info
@@ -248,6 +249,9 @@ def start_light(self):
248249 print (f"ClickHouse server ready" )
249250 else :
250251 print (f"ClickHouse server NOT ready" )
252+
253+ self ._flush_system_logs ()
254+ self .save_system_metadata_files_from_remote_database_disk ()
251255 return res
252256
253257 def install_clickbench_config (self ):
@@ -482,6 +486,9 @@ def start(self, replica_num=0):
482486 if self .is_db_replicated and replica_num == 0 :
483487 res = self .start (replica_num = 1 ) and self .start (replica_num = 2 )
484488
489+ self ._flush_system_logs ()
490+ self .save_system_metadata_files_from_remote_database_disk ()
491+
485492 return res
486493
487494 def create_minio_log_tables (self ):
@@ -692,27 +699,35 @@ def terminate(self):
692699
693700 return self
694701
695- def prepare_logs (self , all = False ):
696- res = self ._get_logs_archives_server ()
697- res += self ._get_jemalloc_profiles ()
698- if Path (self .GDB_LOG ).exists ():
699- res .append (self .GDB_LOG )
700- if all :
701- res += self .debug_artifacts
702- res += self .dump_system_tables ()
703- res += self ._collect_core_dumps ()
704- res += self ._get_logs_archive_coordination ()
705- if Path (self .MINIO_LOG ).exists ():
706- res .append (self .MINIO_LOG )
707- if Path (self .AZURITE_LOG ).exists ():
708- res .append (self .AZURITE_LOG )
709- if Path (self .DMESG_LOG ).exists ():
710- res .append (self .DMESG_LOG )
711- if Path (self .CH_LOCAL_ERR_LOG ).exists ():
712- res .append (self .CH_LOCAL_ERR_LOG )
713- if Path (self .CH_LOCAL_LOG ).exists ():
714- res .append (self .CH_LOCAL_LOG )
715- self .logs = res
702+ def prepare_logs (self , info , all = False ):
703+ res = []
704+ try :
705+ res = self ._get_logs_archives_server ()
706+ res += self ._get_jemalloc_profiles ()
707+ if Path (self .GDB_LOG ).exists ():
708+ res .append (self .GDB_LOG )
709+ if all :
710+ res += self .debug_artifacts
711+ res += self .dump_system_tables ()
712+ res += self ._collect_core_dumps ()
713+ res += self ._get_logs_archive_coordination ()
714+ if Path (self .MINIO_LOG ).exists ():
715+ res .append (self .MINIO_LOG )
716+ if Path (self .AZURITE_LOG ).exists ():
717+ res .append (self .AZURITE_LOG )
718+ if Path (self .DMESG_LOG ).exists ():
719+ res .append (self .DMESG_LOG )
720+ if Path (self .CH_LOCAL_ERR_LOG ).exists ():
721+ res .append (self .CH_LOCAL_ERR_LOG )
722+ if Path (self .CH_LOCAL_LOG ).exists ():
723+ res .append (self .CH_LOCAL_LOG )
724+ self .logs = res
725+ except Exception as e :
726+ print (f"WARNING: Failed to collect logs: { e } " )
727+ traceback .print_exc ()
728+ info .add_workflow_report_message (
729+ f"Failed to collect all logs in job [{ info .job_name } ], ex [{ e } ], see job.log"
730+ )
716731 return res
717732
718733 def _collect_core_dumps (self ):
@@ -1052,23 +1067,41 @@ def dump_system_tables(self):
10521067 res = False
10531068 return [f for f in glob .glob (f"{ temp_dir } /system_tables/*.tsv" )]
10541069
1070+ @staticmethod
1071+ def is_valid_uuid (val ):
1072+ try :
1073+ uuid_obj = uuid .UUID (val )
1074+ return str (uuid_obj ) == val .lower ()
1075+ except ValueError :
1076+ return False
1077+
10551078 def save_system_metadata_files_from_remote_database_disk (self ):
10561079 if not os .path .exists (
10571080 "/etc/clickhouse-server/config.d/remote_database_disk.xml"
10581081 ):
10591082 return
10601083
10611084 # Store system database and table metadata files
1062- self . system_db_uuid = Shell .get_output (
1085+ system_db_uuid = Shell .get_output (
10631086 "clickhouse disks -C /etc/clickhouse-server/config.xml --disk disk_db_remote -q 'read metadata/system.sql' | grep -F UUID | awk -F\" '\" '{print $2}'" ,
10641087 verbose = True ,
10651088 )
1089+ if not self .is_valid_uuid (system_db_uuid ):
1090+ print (f"invalid system_db_uuid: '{ system_db_uuid } '" )
1091+ return
1092+
1093+ if self .system_db_uuid != None and self .system_db_uuid != system_db_uuid :
1094+ print (
1095+ f"system_db_uuid changed: '{ self .system_db_uuid } ' -> '{ system_db_uuid } '"
1096+ )
1097+
1098+ self .system_db_uuid = system_db_uuid
10661099 self .system_db_sql = Shell .get_output (
10671100 "clickhouse disks -C /etc/clickhouse-server/config.xml --disk disk_db_remote -q 'read metadata/system.sql'" ,
10681101 verbose = True ,
10691102 )
1070- print (f"system_db_uuid = { self .system_db_uuid } " )
1071- print (f"system_db_sql = { self .system_db_sql } " )
1103+ print (f"system_db_uuid = ' { self .system_db_uuid } ' " )
1104+ print (f"system_db_sql = ' { self .system_db_sql } ' " )
10721105
10731106 system_table_sql_files = (
10741107 Shell .get_output (
@@ -1080,6 +1113,7 @@ def save_system_metadata_files_from_remote_database_disk(self):
10801113 )
10811114 self .system_table_sql_map = {}
10821115 for system_table_sql_file in system_table_sql_files :
1116+ print (f"system_table_sql_file = '{ system_table_sql_file } '" )
10831117 sql_content = Shell .get_output (
10841118 f"clickhouse disks -C /etc/clickhouse-server/config.xml --disk disk_db_remote -q 'read store/{ self .system_db_uuid [:3 ]} /{ self .system_db_uuid } /{ system_table_sql_file } '" ,
10851119 verbose = True ,
@@ -1097,7 +1131,7 @@ def restore_system_metadata_files_from_remote_database_disk(self):
10971131 # Restore system database and table metadata files for `clickhouse local`
10981132 with open (f"{ self .run_path0 } /metadata/system.sql" , "w" ) as file :
10991133 file .write (self .system_db_sql )
1100- res = Shell .check (
1134+ Shell .check (
11011135 f"mkdir -p { self .run_path0 } /store/{ self .system_db_uuid [:3 ]} /{ self .system_db_uuid } " ,
11021136 verbose = True ,
11031137 )
0 commit comments