Skip to content

Commit

Permalink
modify diagdb utility to accept a class-name parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
YeunjunLee committed Apr 23, 2024
1 parent 41849f6 commit 1ce74a3
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 4 deletions.
7 changes: 6 additions & 1 deletion msg/en_US/utils.msg
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ $set 23 MSGCAT_UTIL_SET_MIGDB

$set 24 MSGCAT_UTIL_SET_DIAGDB
15 Couldn't open output file '%1$s'\n
16 Invalid class name '%1$s'.\n
60 \
diagdb: Dump a database.\n\
usage: %1$s diagdb [OPTION] database-name\n\
Expand All @@ -834,7 +835,11 @@ valid options:\n\
6 dump disk bitmaps\n\
7 dump catalog\n\
8 dump log\n\
9 dump heap\n
9 dump heap / class\n\
-n, --class-name=NAME NAME of class; only used in -d 9 option; NAME should be full class name\n\
that includes owner name and class name, split by '.';\n\
catalog classes do not need owner name.\n



$set 25 MSGCAT_UTIL_SET_LOCKDB
Expand Down
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
27 changes: 24 additions & 3 deletions src/executables/util_sa.c
Original file line number Diff line number Diff line change
Expand Up @@ -1716,10 +1716,31 @@ diagdb (UTIL_FUNCTION_ARG * arg)
if (diag == DIAGDUMP_ALL || diag == DIAGDUMP_HEAP)
{
bool dump_records;
/* this dumps the contents of all heaps */
const char *class_name;
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);
class_name = utility_get_option_string_value (arg_map, DIAG_CLASS_NAME_S, 0);
if (class_name == NULL)
{
/* this dumps the contents of all heaps */
fprintf (outfp, "\n*** DUMP OF ALL HEAPS ***\n");
(void) file_tracker_dump_all_heap (thread_p, outfp, dump_records);
}
else
{
/* this dumps the contents of a specific heap for given class name */
if (!sm_check_system_class_by_name(class_name))
{
/* check if the format of class name is valid */
if (utility_check_class_name(class_name) != NO_ERROR)
{
PRINT_AND_LOG_ERR_MSG (msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_DIAGDB, DIAGDB_MSG_BAD_CLASSNAME),
class_name);
goto error_exit;
}
}
fprintf (outfp, "\n*** DUMP OF A SPECIFIC HEAP ***\n");
class_dump (thread_p, outfp, dump_records, class_name);
}
}

db_shutdown ();
Expand Down
3 changes: 3 additions & 0 deletions src/executables/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ typedef enum
typedef enum
{
DIAGDB_MSG_BAD_OUTPUT = 15,
DIAGDB_MSG_BAD_CLASSNAME = 16,
DIAGDB_MSG_USAGE = 60
} MSGCAT_DIAGDB_MSG;

Expand Down Expand Up @@ -1197,6 +1198,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 'n'
#define DIAG_CLASS_NAME_L "class-name"

/* patch option list */
#define PATCH_RECREATE_LOG_S 'r'
Expand Down
15 changes: 15 additions & 0 deletions src/storage/file_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -11056,6 +11056,21 @@ file_tracker_dump_all_heap (THREAD_ENTRY * thread_p, FILE * fp, bool dump_record
return file_tracker_map (thread_p, PGBUF_LATCH_READ, file_tracker_item_dump_heap, &context);
}

/*
* class_dump () - 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
class_dump (THREAD_ENTRY * thread_p, FILE * fp, bool dump_records, const char *class_name)
{
fprintf (fp, "\n\n*** DUMP A CLASS NAMED %s ***\n\n", class_name);
}

/*
* file_tracker_item_dump_heap_capacity () - FILE_TRACK_ITEM_FUNC to dump heap file capacity
*
Expand Down
1 change: 1 addition & 0 deletions src/storage/file_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ extern DISK_ISVALID file_tracker_check (THREAD_ENTRY * thread_p);
extern int file_tracker_dump (THREAD_ENTRY * thread_p, FILE * fp);
extern int file_tracker_dump_all_capacities (THREAD_ENTRY * thread_p, FILE * fp);
extern int file_tracker_dump_all_heap (THREAD_ENTRY * thread_p, FILE * fp, bool dump_records);
extern void class_dump (THREAD_ENTRY * thread_p, FILE * fp, bool dump_records, const char *class_name);
extern int file_tracker_dump_all_heap_capacities (THREAD_ENTRY * thread_p, FILE * fp);
extern int file_tracker_dump_all_btree_capacities (THREAD_ENTRY * thread_p, FILE * fp);
#if defined (SA_MODE)
Expand Down

0 comments on commit 1ce74a3

Please sign in to comment.