Skip to content

Commit

Permalink
Tuned the delete log functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenrong-wang committed Oct 16, 2024
1 parent b56b1b6 commit 7c39ca6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 20 deletions.
25 changes: 23 additions & 2 deletions hpcopr/cluster_general_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -4856,14 +4856,24 @@ int tf_test(char* cluster_name, char* cloud_flag, char* cloud_ak, char* cloud_sk
int64_t delete_logs(char* cluster_name){
int64_t file_size=0;
if(cluster_name==NULL||strlen(cluster_name)==0){
printf(GENERAL_BOLD "\n[ -INFO- ]" RESET_DISPLAY " Deleting the log trashbin under %s ...\n", NOW_LOG_DIR);
char logfile[FILENAME_LENGTH]="";
snprintf(logfile,FILENAME_LENGTH,"%s%slog_trashbin.txt",NOW_LOG_DIR,PATH_SLASH);
file_size=get_filesize_byte_byname(logfile);
if(file_size<0){
printf(GENERAL_BOLD "[ -INFO- ]" RESET_DISPLAY " Log file doesn't exist, nothing to delete.\n");
return -5;
}
rm_file_or_dir(logfile);
return (file_exist_or_not(logfile))?file_size:(-1);
if(file_exist_or_not(logfile)==0){
printf(FATAL_RED_BOLD "[ FATAL: ] Failed to delete the log trashbin." RESET_DISPLAY "\n");
return -1;
}
else{
printf(GENERAL_BOLD "[ -INFO- ]" RESET_DISPLAY " Removed the log trashbin under %s.\n", NOW_LOG_DIR);
printf("[ **** ] %ld bytes of disk storage freed.\n", file_size);
return file_size;
}
}
else{
char workdir[DIR_LENGTH]="";
Expand All @@ -4872,8 +4882,10 @@ int64_t delete_logs(char* cluster_name){
char logfile_err[FILENAME_LENGTH]="";
char logfile_std[FILENAME_LENGTH]="";
if(cluster_name_check(cluster_name)!=-7){
printf(FATAL_RED_BOLD "\n[ FATAL: ] The specified cluster name %s is not in the registry." RESET_DISPLAY "\n",cluster_name);
return -3; // Invalid cluster name.
}
printf(GENERAL_BOLD "\n[ -INFO- ]" RESET_DISPLAY " Deleting the archived logs of %s ...\n", cluster_name);
get_nworkdir(workdir,DIR_LENGTH,cluster_name);
create_and_get_subdir(workdir,"log",logdir,DIR_LENGTH);
snprintf(logfile_dbg,FILENAME_LENGTH,"%s%stf_dbg.log.archive",logdir,PATH_SLASH);
Expand All @@ -4885,6 +4897,7 @@ int64_t delete_logs(char* cluster_name){
int64_t size_err=get_filesize_byte_byname(logfile_err);

if(size_dbg<0&&size_std<0&&size_err<0){
printf(GENERAL_BOLD "[ -INFO- ]" RESET_DISPLAY " Log files not exist, nothing to delete.\n");
return -5;
}
if(size_dbg>=0){
Expand All @@ -4899,7 +4912,15 @@ int64_t delete_logs(char* cluster_name){
file_size+=size_err;
rm_file_or_dir(logfile_err);
}
return (file_exist_or_not(logfile_dbg)&file_exist_or_not(logfile_err)&file_exist_or_not(logfile_std))?file_size:(-1);
if(file_exist_or_not(logfile_dbg)&file_exist_or_not(logfile_err)&file_exist_or_not(logfile_std)){
printf(GENERAL_BOLD "[ -INFO- ]" RESET_DISPLAY " Removed the archived logs (debug, standard, error) of %s.\n", cluster_name);
printf("[ **** ] %ld bytes of disk storage freed.\n", file_size);
return file_size;
}
else{
printf(FATAL_RED_BOLD "[ FATAL: ] Failed to delete the log files." RESET_DISPLAY "\n");
return -1;
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion hpcopr/general_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ char command_flags[CMD_FLAG_NUM][16]={
"--month",
"--gcp",
"--rdp",
"--copypass"
"--copypass",
"--trash"
};

char command_keywords[CMD_KWDS_NUM][32]={
Expand Down
33 changes: 17 additions & 16 deletions hpcopr/hpcopr_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -911,34 +911,35 @@ int main(int argc, char* argv[]){
}

if(strcmp(final_command,"del-logs")==0){
cmd_keyword_ncheck(argc,argv,"-c",cluster_name,32);
int64_t delete_flag=delete_logs(cluster_name);
if(delete_flag==-3){
printf(FATAL_RED_BOLD "[ FATAL: ] The specified cluster name %s is not in the registry." RESET_DISPLAY "\n",cluster_name);
if(cmd_flag_check(argc,argv,"--trash")!=0&&cmd_keyword_ncheck(argc,argv,"-c",cluster_name,32)!=0){
printf(FATAL_RED_BOLD "\n[ FATAL: ] Please use --trash or -c CLUSTER_NAME to specify option(s)." RESET_DISPLAY "\n");
printf("[ **** ] Nothing deleted or removed from your disk.\n");
write_operation_log(NULL,operation_log,argc,argv,"TOO_FEW_PARAM",5);
check_and_cleanup(workdir);
return 5;
}
int64_t delete_flag1=0, delete_flag2=0;
if(cmd_flag_check(argc,argv,"--trash")==0){
delete_flag1=delete_logs("");
}
if(cmd_keyword_ncheck(argc,argv,"-c",cluster_name,32)==0){
delete_flag2=delete_logs(cluster_name);
}
if(delete_flag2==-3){
write_operation_log(cluster_name,operation_log,argc,argv,"NOT_IN_THE_CLUSTER_REGISTRY",39);
check_and_cleanup(workdir);
return 39;
}
else if(delete_flag==-1){
printf(FATAL_RED_BOLD "[ FATAL: ] Failed to delete the log(s)." RESET_DISPLAY "\n");
else if(delete_flag1==-1||delete_flag2==-1){
write_operation_log(cluster_name,operation_log,argc,argv,"FAILED_TO_DELETE_LOGS",50);
check_and_cleanup(workdir);
return 50;
}
else if(delete_flag==-5){
printf(WARN_YELLO_BOLD "[ -WARN- ] Log file(s) not exist, there is nothing to delete." RESET_DISPLAY "\n");
else if(delete_flag1==-5||delete_flag2==-5){
write_operation_log(cluster_name,operation_log,argc,argv,"NO_LOGS_TO_DELETE",50);
check_and_cleanup(workdir);
return 50;
}
if(strlen(cluster_name)==0){
printf(GENERAL_BOLD "\n[ -INFO- ]" RESET_DISPLAY " Deleted the log trashbin under %s.\n", NOW_LOG_DIR);
printf("[ **** ] %ld bytes of disk storage freed.\n", delete_flag);
}
else{
printf(GENERAL_BOLD "\n[ -INFO- ]" RESET_DISPLAY " Deleted the log archives of %s.\n", cluster_name);
printf("[ **** ] %ld bytes of disk storage freed.\n", delete_flag);
}
write_operation_log(cluster_name,operation_log,argc,argv,"SUCCEEDED",0);
check_and_cleanup(workdir);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion hpcopr/now_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ typedef struct{
#define COMMAND_STRING_LENGTH_MAX 64
#define SUBCMD_STRING_LENGTH_MAX 32
#define CONF_LINE_NUM 11
#define CMD_FLAG_NUM 30
#define CMD_FLAG_NUM 31
#define CMD_KWDS_NUM 49
#define VERS_SHA_LINES 12

Expand Down

0 comments on commit 7c39ca6

Please sign in to comment.