1 /*
2 Copyright (c) 2003, 2021, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 #include "records.hpp"
26
27 #define JAM_FILE_ID 448
28
29
printOut(const char * string,Uint32 value)30 void printOut(const char *string, Uint32 value) {
31 ndbout_c("%-30s%-12u%-12x", string, value, value);
32 }
33
34 //----------------------------------------------------------------
35 //
36 //----------------------------------------------------------------
37
check()38 bool AbortTransactionRecord::check() {
39 // Not implemented yet.
40 return true;
41 }
42
getLogRecordSize()43 Uint32 AbortTransactionRecord::getLogRecordSize() {
44 return ABORTTRANSACTIONRECORDSIZE;
45 }
46
operator <<(NdbOut & no,const AbortTransactionRecord & atr)47 NdbOut& operator<<(NdbOut& no, const AbortTransactionRecord& atr) {
48 no << "----------ABORT TRANSACTION RECORD-------------" << endl << endl;
49 printOut("Record type:", atr.m_recordType);
50 printOut("TransactionId1:", atr.m_transactionId1);
51 printOut("TransactionId2:", atr.m_transactionId2);
52 no << endl;
53 return no;
54 }
55
56 //----------------------------------------------------------------
57 //
58 //----------------------------------------------------------------
59
check()60 bool NextMbyteRecord::check() {
61 // Not implemented yet.
62 return true;
63 }
64
getLogRecordSize()65 Uint32 NextMbyteRecord::getLogRecordSize() {
66 return NEXTMBYTERECORDSIZE;
67 }
68
operator <<(NdbOut & no,const NextMbyteRecord & nmr)69 NdbOut& operator<<(NdbOut& no, const NextMbyteRecord& nmr) {
70 no << "----------NEXT MBYTE RECORD--------------------" << endl << endl;
71 printOut("Record type:", nmr.m_recordType);
72 no << endl;
73 return no;
74 }
75
76 //----------------------------------------------------------------
77 //
78 //----------------------------------------------------------------
79
check()80 bool CommitTransactionRecord::check() {
81 // Not implemented yet.
82 return true;
83 }
84
getLogRecordSize()85 Uint32 CommitTransactionRecord::getLogRecordSize() {
86 return COMMITTRANSACTIONRECORDSIZE;
87 }
88
operator <<(NdbOut & no,const CommitTransactionRecord & ctr)89 NdbOut& operator<<(NdbOut& no, const CommitTransactionRecord& ctr) {
90 no << "----------COMMIT TRANSACTION RECORD------------" << endl << endl;
91 printOut("Record type:", ctr.m_recordType);
92 printOut("TableId", ctr.m_tableId);
93 printOut("SchemaVersion:", ctr.m_schemaVersion);
94 printOut("FfragmentId", ctr.m_fragmentId);
95 printOut("File no. of Prep. Op.", ctr.m_fileNumberOfPrepareOperation);
96 printOut("Start page no. of Prep. Op.", ctr.m_startPageNumberOfPrepareOperation);
97 printOut("Start page index of Prep. Op.", ctr.m_startPageIndexOfPrepareOperation);
98 printOut("Stop page no. of Prep. Op.", ctr.m_stopPageNumberOfPrepareOperation);
99 printOut("GlobalCheckpoint", ctr.m_globalCheckpoint);
100
101 no << endl;
102 return no;
103 }
104
105 //----------------------------------------------------------------
106 //
107 //----------------------------------------------------------------
108
check()109 bool InvalidCommitTransactionRecord::check() {
110 // Not implemented yet.
111 return true;
112 }
113
getLogRecordSize()114 Uint32 InvalidCommitTransactionRecord::getLogRecordSize() {
115 return COMMITTRANSACTIONRECORDSIZE;
116 }
117
operator <<(NdbOut & no,const InvalidCommitTransactionRecord & ictr)118 NdbOut& operator<<(NdbOut& no, const InvalidCommitTransactionRecord& ictr) {
119 no << "------INVALID COMMIT TRANSACTION RECORD--------" << endl << endl;
120 printOut("Record type:", ictr.m_recordType);
121 printOut("TableId", ictr.m_tableId);
122 printOut("FfragmentId", ictr.m_fragmentId);
123 printOut("File no. of Prep. Op.", ictr.m_fileNumberOfPrepareOperation);
124 printOut("Start page no. of Prep. Op.", ictr.m_startPageNumberOfPrepareOperation);
125 printOut("Start page index of Prep. Op.", ictr.m_startPageIndexOfPrepareOperation);
126 printOut("Stop page no. of Prep. Op.", ictr.m_stopPageNumberOfPrepareOperation);
127 printOut("GlobalCheckpoint", ictr.m_globalCheckpoint);
128
129 no << endl;
130 return no;
131 }
132
133 //----------------------------------------------------------------
134 //
135 //----------------------------------------------------------------
136
check()137 bool PrepareOperationRecord::check() {
138 // Not fully implemented.
139 if (m_operationType == 3 && m_attributeLength != 0)
140 return false;
141
142 if (m_logRecordSize != (m_attributeLength + m_keyLength + 8))
143 return false;
144
145 return true;
146 }
147
getLogRecordSize(Uint32 wordsRead)148 Uint32 PrepareOperationRecord::getLogRecordSize(Uint32 wordsRead) {
149 if (wordsRead < 2)
150 return 2; // make sure we read more
151 return m_logRecordSize;
152 }
153
operator <<(NdbOut & no,const PrepareOperationRecord & por)154 NdbOut& operator<<(NdbOut& no, const PrepareOperationRecord& por) {
155 no << "-----------PREPARE OPERATION RECORD------------" << endl << endl;
156 printOut("Record type:", por.m_recordType);
157 printOut("logRecordSize:", por.m_logRecordSize);
158 printOut("hashValue:", por.m_hashValue);
159 switch (por.m_operationType) {
160 case 0:
161 ndbout_c("%-30s%-12u%-6s", "operationType:",
162 por.m_operationType, "read");
163 break;
164 case 1:
165 ndbout_c("%-30s%-12u%-6s", "operationType:",
166 por.m_operationType, "update");
167 break;
168 case 2:
169 ndbout_c("%-30s%-12u%-6s", "operationType:",
170 por.m_operationType, "insert");
171 break;
172 case 3:
173 ndbout_c("%-30s%-12u%-6s", "operationType:",
174 por.m_operationType, "delete");
175 break;
176 default:
177 printOut("operationType:", por.m_operationType);
178 }
179 printOut("page_no: ", por.m_page_no);
180 printOut("page_idx: ", por.m_page_idx);
181 printOut("attributeLength:", por.m_attributeLength);
182 printOut("keyLength:", por.m_keyLength);
183
184 #if 1
185 // Print keydata
186 Uint32* p = (Uint32*)&por.m_keyInfo;
187 for(Uint32 i=0; i < por.m_keyLength; i++){
188 printOut("keydata:", *p);
189 p++;
190 }
191
192 // Print attrdata
193 for(Uint32 i=0; i < por.m_attributeLength; i++){
194 printOut("attrdata:", *p);
195 p++;
196 }
197 #endif
198
199 no << endl;
200 return no;
201 }
202
203 //----------------------------------------------------------------
204 //
205 //----------------------------------------------------------------
206
check()207 bool CompletedGCIRecord::check() {
208 // Not implemented yet.
209 return true;
210 }
211
getLogRecordSize()212 Uint32 CompletedGCIRecord::getLogRecordSize() {
213 return COMPLETEDGCIRECORDSIZE;
214 }
215
operator <<(NdbOut & no,const CompletedGCIRecord & cGCIr)216 NdbOut& operator<<(NdbOut& no, const CompletedGCIRecord& cGCIr) {
217 no << "-----------COMPLETED GCI RECORD----------------" << endl << endl;
218 printOut("Record type:", cGCIr.m_recordType);
219 printOut("Completed GCI:", cGCIr.m_theCompletedGCI);
220 no << endl;
221 return no;
222 }
223
224 //----------------------------------------------------------------
225 //
226 //----------------------------------------------------------------
227
check()228 bool NextLogRecord::check() {
229 // Not implemented yet.
230 return true;
231 }
232
getLogRecordSize(Uint32 pageIndex)233 Uint32 NextLogRecord::getLogRecordSize(Uint32 pageIndex) {
234 return PAGESIZE - pageIndex;
235 }
236
operator <<(NdbOut & no,const NextLogRecord & nl)237 NdbOut& operator<<(NdbOut& no, const NextLogRecord& nl) {
238 no << "-----------NEXT LOG RECORD --------------------" << endl << endl;
239 printOut("Record type:", nl.m_recordType);
240 no << endl;
241 return no;
242 }
243
244 //----------------------------------------------------------------
245 //
246 //----------------------------------------------------------------
247
getLogRecordSize()248 Uint32 PageHeader::getLogRecordSize() {
249 return PAGEHEADERSIZE;
250 }
251
check()252 bool PageHeader::check() {
253 // Not implemented yet.
254 return true;
255 }
256
lastPage()257 bool PageHeader::lastPage()
258 {
259 return m_next_page == 0xffffff00;
260 }
261
lastWord()262 Uint32 PageHeader::lastWord()
263 {
264 return m_current_page_index;
265 }
266
267
operator <<(NdbOut & no,const PageHeader & ph)268 NdbOut& operator<<(NdbOut& no, const PageHeader& ph) {
269 no << "------------PAGE HEADER------------------------" << endl << endl;
270 ndbout_c("%-30s%-12s%-12s\n", "", "Decimal", "Hex");
271 printOut("Checksum:", ph.m_checksum);
272 printOut("Laps since initial start:", ph.m_lap);
273 printOut("Max gci completed:", ph.m_max_gci_completed);
274 printOut("Max gci started:", ph.m_max_gci_started);
275 printOut("Ptr to next page:", ph.m_next_page);
276 printOut("Ptr to previous page:", ph.m_previous_page);
277 printOut("Ndb version:", ph.m_ndb_version);
278 printOut("Number of log files:", ph.m_number_of_logfiles);
279 printOut("Current page index:", ph.m_current_page_index);
280 printOut("Oldest prepare op. file No.:", ph.m_old_prepare_file_number);
281 printOut("Oldest prepare op. page ref.:", ph.m_old_prepare_page_reference);
282 printOut("Dirty flag:", ph.m_dirty_flag);
283 printOut("Write Timer:", ph.m_log_timer);
284 printOut("Page i-val:", ph.m_page_i_value);
285 printOut("Place written:", ph.m_place_written_from);
286 printOut("Page No in File:", ph.m_page_no);
287 printOut("File No:", ph.m_file_no);
288 printOut("Word Written:", ph.m_word_written);
289 printOut("In Writing (should be 1)", ph.m_in_writing_flag);
290 printOut("Prev Page No (can be garbage)", ph.m_prev_page_no);
291 printOut("In Free List (should be 0):", ph.m_in_free_list);
292 no << endl;
293 return no;
294 }
295
296 //----------------------------------------------------------------
297 //
298 //----------------------------------------------------------------
299
getLogRecordSize()300 Uint32 FileDescriptor::getLogRecordSize() {
301 return FILEDESCRIPTORHEADERSIZE
302 + m_fdHeader.m_noOfDescriptors * NO_MBYTE_IN_FILE * FILEDESCRIPTORENTRYSIZE;
303 }
304
305 static
306 const Uint32 *
printFileDescriptorRecord(Uint32 no,const Uint32 * ptr)307 printFileDescriptorRecord(Uint32 no, const Uint32 * ptr)
308 {
309 ndbout << "------------------FILE DESCRIPTOR " << no
310 <<" ---------------------" << endl << endl;
311 ndbout_c("%-30s%-12s%-12s\n", "", "Decimal", "Hex");
312
313 const Uint32 * completed = ptr;
314 const Uint32 * started = (ptr + NO_MBYTE_IN_FILE);
315 const Uint32 * prepref = (ptr + 2 * NO_MBYTE_IN_FILE);
316 for(unsigned i = 0; i < NO_MBYTE_IN_FILE; i++)
317 {
318 ndbout_c(" mb: %u Max GCI completed: %u"
319 " Max GCI started: %u Last prepared ref: %u (file: %u mb: %u)",
320 i,
321 completed[i],
322 started[i],
323 prepref[i],
324 (prepref[i] >> 16),
325 (prepref[i] & 65535));
326 }
327 ndbout << endl;
328 return ptr + 3 * NO_MBYTE_IN_FILE;
329 }
330
331
operator <<(NdbOut & no,const FileDescriptor & fd)332 NdbOut& operator<<(NdbOut& no, const FileDescriptor& fd) {
333 no << "-------FILE DESCRIPTOR HEADER------------------" << endl << endl;
334 printOut("Record type:", fd.m_fdHeader.m_recordType);
335 printOut("Number of file descriptors:", fd.m_fdHeader.m_noOfDescriptors);
336 printOut("File number:", fd.m_fdHeader.m_fileNo);
337 ndbout << endl;
338 const Uint32 * ptr = fd.m_fdRecord;
339 for(Uint32 i = 0; i < fd.m_fdHeader.m_noOfDescriptors; i++)
340 {
341 ptr = printFileDescriptorRecord(i, ptr);
342 }
343 return no;
344 }
345
check()346 bool FileDescriptor::check() {
347 // Not implemented yet.
348 return true;
349 }
350
351 //----------------------------------------------------------------
352 //
353 //----------------------------------------------------------------
354