CUBRID Engine  latest
log_record.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 // log_record - define log record structures
21 //
22 
23 #ifndef _LOG_RECORD_HPP_
24 #define _LOG_RECORD_HPP_
25 
26 // todo - this should not be exposed to client after HA refactoring
27 // todo - add to a proper namespace
28 
29 #include "client_credentials.hpp"
30 #include "log_lsa.hpp"
31 #include "recovery.h"
32 #include "storage_common.h"
33 #include "system.h"
34 
36 {
37  /* In order of likely of appearance in the log */
38  LOG_SMALLER_LOGREC_TYPE = 0, /* A lower bound check */
39 
40 #if 0
41  LOG_CLIENT_NAME = 1, /* Obsolete */
42 #endif
43  LOG_UNDOREDO_DATA = 2, /* An undo and redo data record */
44  LOG_UNDO_DATA = 3, /* Only undo data */
45  LOG_REDO_DATA = 4, /* Only redo data */
46  LOG_DBEXTERN_REDO_DATA = 5, /* Only database external redo data */
47  LOG_POSTPONE = 6, /* Postpone redo data */
48  LOG_RUN_POSTPONE = 7, /* Run/redo a postpone data. Only for transactions committed with postpone operations */
49  LOG_COMPENSATE = 8, /* Compensation record (compensate a undo record of an aborted tran) */
50 #if 0
51  LOG_LCOMPENSATE = 9, /* Obsolete */
52  LOG_CLIENT_USER_UNDO_DATA = 10, /* Obsolete */
53  LOG_CLIENT_USER_POSTPONE_DATA = 11, /* Obsolete */
54  LOG_RUN_NEXT_CLIENT_UNDO = 12, /* Obsolete */
55  LOG_RUN_NEXT_CLIENT_POSTPONE = 13, /* Obsolete */
56 #endif
57  LOG_WILL_COMMIT = 14, /* Transaction will be committed */
58  LOG_COMMIT_WITH_POSTPONE = 15, /* Committing server postpone operations */
59 #if 0
60  LOG_COMMIT_WITH_CLIENT_USER_LOOSE_ENDS = 16, /* Obsolete */
61 #endif
62  LOG_COMMIT = 17, /* A commit record */
63  LOG_SYSOP_START_POSTPONE = 18, /* Committing server top system postpone operations */
64 #if 0
65  LOG_COMMIT_TOPOPE_WITH_CLIENT_USER_LOOSE_ENDS = 19, /* Obsolete */
66 #endif
67  LOG_SYSOP_END = 20, /* end of system operation record. Its functionality can vary based on LOG_SYSOP_END_TYPE:
68  *
69  * - LOG_SYSOP_END_COMMIT: the usual functionality. changes under system operation become
70  * permanent immediately
71  *
72  * - LOG_SYSOP_END_LOGICAL_UNDO: system operation is used for complex logical operation (that
73  * usually affects more than one page). end system operation also includes undo data that
74  * is processed during rollback or undo.
75  *
76  * - LOG_SYSOP_END_LOGICAL_COMPENSATE: system operation is used for complex logical operation
77  * that has the purpose of compensating a change on undo or rollback. end system operation
78  * also includes the LSA of previous undo log record.
79  *
80  * - LOG_SYSOP_END_LOGICAL_RUN_POSTPONE: system operation is used for complex logical operation
81  * that has the purpose of running a postpone record. end system operation also includes the
82  * postpone LSA and is_sysop_postpone (recovery is different for logical run postpones during
83  * system operation postpone compared to transaction postpone).
84  *
85  * - LOG_SYSOP_END_ABORT: any of the above system operations are not ended due to crash or
86  * errors. the system operation is rollbacked and ended with this type.
87  */
88 #if 0
89  LOG_ABORT_WITH_CLIENT_USER_LOOSE_ENDS = 21, /* Obsolete */
90 #endif
91  LOG_ABORT = 22, /* An abort record */
92 #if 0
93  LOG_ABORT_TOPOPE_WITH_CLIENT_USER_LOOSE_ENDS = 23, /* Obsolete */
94 #endif
95  LOG_ABORT_TOPOPE = 24, /* obsolete */
96  LOG_START_CHKPT = 25, /* Start a checkpoint */
97  LOG_END_CHKPT = 26, /* Checkpoint information */
98  LOG_SAVEPOINT = 27, /* A user savepoint record */
99  LOG_2PC_PREPARE = 28, /* A prepare to commit record */
100  LOG_2PC_START = 29, /* Start the 2PC protocol by sending vote request messages to participants of
101  * distributed tran. */
102  LOG_2PC_COMMIT_DECISION = 30, /* Beginning of the second phase of 2PC, need to perform local & global commits. */
103  LOG_2PC_ABORT_DECISION = 31, /* Beginning of the second phase of 2PC, need to perform local & global aborts. */
104  LOG_2PC_COMMIT_INFORM_PARTICPS = 32, /* Committing, need to inform the participants */
105  LOG_2PC_ABORT_INFORM_PARTICPS = 33, /* Aborting, need to inform the participants */
106  LOG_2PC_RECV_ACK = 34, /* Received ack. from the participant that it received the decision on the fate of
107  * dist. trans. */
108  LOG_END_OF_LOG = 35, /* End of log */
109  LOG_DUMMY_HEAD_POSTPONE = 36, /* A dummy log record. No-op */
110  LOG_DUMMY_CRASH_RECOVERY = 37, /* A dummy log record which indicate the start of crash recovery. No-op */
111 
112 #if 0 /* not used */
113  LOG_DUMMY_FILLPAGE_FORARCHIVE = 38, /* Indicates logical end of current page so it could be archived safely. No-op
114  * This record is not generated no more. It's kept for backward compatibility. */
115 #endif
116  LOG_REPLICATION_DATA = 39, /* Replication log for insert, delete or update */
117  LOG_REPLICATION_STATEMENT = 40, /* Replication log for schema, index, trigger or system catalog updates */
118 #if 0
119  LOG_UNLOCK_COMMIT = 41, /* for repl_agent to guarantee the order of */
120  LOG_UNLOCK_ABORT = 42, /* transaction commit, we append the unlock info. before calling lock_unlock_all() */
121 #endif
122  LOG_DIFF_UNDOREDO_DATA = 43, /* diff undo redo data */
123  LOG_DUMMY_HA_SERVER_STATE = 44, /* HA server state */
124  LOG_DUMMY_OVF_RECORD = 45, /* indicator of the first part of an overflow record */
125 
126  LOG_MVCC_UNDOREDO_DATA = 46, /* Undoredo for MVCC operations (will require more fields than a regular undo-redo. */
127  LOG_MVCC_UNDO_DATA = 47, /* Undo for MVCC operations */
128  LOG_MVCC_REDO_DATA = 48, /* Redo for MVCC operations */
129  LOG_MVCC_DIFF_UNDOREDO_DATA = 49, /* diff undo redo data for MVCC operations */
130  LOG_SYSOP_ATOMIC_START = 50, /* Log marker to start atomic operations that need to be rollbacked immediately after
131  * redo phase of recovery and before finishing postpones */
132 
133  LOG_DUMMY_GENERIC, /* used for flush for now. it is ridiculous to create dummy log records for every single
134  * case. we should find a different approach */
135 
136  LOG_LARGER_LOGREC_TYPE /* A higher bound for checks */
137 };
139 
140 /* Description of a log record */
143 {
144  LOG_LSA prev_tranlsa; /* Address of previous log record for the same transaction */
145  LOG_LSA back_lsa; /* Backward log address */
146  LOG_LSA forw_lsa; /* Forward log address */
147  TRANID trid; /* Transaction identifier of the log record */
148  LOG_RECTYPE type; /* Log record type (e.g., commit, abort) */
149 };
150 
151 /* Common information of log data records */
152 typedef struct log_data LOG_DATA;
153 struct log_data
154 {
155  LOG_RCVINDEX rcvindex; /* Index to recovery function */
156  PAGEID pageid; /* Pageid of recovery data */
157  PGLENGTH offset; /* offset of recovery data in pageid */
158  VOLID volid; /* Volume identifier of recovery data */
159 };
160 
161 /* Information of undo_redo log records */
164 {
165  LOG_DATA data; /* Location of recovery data */
166  int ulength; /* Length of undo data */
167  int rlength; /* Length of redo data */
168 };
169 
170 /* Information of undo log records */
171 typedef struct log_rec_undo LOG_REC_UNDO;
173 {
174  LOG_DATA data; /* Location of recovery data */
175  int length; /* Length of undo data */
176 };
177 
178 /* Information of redo log records */
179 typedef struct log_rec_redo LOG_REC_REDO;
181 {
182  LOG_DATA data; /* Location of recovery data */
183  int length; /* Length of redo data */
184 };
185 
186 /* Log information required for vacuum */
189 {
190  LOG_LSA prev_mvcc_op_log_lsa; /* Log lsa of previous MVCC operation log record. Used by vacuum to process log data. */
191  VFID vfid; /* File identifier. Will be used by vacuum for heap files (TODO: maybe b-tree too).
192  * Used to: - Find if the file was dropped/reused. - Find the type of objects in heap
193  * file (reusable or referable). */
194 };
195 
196 /* Information of undo_redo log records for MVCC operations */
199 {
200  LOG_REC_UNDOREDO undoredo; /* Undoredo information */
201  MVCCID mvccid; /* MVCC Identifier for transaction */
202  LOG_VACUUM_INFO vacuum_info; /* Info required for vacuum */
203 };
204 
205 /* Information of undo log records for MVCC operations */
208 {
209  LOG_REC_UNDO undo; /* Undo information */
210  MVCCID mvccid; /* MVCC Identifier for transaction */
211  LOG_VACUUM_INFO vacuum_info; /* Info required for vacuum */
212 };
213 
214 /* Information of redo log records for MVCC operations */
217 {
218  LOG_REC_REDO redo; /* Location of recovery data */
219  MVCCID mvccid; /* MVCC Identifier for transaction */
220 };
221 
222 /* replication log structure */
225 {
227  int length;
228  int rcvindex;
229 };
230 
231 /* Log the time of termination of transaction */
234 {
235  INT64 at_time; /* Database creation time. For safety reasons */
236 };
237 
238 /* Log the change of the server's HA state */
241 {
242  int state; /* ha_Server_state */
243  int dummy; /* dummy for alignment */
244 
245  INT64 at_time; /* time recorded by active server */
246 };
247 
248 /* Information of database external redo log records */
251 {
252  LOG_RCVINDEX rcvindex; /* Index to recovery function */
253  int length; /* Length of redo data */
254 };
255 
256 /* Information of a compensating log records */
259 {
260  LOG_DATA data; /* Location of recovery data */
261  LOG_LSA undo_nxlsa; /* Address of next log record to undo */
262  int length; /* Length of compensating data */
263 };
264 
265 /* This entry is included during commit */
268 {
270 };
271 
272 /* types of end system operation */
274 {
275  LOG_SYSOP_END_COMMIT, /* permanent changes */
276  LOG_SYSOP_END_ABORT, /* aborted system op */
277  LOG_SYSOP_END_LOGICAL_UNDO, /* logical undo */
278  LOG_SYSOP_END_LOGICAL_MVCC_UNDO, /* logical mvcc undo */
279  LOG_SYSOP_END_LOGICAL_COMPENSATE, /* logical compensate */
280  LOG_SYSOP_END_LOGICAL_RUN_POSTPONE /* logical run postpone */
281 };
283 #define LOG_SYSOP_END_TYPE_CHECK(type) \
284  assert ((type) == LOG_SYSOP_END_COMMIT \
285  || (type) == LOG_SYSOP_END_ABORT \
286  || (type) == LOG_SYSOP_END_LOGICAL_UNDO \
287  || (type) == LOG_SYSOP_END_LOGICAL_MVCC_UNDO \
288  || (type) == LOG_SYSOP_END_LOGICAL_COMPENSATE \
289  || (type) == LOG_SYSOP_END_LOGICAL_RUN_POSTPONE)
290 
291 /* end system operation log record */
294 {
295  LOG_LSA lastparent_lsa; /* last address before the top action */
296  LOG_LSA prv_topresult_lsa; /* previous top action (either, partial abort or partial commit) address */
297  LOG_SYSOP_END_TYPE type; /* end system op type */
298  /* File where the page belong. same as mvcc_undo->vacuum_info if type == LOG_SYSOP_END_LOGICAL_MVCC_UNDO. It is used to get TDE information.*/
299  const VFID *vfid;
300  union /* other info based on type */
301  {
302  LOG_REC_UNDO undo; /* undo data for logical undo */
303  LOG_REC_MVCC_UNDO mvcc_undo; /* undo data for logical undo of MVCC operation */
304  LOG_LSA compensate_lsa; /* compensate lsa for logical compensate */
305  struct
306  {
307  LOG_LSA postpone_lsa; /* postpone lsa */
308  bool is_sysop_postpone; /* true if run postpone is used during a system op postpone, false if used during
309  * transaction postpone */
310  } run_postpone; /* run postpone info */
311  };
312 };
313 
314 /* This entry is included during the commit of top system operations */
317 {
318  LOG_REC_SYSOP_END sysop_end; /* log record used for end of system operation */
319  LOG_LSA posp_lsa; /* address where the first postpone operation start */
320 };
321 
322 /* Information of execution of a postpone data */
325 {
326  LOG_DATA data; /* Location of recovery data */
327  LOG_LSA ref_lsa; /* Address of the original postpone record */
328  int length; /* Length of redo data */
329 };
330 
331 /* A checkpoint record */
334 {
335  LOG_LSA redo_lsa; /* Oldest LSA of dirty data page in page buffers */
336  int ntrans; /* Number of active transactions */
337  int ntops; /* Total number of system operations */
338 };
339 
340 /* Transaction descriptor */
343 {
345  TRANID trid; /* Transaction identifier */
346  TRAN_STATE state; /* Transaction state (e.g., Active, aborted) */
347  LOG_LSA head_lsa; /* First log address of transaction */
348  LOG_LSA tail_lsa; /* Last log record address of transaction */
349  LOG_LSA undo_nxlsa; /* Next log record address of transaction for UNDO purposes. Needed since compensating
350  * log records are logged during UNDO */
351  LOG_LSA posp_nxlsa; /* First address of a postpone record */
352  LOG_LSA savept_lsa; /* Address of last savepoint */
353  LOG_LSA tail_topresult_lsa; /* Address of last partial abort/commit */
354  LOG_LSA start_postpone_lsa; /* Address of start postpone (if transaction was doing postpone during checkpoint) */
355  char user_name[LOG_USERNAME_MAX]; /* Name of the client */
356 
357 };
358 
361 {
362  TRANID trid; /* Transaction identifier */
363  LOG_LSA sysop_start_postpone_lsa; /* saved lsa of system op start postpone log record */
364  LOG_LSA atomic_sysop_start_lsa; /* saved lsa of atomic system op start */
365 };
366 
369 {
370  LOG_LSA prv_savept; /* Previous savepoint record */
371  int length; /* Savepoint name */
372 };
373 
374 /* Log a prepare to commit record */
377 {
378  char user_name[DB_MAX_USER_LENGTH + 1]; /* Name of the client */
379  int gtrid; /* Identifier of the global transaction */
380  int gtrinfo_length; /* length of the global transaction info */
381  unsigned int num_object_locks; /* Total number of update-type locks acquired by this transaction on the
382  * objects. */
383  unsigned int num_page_locks; /* Total number of update-type locks acquired by this transaction on the pages. */
384 };
385 
386 /* Start 2PC protocol. Record information about identifiers of participants. */
389 {
390  char user_name[DB_MAX_USER_LENGTH + 1]; /* Name of the client */
391  int gtrid; /* Identifier of the global tran */
392  int num_particps; /* number of participants */
393  int particp_id_length; /* length of a participant identifier */
394 };
395 
396 /*
397  * Log the acknowledgment from a participant that it received the commit/abort
398  * decision
399  */
402 {
403  int particp_index; /* Index of the acknowledging participant */
404 };
405 
406 #define LOG_GET_LOG_RECORD_HEADER(log_page_p, lsa) \
407  ((LOG_RECORD_HEADER *) ((log_page_p)->area + (lsa)->offset))
408 
409 /* Definitions used to identify UNDO/REDO/UNDOREDO log record data types */
410 
411 /* Is record type UNDO */
412 #define LOG_IS_UNDO_RECORD_TYPE(type) \
413  (((type) == LOG_UNDO_DATA) || ((type) == LOG_MVCC_UNDO_DATA))
414 
415 /* Is record type REDO */
416 #define LOG_IS_REDO_RECORD_TYPE(type) \
417  (((type) == LOG_REDO_DATA) || ((type) == LOG_MVCC_REDO_DATA))
418 
419 /* Is record type UNDOREDO */
420 #define LOG_IS_UNDOREDO_RECORD_TYPE(type) \
421  (((type) == LOG_UNDOREDO_DATA) || ((type) == LOG_MVCC_UNDOREDO_DATA) \
422  || ((type) == LOG_DIFF_UNDOREDO_DATA) || ((type) == LOG_MVCC_DIFF_UNDOREDO_DATA))
423 
424 #define LOG_IS_DIFF_UNDOREDO_TYPE(type) \
425  ((type) == LOG_DIFF_UNDOREDO_DATA || (type) == LOG_MVCC_DIFF_UNDOREDO_DATA)
426 
427 /* Is record type used a MVCC operation */
428 #define LOG_IS_MVCC_OP_RECORD_TYPE(type) \
429  (((type) == LOG_MVCC_UNDO_DATA) \
430  || ((type) == LOG_MVCC_REDO_DATA) \
431  || ((type) == LOG_MVCC_UNDOREDO_DATA) \
432  || ((type) == LOG_MVCC_DIFF_UNDOREDO_DATA))
433 
434 #endif // _LOG_RECORD_HPP_
unsigned int num_object_locks
Definition: log_record.hpp:381
LOG_REC_UNDO undo
Definition: log_record.hpp:209
LOG_SYSOP_END_TYPE type
Definition: log_record.hpp:297
const VFID * vfid
Definition: log_record.hpp:299
LOG_DATA data
Definition: log_record.hpp:182
int TRANID
LOG_VACUUM_INFO vacuum_info
Definition: log_record.hpp:211
LOG_REC_UNDO undo
Definition: log_record.hpp:302
LOG_RCVINDEX
Definition: recovery.h:36
LOG_REC_REDO redo
Definition: log_record.hpp:218
log_sysop_end_type
Definition: log_record.hpp:273
LOG_LSA forw_lsa
Definition: log_record.hpp:146
LOG_LSA prev_tranlsa
Definition: log_record.hpp:144
INT16 VOLID
VOLID volid
Definition: log_record.hpp:158
LOG_LSA atomic_sysop_start_lsa
Definition: log_record.hpp:364
LOG_VACUUM_INFO vacuum_info
Definition: log_record.hpp:202
LOG_LSA back_lsa
Definition: log_record.hpp:145
PGLENGTH offset
Definition: log_record.hpp:157
LOG_RECTYPE type
Definition: log_record.hpp:148
LOG_REC_SYSOP_END sysop_end
Definition: log_record.hpp:318
LOG_LSA prv_savept
Definition: log_record.hpp:370
enum log_rectype LOG_RECTYPE
Definition: log_record.hpp:138
LOG_REC_MVCC_UNDO mvcc_undo
Definition: log_record.hpp:303
LOG_LSA prev_mvcc_op_log_lsa
Definition: log_record.hpp:190
LOG_DATA data
Definition: log_record.hpp:174
UINT64 MVCCID
LOG_LSA lastparent_lsa
Definition: log_record.hpp:295
LOG_REC_UNDOREDO undoredo
Definition: log_record.hpp:200
LOG_LSA prv_topresult_lsa
Definition: log_record.hpp:296
INT16 PGLENGTH
LOG_LSA compensate_lsa
Definition: log_record.hpp:304
LOG_LSA redo_lsa
Definition: log_record.hpp:335
PAGEID pageid
Definition: log_record.hpp:156
LOG_LSA sysop_start_postpone_lsa
Definition: log_record.hpp:363
const size_t LOG_USERNAME_MAX
LOG_RCVINDEX rcvindex
Definition: log_record.hpp:155
enum log_sysop_end_type LOG_SYSOP_END_TYPE
Definition: log_record.hpp:282
TRAN_STATE
Definition: log_comm.h:36
INT32 PAGEID
unsigned int num_page_locks
Definition: log_record.hpp:383
#define DB_MAX_USER_LENGTH
Definition: dbtype_def.h:498
LOG_RCVINDEX rcvindex
Definition: log_record.hpp:252
log_rectype
Definition: log_record.hpp:35