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