Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CBRD-25312] Modify diagdb utility to accept a class-name parameter #5141

Merged
merged 12 commits into from
Apr 25, 2024
2 changes: 2 additions & 0 deletions src/executables/util_admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ static UTIL_ARG_MAP ua_Diag_Option_Map[] = {
{DIAG_DUMP_RECORDS_S, {ARG_BOOLEAN}, {0}},
{DIAG_OUTPUT_FILE_S, {ARG_STRING}, {0}},
{DIAG_EMERGENCY_S, {ARG_BOOLEAN}, {0}},
{DIAG_CLASS_NAME_S, {ARG_STRING}, {0}},
{0, {0}, {0}}
};

Expand All @@ -327,6 +328,7 @@ static GETOPT_LONG ua_Diag_Option[] = {
{DIAG_DUMP_RECORDS_L, 0, 0, DIAG_DUMP_RECORDS_S},
{DIAG_OUTPUT_FILE_L, 1, 0, DIAG_OUTPUT_FILE_S},
{DIAG_EMERGENCY_L, 0, 0, DIAG_EMERGENCY_S},
{DIAG_CLASS_NAME_L, 1, 0, DIAG_CLASS_NAME_S},
{0, 0, 0, 0}
};

Expand Down
28 changes: 25 additions & 3 deletions src/executables/util_sa.c
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,7 @@ diagdb (UTIL_FUNCTION_ARG * arg)
char er_msg_file[PATH_MAX];
const char *db_name;
const char *output_file = NULL;
const char *class_name;
FILE *outfp = NULL;
bool is_emergency = false;
DIAGDUMP_TYPE diag;
Expand Down Expand Up @@ -1565,13 +1566,19 @@ diagdb (UTIL_FUNCTION_ARG * arg)
}
}

class_name = utility_get_option_string_value (arg_map, DIAG_CLASS_NAME_S, 0);
diag = (DIAGDUMP_TYPE) utility_get_option_int_value (arg_map, DIAG_DUMP_TYPE_S);

if (diag != DIAGDUMP_LOG && utility_get_option_string_table_size (arg_map) != 1)
{
goto print_diag_usage;
}

if (diag == DIAGDUMP_ALL && class_name != NULL)
{
goto print_diag_usage;
}
Comment on lines +1577 to +1580
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (diag == DIAGDUMP_ALL && class_name != NULL)
{
goto print_diag_usage;
}
if (diag == DIAGDUMP_ALL && class_name != NULL)
{
goto print_diag_usage;
}


if (check_database_name (db_name))
{
goto error_exit;
Expand Down Expand Up @@ -1716,10 +1723,25 @@ diagdb (UTIL_FUNCTION_ARG * arg)
if (diag == DIAGDUMP_ALL || diag == DIAGDUMP_HEAP)
{
bool dump_records;
/* this dumps the contents of all heaps */
dump_records = utility_get_option_bool_value (arg_map, DIAG_DUMP_RECORDS_S);
fprintf (outfp, "\n*** DUMP OF ALL HEAPS ***\n");
(void) file_tracker_dump_all_heap (thread_p, outfp, dump_records);

if (class_name == NULL)
{
fprintf (outfp, "\n*** DUMP OF ALL HEAPS ***\n");
(void) file_tracker_dump_all_heap (thread_p, outfp, dump_records);
}
else
{
if (!sm_check_system_class_by_name (class_name))
{
if (utility_check_class_name (class_name) != NO_ERROR)
{
goto error_exit;
}
}
fprintf (outfp, "\n*** DUMP HEAP OF %s ***\n", class_name);
heap_dump_heap_file (thread_p, outfp, dump_records, class_name);
}
}

db_shutdown ();
Expand Down
2 changes: 2 additions & 0 deletions src/executables/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,8 @@ typedef struct _ha_config
#define DIAG_OUTPUT_FILE_L "output-file"
#define DIAG_EMERGENCY_S 11202
#define DIAG_EMERGENCY_L "emergency"
#define DIAG_CLASS_NAME_S 'c'
#define DIAG_CLASS_NAME_L "class-name"

/* patch option list */
#define PATCH_RECREATE_LOG_S 'r'
Expand Down
17 changes: 17 additions & 0 deletions src/storage/heap_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -14507,6 +14507,23 @@ heap_dump (THREAD_ENTRY * thread_p, FILE * fp, HFID * hfid, bool dump_records)
fprintf (fp, "\n\n*** END OF DUMP FOR HEAP FILE ***\n\n");
}

#if defined (SA_MODE)
/*
* heap_dump_heap_file () - dump a specific heap file with class name
*
* return :
* thread_p (in) : thread entry
* fp (in) : output file
* dump_records (in) : true to dump records
* class_name (in) : name of class to dump
*/
void
heap_dump_heap_file (THREAD_ENTRY * thread_p, FILE * fp, bool dump_records, const char *class_name)
{
/* TODO: Fetch HFID of class which corresponds to class_name, and dump heap file by HFID. Will be handled at CBRD-25313 and CBRD-25314. */
}
#endif

/*
* heap_dump_capacity () - dump heap file capacity
*
Expand Down
3 changes: 3 additions & 0 deletions src/storage/heap_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,9 @@ extern int heap_set_autoincrement_value (THREAD_ENTRY * thread_p, HEAP_CACHE_ATT
HEAP_SCANCACHE * scan_cache, int *is_set);

extern void heap_dump (THREAD_ENTRY * thread_p, FILE * fp, HFID * hfid, bool dump_records);
#if defined (SA_MODE)
extern void heap_dump_heap_file (THREAD_ENTRY * thread_p, FILE * fp, bool dump_records, const char *class_name);
#endif
extern void heap_attrinfo_dump (THREAD_ENTRY * thread_p, FILE * fp, HEAP_CACHE_ATTRINFO * attr_info, bool dump_schema);
#if defined (CUBRID_DEBUG)
extern void heap_chnguess_dump (FILE * fp);
Expand Down
Loading