From 52ea64ffeb9e01ba138491e724e78bd3801c7416 Mon Sep 17 00:00:00 2001 From: KIM HUISU Date: Tue, 13 Aug 2024 10:27:13 +0900 Subject: [PATCH 1/3] [CBRD-25365] Change 'Creation_time' in 'SHOW VOLUME|LOG|ARCHIVE LOG HEADER' statements to Volume creation time. (#5230) http://jira.cubrid.org/browse/CBRD-25365 --- src/storage/disk_manager.c | 34 ++++++++++++++++++++++--------- src/storage/disk_manager.h | 2 +- src/transaction/log_manager.c | 20 +++++++++--------- src/transaction/log_page_buffer.c | 3 +++ src/transaction/log_recovery.c | 4 ++-- src/transaction/log_storage.hpp | 4 ++++ src/transaction/log_writer.c | 1 + 7 files changed, 45 insertions(+), 23 deletions(-) diff --git a/src/storage/disk_manager.c b/src/storage/disk_manager.c index 59f9d85c1a1..fe41acd32fb 100644 --- a/src/storage/disk_manager.c +++ b/src/storage/disk_manager.c @@ -90,6 +90,7 @@ struct disk_volume_header INT32 dummy2; /* Dummy fields for alignment */ INT64 db_creation; /* Database creation time. For safety reasons, this value is set on all volumes and the * log. The value is generated by the log manager */ + INT64 vol_creation; /* Volume creation time */ LOG_LSA chkpt_lsa; /* Lowest log sequence address to start the recovery process of this volume */ HFID boot_hfid; /* System Heap file for booting purposes and multi volumes */ INT32 reserved0; /* reserved area */ @@ -612,8 +613,6 @@ disk_format (THREAD_ENTRY * thread_p, const char *dbname, VOLID volid, DBDEF_VOL goto exit; } - /* Find the time of the creation of the database and the current LSA checkpoint. */ - error_code = log_get_db_start_parameters (&vhdr->db_creation, &vhdr->chkpt_lsa); if (error_code != NO_ERROR) { @@ -621,6 +620,8 @@ disk_format (THREAD_ENTRY * thread_p, const char *dbname, VOLID volid, DBDEF_VOL goto exit; } + vhdr->vol_creation = time (NULL); + /* Initialize the system heap file for booting purposes. This field is reseted after the heap file is created by the * boot manager */ @@ -904,9 +905,22 @@ disk_set_creation (THREAD_ENTRY * thread_p, INT16 volid, const char *new_vol_ful log_skip_logging (thread_p, &addr); } - /* Modify volume creation information */ - memcpy (&vhdr->db_creation, new_dbcreation, sizeof (*new_dbcreation)); - memcpy (&vhdr->chkpt_lsa, new_chkptlsa, sizeof (*new_chkptlsa)); + /* + * 1. The values of vhdr->db_creation and new_dbcreation differ only when a new database volume is being created. (ex: copydb) + * 2. The value of new_chkptlsa differs from vhdr->chkpt_lsa only when a new database is created + * or when the active log header's chkpt_lsa value is changed due to a call to the log_final() function. + */ + if (vhdr->db_creation != *new_dbcreation) + { + memcpy (&vhdr->db_creation, new_dbcreation, sizeof (*new_dbcreation)); + vhdr->vol_creation = time (NULL); + } + + if (!LSA_EQ (&vhdr->chkpt_lsa, new_chkptlsa)) + { + memcpy (&vhdr->chkpt_lsa, new_chkptlsa, sizeof (*new_chkptlsa)); + } + if (disk_vhdr_set_vol_fullname (vhdr, new_vol_fullname) != NO_ERROR) { goto error; @@ -2877,7 +2891,7 @@ disk_volume_header_next_scan (THREAD_ENTRY * thread_p, int cursor, DB_VALUE ** o DISK_VOLUME_HEADER *vhdr; int error = NO_ERROR, idx = 0; PAGE_PTR pgptr = NULL; - DB_DATETIME create_time; + DB_DATETIME vol_creation; char buf[256]; DISK_VOL_HEADER_CONTEXT *ctx = (DISK_VOL_HEADER_CONTEXT *) ptr; @@ -2940,8 +2954,8 @@ disk_volume_header_next_scan (THREAD_ENTRY * thread_p, int cursor, DB_VALUE ** o db_make_int (out_values[idx], vhdr->sys_lastpage); idx++; - db_localdatetime ((time_t *) (&vhdr->db_creation), &create_time); - db_make_datetime (out_values[idx], &create_time); + db_localdatetime ((time_t *) (&vhdr->vol_creation), &vol_creation); + db_make_datetime (out_values[idx], &vol_creation); idx++; db_make_int (out_values[idx], vhdr->db_charset); @@ -5406,13 +5420,13 @@ disk_get_checkpoint (THREAD_ENTRY * thread_p, INT16 volid, LOG_LSA * vol_lsa) } /* - * disk_get_creation_time () - Get the database creation time according to the volume header + * disk_get_db_creation () - Get the database creation time according to the volume header * return: void * volid(in): Permanent volume identifier * db_creation(out): Database creation time according to the volume */ int -disk_get_creation_time (THREAD_ENTRY * thread_p, INT16 volid, INT64 * db_creation) +disk_get_db_creation (THREAD_ENTRY * thread_p, INT16 volid, INT64 * db_creation) { DISK_VOLUME_HEADER *vhdr; PAGE_PTR hdr_pgptr = NULL; diff --git a/src/storage/disk_manager.h b/src/storage/disk_manager.h index baf55fb13b8..9d1cee41d36 100644 --- a/src/storage/disk_manager.h +++ b/src/storage/disk_manager.h @@ -108,7 +108,7 @@ extern DISK_ISVALID disk_check_sectors_are_reserved (THREAD_ENTRY * thread_p, VS extern INT16 xdisk_get_purpose_and_sys_lastpage (THREAD_ENTRY * thread_p, INT16 volid, DISK_VOLPURPOSE * vol_purpose, INT32 * sys_lastpage); extern int disk_get_checkpoint (THREAD_ENTRY * thread_p, INT16 volid, LOG_LSA * vol_lsa); -extern int disk_get_creation_time (THREAD_ENTRY * thread_p, INT16 volid, INT64 * db_creation); +extern int disk_get_db_creation (THREAD_ENTRY * thread_p, INT16 volid, INT64 * db_creation); extern INT32 disk_get_total_numsectors (THREAD_ENTRY * thread_p, INT16 volid); extern HFID *disk_get_boot_hfid (THREAD_ENTRY * thread_p, INT16 volid, HFID * hfid); extern char *disk_get_link (THREAD_ENTRY * thread_p, INT16 volid, INT16 * next_volid, char *next_volext_fullname); diff --git a/src/transaction/log_manager.c b/src/transaction/log_manager.c index cc40d8a0b8a..ce00ff77e01 100644 --- a/src/transaction/log_manager.c +++ b/src/transaction/log_manager.c @@ -667,14 +667,14 @@ log_get_final_restored_lsa (void) static bool log_verify_dbcreation (THREAD_ENTRY * thread_p, VOLID volid, const INT64 * log_dbcreation) { - INT64 vol_dbcreation; /* Database creation time in volume */ + INT64 db_creation; /* Database creation time in volume */ - if (disk_get_creation_time (thread_p, volid, &vol_dbcreation) != NO_ERROR) + if (disk_get_db_creation (thread_p, volid, &db_creation) != NO_ERROR) { return false; } - if (difftime ((time_t) vol_dbcreation, (time_t) (*log_dbcreation)) == 0) + if (difftime ((time_t) db_creation, (time_t) (*log_dbcreation)) == 0) { return true; } @@ -8830,7 +8830,7 @@ log_recreate (THREAD_ENTRY * thread_p, const char *db_fullname, const char *logp LOG_LSA init_nontemp_lsa; int ret = NO_ERROR; - ret = disk_get_creation_time (thread_p, LOG_DBFIRST_VOLID, &db_creation); + ret = disk_get_db_creation (thread_p, LOG_DBFIRST_VOLID, &db_creation); if (ret != NO_ERROR) { return ret; @@ -9289,7 +9289,7 @@ log_active_log_header_next_scan (THREAD_ENTRY * thread_p, int cursor, DB_VALUE * int val; const char *str; char buf[256]; - DB_DATETIME time_val; + DB_DATETIME vol_creation; ACTIVE_LOG_HEADER_SCAN_CTX *ctx = (ACTIVE_LOG_HEADER_SCAN_CTX *) ptr; LOG_HEADER *header = &ctx->header; @@ -9313,8 +9313,8 @@ log_active_log_header_next_scan (THREAD_ENTRY * thread_p, int cursor, DB_VALUE * db_make_int (out_values[idx], val); idx++; - db_localdatetime ((time_t *) (&header->db_creation), &time_val); - error = db_make_datetime (out_values[idx], &time_val); + db_localdatetime ((time_t *) (&header->vol_creation), &vol_creation); + error = db_make_datetime (out_values[idx], &vol_creation); idx++; if (error != NO_ERROR) { @@ -9626,7 +9626,7 @@ log_archive_log_header_next_scan (THREAD_ENTRY * thread_p, int cursor, DB_VALUE int error = NO_ERROR; int idx = 0; int val; - DB_DATETIME time_val; + DB_DATETIME vol_creation; ARCHIVE_LOG_HEADER_SCAN_CTX *ctx = (ARCHIVE_LOG_HEADER_SCAN_CTX *) ptr; LOG_ARV_HEADER *header = &ctx->header; @@ -9651,8 +9651,8 @@ log_archive_log_header_next_scan (THREAD_ENTRY * thread_p, int cursor, DB_VALUE db_make_int (out_values[idx], val); idx++; - db_localdatetime ((time_t *) (&header->db_creation), &time_val); - error = db_make_datetime (out_values[idx], &time_val); + db_localdatetime ((time_t *) (&header->vol_creation), &vol_creation); + error = db_make_datetime (out_values[idx], &vol_creation); idx++; if (error != NO_ERROR) { diff --git a/src/transaction/log_page_buffer.c b/src/transaction/log_page_buffer.c index 959a8354df5..e8964661e6d 100644 --- a/src/transaction/log_page_buffer.c +++ b/src/transaction/log_page_buffer.c @@ -1319,10 +1319,12 @@ logpb_initialize_header (THREAD_ENTRY * thread_p, LOG_HEADER * loghdr, const cha if (db_creation != NULL) { loghdr->db_creation = *db_creation; + loghdr->vol_creation = time (NULL); } else { loghdr->db_creation = -1; + loghdr->vol_creation = -1; } if (strlen (rel_release_string ()) >= REL_MAX_RELEASE_LENGTH) @@ -5680,6 +5682,7 @@ logpb_archive_active_log (THREAD_ENTRY * thread_p) arvhdr = (LOG_ARV_HEADER *) malloc_arv_hdr_pgptr->area; strncpy (arvhdr->magic, CUBRID_MAGIC_LOG_ARCHIVE, CUBRID_MAGIC_MAX_LENGTH); arvhdr->db_creation = log_Gl.hdr.db_creation; + arvhdr->vol_creation = time (NULL); arvhdr->next_trid = log_Gl.hdr.next_trid; arvhdr->arv_num = log_Gl.hdr.nxarv_num; diff --git a/src/transaction/log_recovery.c b/src/transaction/log_recovery.c index 20bd0a20d51..534a7bb2fbf 100644 --- a/src/transaction/log_recovery.c +++ b/src/transaction/log_recovery.c @@ -5359,7 +5359,7 @@ log_recovery_notpartof_volumes (THREAD_ENTRY * thread_p) vdes = fileio_mount (thread_p, log_Db_fullname, vol_fullname, volid, false, false); if (vdes != NULL_VOLDES) { - ret = disk_get_creation_time (thread_p, volid, &vol_dbcreation); + ret = disk_get_db_creation (thread_p, volid, &vol_dbcreation); fileio_dismount (thread_p, vdes); if (difftime ((time_t) vol_dbcreation, (time_t) log_Gl.hdr.db_creation) != 0) { @@ -5478,7 +5478,7 @@ log_recovery_resetlog (THREAD_ENTRY * thread_p, const LOG_LSA * new_append_lsa, if (log_Gl.append.vdes == NULL_VOLDES) { /* Create the log active since we do not have one */ - ret = disk_get_creation_time (thread_p, LOG_DBFIRST_VOLID, &log_Gl.hdr.db_creation); + ret = disk_get_db_creation (thread_p, LOG_DBFIRST_VOLID, &log_Gl.hdr.db_creation); if (ret != NO_ERROR) { logpb_fatal_error (thread_p, true, ARG_FILE_LINE, "log_recovery_resetlog"); diff --git a/src/transaction/log_storage.hpp b/src/transaction/log_storage.hpp index 41e475ad02a..2e2d322a730 100644 --- a/src/transaction/log_storage.hpp +++ b/src/transaction/log_storage.hpp @@ -118,6 +118,7 @@ struct log_header INT32 dummy; /* for 8byte align */ INT64 db_creation; /* Database creation time. For safety reasons, this value is set on all volumes and the * log. The value is generated by the log manager */ + INT64 vol_creation; /* volume creation time */ char db_release[REL_MAX_RELEASE_LENGTH]; /* CUBRID Release */ /* Here exists 1 byte */ float db_compatibility; /* Compatibility of the database against the current release of CUBRID */ @@ -176,6 +177,7 @@ struct log_header : magic {'0'} , dummy (0) , db_creation (0) + , vol_creation (0) , db_release {'0'} , db_compatibility (0.0f) , db_iopagesize (0) @@ -233,6 +235,7 @@ struct log_arv_header INT32 dummy; /* for 8byte align */ INT64 db_creation; /* Database creation time. For safety reasons, this value is set on all volumes and the * log. The value is generated by the log manager */ + INT64 vol_creation; /* volume creation time */ TRANID next_trid; /* Next Transaction identifier */ DKNPAGES npages; /* Number of pages in the archive log */ LOG_PAGEID fpageid; /* Logical pageid at physical location 1 in archive log */ @@ -243,6 +246,7 @@ struct log_arv_header : magic {'0'} , dummy (0) , db_creation (0) + , vol_creation (0) , next_trid (0) , npages (0) , fpageid (0) diff --git a/src/transaction/log_writer.c b/src/transaction/log_writer.c index b9d8ed630b7..47faca99bdf 100644 --- a/src/transaction/log_writer.c +++ b/src/transaction/log_writer.c @@ -1308,6 +1308,7 @@ logwr_archive_active_log (void) arvhdr = (LOG_ARV_HEADER *) malloc_arv_hdr_pgptr->area; strncpy (arvhdr->magic, CUBRID_MAGIC_LOG_ARCHIVE, CUBRID_MAGIC_MAX_LENGTH); arvhdr->db_creation = logwr_Gl.hdr.db_creation; + arvhdr->vol_creation = time (NULL); arvhdr->next_trid = NULL_TRANID; arvhdr->fpageid = logwr_Gl.last_arv_fpageid; arvhdr->arv_num = logwr_Gl.last_arv_num; From 549459a3d099783bb891682819c7cd3222ffbfbc Mon Sep 17 00:00:00 2001 From: KIM HUISU Date: Tue, 27 Aug 2024 12:44:08 +0900 Subject: [PATCH 2/3] [CBRD-25462] Modify the applyinfo utility to print the volume creation time. (#5424) Added volume creation time to the log header and archive log header information output by the 'applyinfo' utility --- src/transaction/log_applier.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/transaction/log_applier.c b/src/transaction/log_applier.c index 98dee887787..30f92fef093 100644 --- a/src/transaction/log_applier.c +++ b/src/transaction/log_applier.c @@ -7129,19 +7129,26 @@ void la_print_log_header (const char *database_name, LOG_HEADER * hdr, bool verbose) { time_t tloc; + time_t db_creation_time, vol_creation_time; DB_DATETIME datetime; char timebuf[1024]; + char db_creation_time_buf[1024], vol_creation_time_buf[1024]; - tloc = hdr->db_creation; - db_localdatetime (&tloc, &datetime); - db_datetime_to_string ((char *) timebuf, 1024, &datetime); + db_creation_time = hdr->db_creation; + db_localdatetime (&db_creation_time, &datetime); + db_datetime_to_string ((char *) db_creation_time_buf, 1024, &datetime); + + vol_creation_time = hdr->vol_creation; + db_localdatetime (&vol_creation_time, &datetime); + db_datetime_to_string ((char *) vol_creation_time_buf, 1024, &datetime); if (verbose) { printf ("%-30s : %s\n", "Magic", hdr->magic); } printf ("%-30s : %s\n", "DB name", database_name); - printf ("%-30s : %s (%ld)\n", "DB creation time", timebuf, tloc); + printf ("%-30s : %s (%ld)\n", "DB creation time", db_creation_time_buf, db_creation_time); + printf ("%-30s : %s (%ld)\n", "Vol creation time", vol_creation_time_buf, vol_creation_time); printf ("%-30s : %lld | %d\n", "EOF LSA", (long long int) hdr->eof_lsa.pageid, (int) hdr->eof_lsa.offset); printf ("%-30s : %lld | %d\n", "Append LSA", (long long int) hdr->append_lsa.pageid, (int) hdr->append_lsa.offset); printf ("%-30s : %s\n", "HA server state", css_ha_server_state_string ((HA_SERVER_STATE) hdr->ha_server_state)); @@ -7186,16 +7193,22 @@ la_print_log_header (const char *database_name, LOG_HEADER * hdr, bool verbose) void la_print_log_arv_header (const char *database_name, LOG_ARV_HEADER * hdr, bool verbose) { - time_t tloc; + time_t db_creation_time, vol_creation_time; DB_DATETIME datetime; - char timebuf[1024]; + char db_creation_time_buf[1024], vol_creation_time_buf[1024]; - tloc = hdr->db_creation; - db_localdatetime (&tloc, &datetime); - db_datetime_to_string ((char *) timebuf, 1024, &datetime); + db_creation_time = hdr->db_creation; + db_localdatetime (&db_creation_time, &datetime); + db_datetime_to_string ((char *) db_creation_time_buf, 1024, &datetime); + + vol_creation_time = hdr->vol_creation; + db_localdatetime (&vol_creation_time, &datetime); + db_datetime_to_string ((char *) vol_creation_time_buf, 1024, &datetime); printf ("%-30s : %s\n", "DB name ", database_name); - printf ("%-30s : %s (%ld)\n", "DB creation time ", timebuf, tloc); + printf ("%-30s : %s (%ld)\n", "DB creation time", db_creation_time_buf, db_creation_time); + printf ("%-30s : %s (%ld)\n", "Vol creation time", vol_creation_time_buf, vol_creation_time); + if (verbose) { printf ("%-30s : %d\n", "Next transaction identifier", hdr->next_trid); From d4fcac534466e830e3e54fd19639026ad978f29c Mon Sep 17 00:00:00 2001 From: KIM HUISU Date: Tue, 27 Aug 2024 13:21:42 +0900 Subject: [PATCH 3/3] [CBRD-25461] Modify diagdb utility to additionally display volume creation (#5419) --- src/storage/disk_manager.c | 13 ++++++++----- src/transaction/log_manager.c | 21 ++++++++++++--------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/storage/disk_manager.c b/src/storage/disk_manager.c index fe41acd32fb..5029e5c9f5e 100644 --- a/src/storage/disk_manager.c +++ b/src/storage/disk_manager.c @@ -3034,8 +3034,11 @@ disk_volume_header_end_scan (THREAD_ENTRY * thread_p, void **ptr) static void disk_vhdr_dump (FILE * fp, const DISK_VOLUME_HEADER * vhdr) { - char time_val[CTIME_MAX]; - time_t tmp_time; + char db_creation_time_val[CTIME_MAX]; + char vol_creation_time_val[CTIME_MAX]; + + (void) ctime_r ((time_t *) & vhdr->db_creation, db_creation_time_val); + (void) ctime_r ((time_t *) & vhdr->vol_creation, vol_creation_time_val); (void) fprintf (fp, " MAGIC SYMBOL = %s at disk location = %lld\n", vhdr->magic, offsetof (FILEIO_PAGE, page) + (long long) offsetof (DISK_VOLUME_HEADER, magic)); @@ -3052,9 +3055,9 @@ disk_vhdr_dump (FILE * fp, const DISK_VOLUME_HEADER * vhdr) (void) fprintf (fp, " SECTOR TABLE: SIZE IN PAGES = %10d, FIRST_PAGE = %5d\n", vhdr->stab_npages, vhdr->stab_first_page); - tmp_time = (time_t) vhdr->db_creation; - (void) ctime_r (&tmp_time, time_val); - (void) fprintf (fp, " Database creation time = %s\n Lowest Checkpoint for recovery = %lld|%lld\n", time_val, + (void) fprintf (fp, " Database creation time = %s", db_creation_time_val); + (void) fprintf (fp, " Volume creation time = %s", vol_creation_time_val); + (void) fprintf (fp, " Lowest Checkpoint for recovery = %lld|%lld\n", (long long) vhdr->chkpt_lsa.pageid, (long long) vhdr->chkpt_lsa.offset); (void) fprintf (fp, "Boot_hfid: volid %d, fileid %d header_pageid %d\n", vhdr->boot_hfid.vfid.volid, vhdr->boot_hfid.vfid.fileid, vhdr->boot_hfid.hpgid); diff --git a/src/transaction/log_manager.c b/src/transaction/log_manager.c index ce00ff77e01..11e7ad6c168 100644 --- a/src/transaction/log_manager.c +++ b/src/transaction/log_manager.c @@ -6216,24 +6216,27 @@ log_dump_data (THREAD_ENTRY * thread_p, FILE * out_fp, int length, LOG_LSA * log static void log_dump_header (FILE * out_fp, LOG_HEADER * log_header_p) { - time_t tmp_time; - char time_val[CTIME_MAX]; + char db_creation_time_val[CTIME_MAX]; + char vol_creation_time_val[CTIME_MAX]; + + (void) ctime_r ((time_t *) & log_header_p->db_creation, db_creation_time_val); + (void) ctime_r ((time_t *) & log_header_p->vol_creation, vol_creation_time_val); fprintf (out_fp, "\n ** DUMP LOG HEADER **\n"); - tmp_time = (time_t) log_header_p->db_creation; - (void) ctime_r (&tmp_time, time_val); fprintf (out_fp, - "HDR: Magic Symbol = %s at disk location = %lld\n Creation_time = %s" + "HDR: Magic Symbol = %s at disk location = %lld\n" + " Db_creation_time = %s" + " Vol_creation_time = %s" " Release = %s, Compatibility_disk_version = %g,\n" " Db_pagesize = %d, log_pagesize= %d, Shutdown = %d,\n" " Next_trid = %d, Next_mvcc_id = %llu, Num_avg_trans = %d, Num_avg_locks = %d,\n" " Num_active_log_pages = %d, First_active_log_page = %lld,\n" " Current_append = %lld|%d, Checkpoint = %lld|%d,\n", log_header_p->magic, - (long long) offsetof (LOG_PAGE, area), time_val, log_header_p->db_release, log_header_p->db_compatibility, - log_header_p->db_iopagesize, log_header_p->db_logpagesize, log_header_p->is_shutdown, - log_header_p->next_trid, (long long int) log_header_p->mvcc_next_id, log_header_p->avg_ntrans, - log_header_p->avg_nlocks, log_header_p->npages, (long long) log_header_p->fpageid, + (long long) offsetof (LOG_PAGE, area), db_creation_time_val, vol_creation_time_val, log_header_p->db_release, + log_header_p->db_compatibility, log_header_p->db_iopagesize, log_header_p->db_logpagesize, + log_header_p->is_shutdown, log_header_p->next_trid, (long long int) log_header_p->mvcc_next_id, + log_header_p->avg_ntrans, log_header_p->avg_nlocks, log_header_p->npages, (long long) log_header_p->fpageid, LSA_AS_ARGS (&log_header_p->append_lsa), LSA_AS_ARGS (&log_header_p->chkpt_lsa)); fprintf (out_fp,