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-25365] Change 'Creation_time' in 'SHOW VOLUME|LOG|ARCHIVE LOG HEADER' statements to Volume creation time. #5718

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 32 additions & 15 deletions src/storage/disk_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -612,15 +613,15 @@ 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)
{
ASSERT_ERROR ();
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 */

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -3020,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));
Expand All @@ -3038,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);
Expand Down Expand Up @@ -5406,13 +5423,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;
Expand Down
2 changes: 1 addition & 1 deletion src/storage/disk_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
33 changes: 23 additions & 10 deletions src/transaction/log_applier.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down
41 changes: 22 additions & 19 deletions src/transaction/log_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -8830,7 +8833,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;
Expand Down Expand Up @@ -9289,7 +9292,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;

Expand All @@ -9313,8 +9316,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)
{
Expand Down Expand Up @@ -9626,7 +9629,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;
Expand All @@ -9651,8 +9654,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)
{
Expand Down
3 changes: 3 additions & 0 deletions src/transaction/log_page_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/transaction/log_recovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 4 additions & 0 deletions src/transaction/log_storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 */
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/transaction/log_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading