CUBRID Engine  latest
log_storage.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 //
20 // Define storage of logging system
21 //
22 
23 #ifndef _LOG_STORAGE_HPP_
24 #define _LOG_STORAGE_HPP_
25 
26 #include "file_io.h"
27 #include "log_lsa.hpp"
28 #include "release_string.h"
29 #include "storage_common.h"
30 #include "system.h"
31 #include "transaction_global.hpp"
32 #include "tde.h"
33 
34 #include <cstdint>
35 
36 /* Definitions for flags in LOG_HDRPAGE */
37 
38 /*
39  * TDE_ALGORITHM to be applied to the log page
40  * Set if any record in the page has to be tde-encrypted
41  */
42 #define LOG_HDRPAGE_FLAG_ENCRYPTED_AES 0x1
43 #define LOG_HDRPAGE_FLAG_ENCRYPTED_ARIA 0x2
44 
45 #define LOG_HDRPAGE_FLAG_ENCRYPTED_MASK 0x3
46 
47 #define LOG_IS_PAGE_TDE_ENCRYPTED(log_page_p) \
48  ((log_page_p)->hdr.flags & LOG_HDRPAGE_FLAG_ENCRYPTED_AES \
49  || (log_page_p)->hdr.flags & LOG_HDRPAGE_FLAG_ENCRYPTED_ARIA)
50 
51 const LOG_PAGEID LOGPB_HEADER_PAGE_ID = -9; /* The first log page in the infinite log sequence. It is always kept
52  * on the active portion of the log. Log records are not stored on this
53  * page. This page is backed up in all archive logs */
54 
55 const size_t LOGPB_IO_NPAGES = 4;
56 const size_t LOGPB_BUFFER_NPAGES_LOWER = 128;
57 
58 /*
59  * LOG PAGE
60  */
61 
62 typedef struct log_hdrpage LOG_HDRPAGE;
64 {
65  LOG_PAGEID logical_pageid; /* Logical pageid in infinite log */
66  PGLENGTH offset; /* Offset of first log record in this page. This may be useful when previous log page
67  * is corrupted and an archive of that page does not exist. Instead of losing the whole
68  * log because of such bad page, we could salvage the log starting at the offset
69  * address, that is, at the next log record */
70  short flags; /* flags */
71  int checksum; /* checksum - currently CRC32 is used to check log page consistency. */
72 };
73 
74 /* WARNING:
75  * Don't use sizeof(LOG_PAGE) or of any structure that contains it
76  * Use macro LOG_PAGESIZE instead.
77  * It is also bad idea to allocate a variable for LOG_PAGE on the stack.
78  */
79 
80 typedef struct log_page LOG_PAGE;
81 struct log_page
82 {
83  /* The log page */
85  char area[1];
86 };
87 
88 const size_t MAXLOGNAME = (30 - 12);
89 
90 // vacuum blocks
91 using VACUUM_LOG_BLOCKID = std::int64_t;
92 
93 /*
94  * This structure encapsulates various information and metrics related
95  * to each backup level.
96  * Estimates and heuristics are not currently used but are placeholder
97  * for the future to avoid changing the physical representation again.
98  */
101 {
102  INT64 bkup_attime; /* Timestamp when this backup lsa taken */
103  INT64 io_baseln_time; /* time (secs.) to write a single page */
104  INT64 io_bkuptime; /* total time to write the backup */
105  int ndirty_pages_post_bkup; /* number of pages written since the lsa for this backup level. */
106  int io_numpages; /* total number of pages in last backup */
107 };
108 
109 /*
110  * LOG HEADER INFORMATION
111  */
112 typedef struct log_header LOG_HEADER;
114 {
115  /* Log header information */
116  char magic[CUBRID_MAGIC_MAX_LENGTH]; /* Magic value for file/magic Unix utility */
117  /* Here exists 3 bytes */
118  INT32 dummy; /* for 8byte align */
119  INT64 db_creation; /* Database creation time. For safety reasons, this value is set on all volumes and the
120  * log. The value is generated by the log manager */
121  char db_release[REL_MAX_RELEASE_LENGTH]; /* CUBRID Release */
122  /* Here exists 1 byte */
123  float db_compatibility; /* Compatibility of the database against the current release of CUBRID */
124  PGLENGTH db_iopagesize; /* Size of pages in the database. For safety reasons this value is recorded in the log
125  * to make sure that the database is always run with the same page size */
126  PGLENGTH db_logpagesize; /* Size of log pages in the database. */
127  bool is_shutdown; /* Was the log shutdown ? */
128  /* Here exists 3 bytes */
129  TRANID next_trid; /* Next Transaction identifier */
130  MVCCID mvcc_next_id; /* Next MVCC ID */
131  int avg_ntrans; /* Number of average transactions */
132  int avg_nlocks; /* Average number of object locks */
133  DKNPAGES npages; /* Number of pages in the active log portion. Does not include the log header page. */
135  bool was_copied; /* set to true for copied database; should be reset on first server start */
136  INT8 dummy3; /* Dummy fields for 8byte align */
137  INT8 dummy4;
138  LOG_PAGEID fpageid; /* Logical pageid at physical location 1 in active log */
139  LOG_LSA append_lsa; /* Current append location */
140  LOG_LSA chkpt_lsa; /* Lowest log sequence address to start the recovery process */
141  LOG_PAGEID nxarv_pageid; /* Next logical page to archive */
142  LOG_PHY_PAGEID nxarv_phy_pageid; /* Physical location of logical page to archive */
143  int nxarv_num; /* Next log archive number */
144  int last_arv_num_for_syscrashes; /* Last log archive needed for system crashes */
145  int last_deleted_arv_num; /* Last deleted archive number */
146  LOG_LSA bkup_level0_lsa; /* Lsa of backup level 0 */
147  LOG_LSA bkup_level1_lsa; /* Lsa of backup level 1 */
148  LOG_LSA bkup_level2_lsa; /* Lsa of backup level 2 */
149  char prefix_name[MAXLOGNAME]; /* Log prefix name */
150  bool has_logging_been_skipped; /* Has logging been skipped ? */
151  /* Here exists 5 bytes */
152  VACUUM_LOG_BLOCKID vacuum_last_blockid; /* Last processed blockid needed for vacuum. */
154  /* Here exists 4 bytes */
156  /* backup specific info for future growth */
157 
161 
163 
164  // next fields track MVCC info relevant for vacuum
165  LOG_LSA mvcc_op_log_lsa; /* LSA of last MVCC operation log record */
166  MVCCID oldest_visible_mvccid; /* oldest visible MVCCID */
167  MVCCID newest_block_mvccid; /* newest MVCCID for current block */
168 
174 
176  : magic {'0'}
177  , dummy (0)
178  , db_creation (0)
179  , db_release {'0'}
180  , db_compatibility (0.0f)
181  , db_iopagesize (0)
182  , db_logpagesize (0)
183  , is_shutdown (false)
184  , next_trid (LOG_SYSTEM_TRANID + 1)
185  , mvcc_next_id (MVCCID_NULL)
186  , avg_ntrans (0)
187  , avg_nlocks (0)
188  , npages (0)
189  , db_charset (0)
190  , was_copied (false)
191  , dummy3 (0)
192  , dummy4 (0)
193  , fpageid (0)
194  , append_lsa (NULL_LSA)
195  , chkpt_lsa (NULL_LSA)
196  , nxarv_pageid (0)
197  , nxarv_phy_pageid (0)
198  , nxarv_num (0)
199  , last_arv_num_for_syscrashes (0)
200  , last_deleted_arv_num (0)
201  , bkup_level0_lsa (NULL_LSA)
202  , bkup_level1_lsa (NULL_LSA)
203  , bkup_level2_lsa (NULL_LSA)
204  , prefix_name {'0'}
205  , has_logging_been_skipped (false)
206  , vacuum_last_blockid (0)
207  , perm_status_obsolete (0)
208  , bkinfo {{0, 0, 0, 0, 0}}
209  , ha_server_state (0)
210  , ha_file_status (0)
211  , eof_lsa (NULL_LSA)
212  , smallest_lsa_at_last_chkpt (NULL_LSA)
213  , mvcc_op_log_lsa (NULL_LSA)
214  , oldest_visible_mvccid (MVCCID_FIRST)
215  , newest_block_mvccid (MVCCID_NULL)
216  , ha_promotion_time (0)
217  , db_restore_time (0)
218  , mark_will_del (false)
219  , does_block_need_vacuum (false)
220  , was_active_log_reset (false)
221  {
222  //
223  }
224 };
225 
226 
227 
230 {
231  /* Log archive header information */
232  char magic[CUBRID_MAGIC_MAX_LENGTH]; /* Magic value for file/magic Unix utility */
233  INT32 dummy; /* for 8byte align */
234  INT64 db_creation; /* Database creation time. For safety reasons, this value is set on all volumes and the
235  * log. The value is generated by the log manager */
236  TRANID next_trid; /* Next Transaction identifier */
237  DKNPAGES npages; /* Number of pages in the archive log */
238  LOG_PAGEID fpageid; /* Logical pageid at physical location 1 in archive log */
239  int arv_num; /* The archive number */
240  INT32 dummy2; /* Dummy field for 8byte align */
241 
243  : magic {'0'}
244  , dummy (0)
245  , db_creation (0)
246  , next_trid (0)
247  , npages (0)
248  , fpageid (0)
249  , arv_num (0)
250  , dummy2 (0)
251  {
252  }
253 };
254 #endif // !_LOG_STORAGE_HPP_
DKNPAGES npages
float db_compatibility
bool was_active_log_reset
LOG_LSA bkup_level1_lsa
int TRANID
#define MVCCID_FIRST
PAGEID DKNPAGES
LOG_HDRPAGE hdr
Definition: log_storage.hpp:84
MVCCID oldest_visible_mvccid
const LOG_PAGEID LOGPB_HEADER_PAGE_ID
Definition: log_storage.hpp:51
PAGEID LOG_PHY_PAGEID
const size_t LOGPB_BUFFER_NPAGES_LOWER
Definition: log_storage.hpp:56
#define REL_MAX_RELEASE_LENGTH
#define MVCCID_NULL
LOG_PAGEID fpageid
LOG_LSA append_lsa
bool has_logging_been_skipped
const size_t MAXLOGNAME
Definition: log_storage.hpp:88
INT64 db_creation
INT64 db_restore_time
std::int64_t VACUUM_LOG_BLOCKID
Definition: log_storage.hpp:91
LOG_PAGEID fpageid
PGLENGTH db_logpagesize
#define CUBRID_MAGIC_MAX_LENGTH
int last_deleted_arv_num
int ha_server_state
LOG_PAGEID logical_pageid
Definition: log_storage.hpp:65
int ha_file_status
INT64 ha_promotion_time
ha_server_state
Definition: boot.h:115
LOG_PAGEID nxarv_pageid
INT64 LOG_PAGEID
UINT64 MVCCID
LOG_LSA bkup_level2_lsa
int last_arv_num_for_syscrashes
PGLENGTH offset
Definition: log_storage.hpp:66
MVCCID newest_block_mvccid
PGLENGTH db_iopagesize
LOG_PHY_PAGEID nxarv_phy_pageid
INT16 PGLENGTH
bool is_shutdown
LOG_LSA smallest_lsa_at_last_chkpt
LOG_LSA eof_lsa
VACUUM_LOG_BLOCKID vacuum_last_blockid
LOG_LSA bkup_level0_lsa
TRANID next_trid
MVCCID mvcc_next_id
LOG_LSA mvcc_op_log_lsa
const size_t LOGPB_IO_NPAGES
Definition: log_storage.hpp:55
LOG_LSA chkpt_lsa
const TRANID LOG_SYSTEM_TRANID
const log_lsa NULL_LSA
Definition: log_lsa.hpp:59
int perm_status_obsolete
bool does_block_need_vacuum
bool mark_will_del