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