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