CUBRID Engine  latest
log_append.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_append - creating & appending log records
21 //
22 
23 #ifndef _LOG_APPEND_HPP_
24 #define _LOG_APPEND_HPP_
25 
26 #if !defined (SERVER_MODE) && !defined (SA_MODE)
27 #error Wrong module
28 #endif
29 
30 #include "log_lsa.hpp"
31 #include "log_record.hpp"
32 #include "log_storage.hpp"
33 #include "memory_alloc.h"
35 #include "recovery.h"
36 #include "storage_common.h"
37 
38 #include <atomic>
39 #include <mutex>
40 
41 // forward declarations
42 struct log_tdes;
43 
44 typedef struct log_crumb LOG_CRUMB;
45 struct log_crumb
46 {
47  int length;
48  const void *data;
49 };
50 
53 {
55 
56  const VFID *vfid; /* File where the page belong or NULL when the page is not associated with a file */
58  offset_type offset; /* Offset or slot */
59 
60  log_data_addr () = default;
61  log_data_addr (const VFID *vfid, PAGE_PTR pgptr, PGLENGTH offset);
62 };
63 #define LOG_DATA_ADDR_INITIALIZER { NULL, NULL, 0 } // todo: remove me
64 
66 {
69 };
70 
73 {
74  int vdes; /* Volume descriptor of active log */
75  std::atomic<LOG_LSA> nxio_lsa; /* Lowest log sequence number which has not been written to disk (for WAL). */
76  /* todo - not really belonging here. should be part of page buffer. */
77  LOG_LSA prev_lsa; /* Address of last append log record */
78  LOG_PAGE *log_pgptr; /* The log page which is fixed */
79 
80  bool appending_page_tde_encrypted; /* true if a newly appended page has to be tde-encrypted */
81 
82  log_append_info ();
83  log_append_info (const log_append_info &other);
84 
85  LOG_LSA get_nxio_lsa () const;
86  void set_nxio_lsa (const LOG_LSA &next_io_lsa);
87 };
88 
91 {
93  LOG_LSA start_lsa; /* for assertion */
94 
95  bool tde_encrypted; /* whether the log page which'll contain this node has to be encrypted */
96 
97  /* data header info */
99  char *data_header;
100 
101  /* data info */
102  int ulength;
103  char *udata;
104  int rlength;
105  char *rdata;
106 
108 };
109 
112 {
115 
116  /* list */
119 
120  INT64 list_size; /* bytes */
121 
122  /* flush list */
124 
126 
128 };
129 
130 //
131 // log record partial updates logging
132 //
139 
145 constexpr size_t LOG_RV_RECORD_UPDPARTIAL_ALIGNED_SIZE (size_t new_data_size);
146 
147 void LOG_RESET_APPEND_LSA (const LOG_LSA *lsa);
148 void LOG_RESET_PREV_LSA (const LOG_LSA *lsa);
149 char *LOG_APPEND_PTR ();
150 
153  LOG_DATA_ADDR *addr, int ulength, const char *udata, int rlength, const char *rdata);
155  LOG_DATA_ADDR *addr, const int num_ucrumbs, const LOG_CRUMB *ucrumbs, const int num_rcrumbs,
156  const LOG_CRUMB *rcrumbs);
160 bool prior_is_tde_encrypted (const log_prior_node *node);
161 void log_append_init_zip ();
162 void log_append_final_zip ();
163 
164 // todo - move to header of log page buffer
165 size_t logpb_get_memsize ();
166 
168 //
169 // Inline/templates
170 //
172 
173 bool
175 {
177 }
178 
179 bool
181 {
183 }
184 
185 bool
187 {
189 }
190 
191 bool
193 {
195 }
196 
197 void
199 {
200  addr->offset = (addr->offset & (~LOG_RV_RECORD_MODIFY_MASK)) | (mode);
201 }
202 
203 constexpr size_t
205 {
206  return DB_ALIGN (new_data_size + OR_SHORT_SIZE + 2 * OR_BYTE_SIZE, INT_ALIGNMENT);
207 }
208 
209 #endif // !_LOG_APPEND_HPP_
char * PAGE_PTR
size_t logpb_get_memsize()
LOG_PRIOR_NODE * prior_list_header
Definition: log_append.hpp:117
bool prior_is_tde_encrypted(const log_prior_node *node)
const log_rv_record_flag_type LOG_RV_RECORD_DELETE
Definition: log_append.hpp:135
const log_rv_record_flag_type LOG_RV_RECORD_UPDATE_ALL
Definition: log_append.hpp:136
LOG_RECORD_HEADER log_header
Definition: log_append.hpp:92
LOG_PRIOR_LSA_LOCK
Definition: log_append.hpp:65
LOG_RCVINDEX
Definition: recovery.h:36
static API_MUTEX mutex
Definition: api_util.c:72
void LOG_RV_RECORD_SET_MODIFY_MODE(log_data_addr *addr, log_rv_record_flag_type mode)
Definition: log_append.hpp:198
PGLENGTH offset_type
Definition: log_append.hpp:54
const log_rv_record_flag_type LOG_RV_RECORD_MODIFY_MASK
Definition: log_append.hpp:138
LOG_PRIOR_NODE * prior_list_tail
Definition: log_append.hpp:118
bool LOG_RV_RECORD_IS_INSERT(log_rv_record_flag_type flags)
Definition: log_append.hpp:174
LOG_PRIOR_NODE * prior_lsa_alloc_and_copy_crumbs(THREAD_ENTRY *thread_p, LOG_RECTYPE rec_type, LOG_RCVINDEX rcvindex, LOG_DATA_ADDR *addr, const int num_ucrumbs, const LOG_CRUMB *ucrumbs, const int num_rcrumbs, const LOG_CRUMB *rcrumbs)
Definition: log_append.cpp:407
#define OR_SHORT_SIZE
std::mutex prior_lsa_mutex
Definition: log_append.hpp:125
bool appending_page_tde_encrypted
Definition: log_append.hpp:80
LOG_PRIOR_NODE * prior_lsa_alloc_and_copy_data(THREAD_ENTRY *thread_p, LOG_RECTYPE rec_type, LOG_RCVINDEX rcvindex, LOG_DATA_ADDR *addr, int ulength, const char *udata, int rlength, const char *rdata)
Definition: log_append.cpp:273
void LOG_RESET_PREV_LSA(const LOG_LSA *lsa)
Definition: log_append.cpp:137
char * LOG_APPEND_PTR()
Definition: log_append.cpp:145
LOG_PRIOR_NODE * prior_flush_list_header
Definition: log_append.hpp:123
void THREAD_ENTRY
char * data_header
Definition: log_append.hpp:99
bool log_prior_has_worker_log_records(THREAD_ENTRY *thread_p)
Definition: log_append.cpp:152
void log_append_init_zip()
Definition: log_append.cpp:185
LOG_LSA start_lsa
Definition: log_append.hpp:93
LOG_PRIOR_NODE * next
Definition: log_append.hpp:107
LOG_PAGE * log_pgptr
Definition: log_append.hpp:78
enum log_rectype LOG_RECTYPE
Definition: log_record.hpp:138
static enum scanner_mode mode
bool LOG_RV_RECORD_IS_UPDATE_ALL(log_rv_record_flag_type flags)
Definition: log_append.hpp:186
bool LOG_RV_RECORD_IS_UPDATE_PARTIAL(log_rv_record_flag_type flags)
Definition: log_append.hpp:192
const log_rv_record_flag_type LOG_RV_RECORD_UPDATE_PARTIAL
Definition: log_append.hpp:137
log_data_addr::offset_type log_rv_record_flag_type
Definition: log_append.hpp:133
void log_append_final_zip()
Definition: log_append.cpp:232
const VFID * vfid
Definition: log_append.hpp:56
PAGE_PTR pgptr
Definition: log_append.hpp:57
offset_type offset
Definition: log_append.hpp:58
LOG_LSA prior_lsa_next_record(THREAD_ENTRY *thread_p, LOG_PRIOR_NODE *node, log_tdes *tdes)
int data_header_length
Definition: log_append.hpp:98
LOG_LSA prev_lsa
Definition: log_append.hpp:77
#define OR_BYTE_SIZE
INT16 PGLENGTH
#define DB_ALIGN(offset, align)
Definition: memory_alloc.h:84
const log_rv_record_flag_type LOG_RV_RECORD_INSERT
Definition: log_append.hpp:134
int prior_set_tde_encrypted(log_prior_node *node, LOG_RCVINDEX recvindex)
#define INT_ALIGNMENT
Definition: memory_alloc.h:61
LOG_LSA prior_lsa_next_record_with_lock(THREAD_ENTRY *thread_p, LOG_PRIOR_NODE *node, log_tdes *tdes)
constexpr size_t LOG_RV_RECORD_UPDPARTIAL_ALIGNED_SIZE(size_t new_data_size)
Definition: log_append.hpp:204
const void * data
Definition: log_append.hpp:48
std::atomic< LOG_LSA > nxio_lsa
Definition: log_append.hpp:75
void LOG_RESET_APPEND_LSA(const LOG_LSA *lsa)
Definition: log_append.cpp:129
bool LOG_RV_RECORD_IS_DELETE(log_rv_record_flag_type flags)
Definition: log_append.hpp:180