#include <ndb_global.h>#include <NdbOut.hpp>#include <UtilBuffer.hpp>#include "diskpage.hpp"#include <ndb_limits.h>#include <dbtup/tuppage.hpp>#include "dbtup/Dbtup.hpp"Include dependency graph for print_file.cpp:

Go to the source code of this file.
Defines | |
| #define | DBTUP_C |
Functions | |
| static void | print_usage (const char *) |
| static int | print_zero_page (int, void *, Uint32 sz) |
| static int | print_extent_page (int, void *, Uint32 sz) |
| static int | print_undo_page (int, void *, Uint32 sz) |
| static int | print_data_page (int, void *, Uint32 sz) |
| static bool | print_page (int page_no) |
| int | main (int argc, char **argv) |
| NdbOut & | operator<< (NdbOut &out, const File_formats::Datafile::Extent_header &obj) |
Variables | |
| int | g_verbosity = 1 |
| int | g_page_size = File_formats::NDB_PAGE_SIZE |
| int(*) | g_print_page (int count, void *, Uint32 sz) = print_zero_page |
| File_formats::Undofile::Zero_page | g_uf_zero |
| File_formats::Datafile::Zero_page | g_df_zero |
| #define DBTUP_C |
Definition at line 249 of file print_file.cpp.
| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
Definition at line 42 of file print_file.cpp.
References buffer, exit, f, filename, g_page_size, g_print_page, g_verbosity, ndbout(), pos(), print_usage(), and strcmp().
00043 { 00044 for(int i = 1; i<argc; i++){ 00045 if(!strncmp(argv[i], "-v", 2)) 00046 { 00047 int pos= 2; 00048 do { 00049 g_verbosity++; 00050 } while(argv[i][pos++] == 'v'); 00051 continue; 00052 } 00053 else if(!strcmp(argv[i], "-q")) 00054 { 00055 g_verbosity--; 00056 continue; 00057 } 00058 else if(!strcmp(argv[i], "-?") || 00059 !strcmp(argv[i], "--?") || 00060 !strcmp(argv[i], "-h") || 00061 !strcmp(argv[i], "--help")) 00062 { 00063 print_usage(argv[0]); 00064 exit(0); 00065 } 00066 00067 const char * filename = argv[i]; 00068 00069 struct stat sbuf; 00070 const int res = stat(filename, &sbuf); 00071 if(res != 0){ 00072 ndbout << "Could not find file: \"" << filename << "\"" << endl; 00073 continue; 00074 } 00075 const Uint32 bytes = sbuf.st_size; 00076 00077 UtilBuffer buffer; 00078 00079 FILE * f = fopen(filename, "rb"); 00080 if(f == 0){ 00081 ndbout << "Failed to open file" << endl; 00082 continue; 00083 } 00084 00085 Uint32 sz; 00086 Uint32 j = 0; 00087 do { 00088 buffer.grow(g_page_size); 00089 sz = fread(buffer.get_data(), 1, g_page_size, f); 00090 if((* g_print_page)(j++, buffer.get_data(), sz)) 00091 break; 00092 } while(sz == g_page_size); 00093 00094 fclose(f); 00095 continue; 00096 } 00097 return 0; 00098 }
Here is the call graph for this function:

| NdbOut& operator<< | ( | NdbOut & | out, | |
| const File_formats::Datafile::Extent_header & | obj | |||
| ) |
Definition at line 161 of file print_file.cpp.
References g_df_zero, File_formats::Datafile::Extent_header::get_free_bits(), File_formats::Datafile::Zero_page::m_extent_size, File_formats::Datafile::Extent_header::m_fragment_id, File_formats::Datafile::Extent_header::m_next_free_extent, File_formats::Datafile::Extent_header::m_table, RNIL, and BaseString::snprintf().
00162 { 00163 if(obj.m_table == RNIL) 00164 { 00165 if(obj.m_next_free_extent != RNIL) 00166 out << " FREE, next free: " << obj.m_next_free_extent; 00167 else 00168 out << " FREE, next free: RNIL"; 00169 } 00170 else 00171 { 00172 out << "table: " << obj.m_table 00173 << " fragment: " << obj.m_fragment_id << " "; 00174 for(Uint32 i = 0; i<g_df_zero.m_extent_size; i++) 00175 { 00176 char t[2]; 00177 BaseString::snprintf(t, sizeof(t), "%x", obj.get_free_bits(i)); 00178 out << t; 00179 } 00180 } 00181 return out; 00182 }
Here is the call graph for this function:

| int print_data_page | ( | int | , | |
| void * | , | |||
| Uint32 | sz | |||
| ) | [static] |
Definition at line 216 of file print_file.cpp.
References g_verbosity, ndbout(), page, print_page(), File_formats::PT_Tup_fixsize_page, File_formats::PT_Tup_varsize_page, and File_formats::PT_Unallocated.
Referenced by print_extent_page().
00216 { 00217 00218 File_formats::Datafile::Data_page * page = 00219 (File_formats::Datafile::Data_page*)ptr; 00220 00221 ndbout << "Data page: " << count 00222 << ", lsn = [ " 00223 << page->m_page_header.m_page_lsn_hi << " " 00224 << page->m_page_header.m_page_lsn_lo << "]" ; 00225 00226 if(g_verbosity > 1 || print_page(count)) 00227 { 00228 switch(page->m_page_header.m_page_type){ 00229 case File_formats::PT_Unallocated: 00230 break; 00231 case File_formats::PT_Tup_fixsize_page: 00232 ndbout << " fix "; 00233 if(g_verbosity > 2 || print_page(count)) 00234 ndbout << (* (Tup_fixsize_page*)page); 00235 break; 00236 case File_formats::PT_Tup_varsize_page: 00237 ndbout << " var "; 00238 if(g_verbosity > 2 || print_page(count)) 00239 ndbout << endl << (* (Tup_varsize_page*)page); 00240 break; 00241 default: 00242 ndbout << " unknown page type: %d" << page->m_page_header.m_page_type; 00243 } 00244 } 00245 ndbout << endl; 00246 return 0; 00247 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int print_extent_page | ( | int | , | |
| void * | , | |||
| Uint32 | sz | |||
| ) | [static] |
Definition at line 185 of file print_file.cpp.
References File_formats::Datafile::extent_header_words(), g_df_zero, g_print_page, File_formats::Datafile::Zero_page::m_extent_count, File_formats::Datafile::Zero_page::m_extent_pages, File_formats::Datafile::Zero_page::m_extent_size, max, ndbout(), page, and print_data_page().
Referenced by print_zero_page().
00185 { 00186 if(count == g_df_zero.m_extent_pages) 00187 { 00188 g_print_page = print_data_page; 00189 } 00190 Uint32 header_words = 00191 File_formats::Datafile::extent_header_words(g_df_zero.m_extent_size); 00192 Uint32 per_page = File_formats::Datafile::EXTENT_PAGE_WORDS / header_words; 00193 00194 int no = count * per_page; 00195 00196 const int max = count < g_df_zero.m_extent_pages ? 00197 per_page : g_df_zero.m_extent_count % per_page; 00198 00199 File_formats::Datafile::Extent_page * page = 00200 (File_formats::Datafile::Extent_page*)ptr; 00201 00202 ndbout << "Extent page: " << count 00203 << ", lsn = [ " 00204 << page->m_page_header.m_page_lsn_hi << " " 00205 << page->m_page_header.m_page_lsn_lo << "]" 00206 << endl; 00207 for(int i = 0; i<max; i++) 00208 { 00209 ndbout << " extent " << no+i << ": " 00210 << (* page->get_header(i, g_df_zero.m_extent_size)) << endl; 00211 } 00212 return 0; 00213 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static bool print_page | ( | int | page_no | ) | [static] |
Definition at line 30 of file print_file.cpp.
Referenced by print_data_page().
Here is the caller graph for this function:

| int print_undo_page | ( | int | , | |
| void * | , | |||
| Uint32 | sz | |||
| ) | [static] |
Definition at line 253 of file print_file.cpp.
References assert, g_uf_zero, g_verbosity, Dbtup::Disk_undo::Free::m_file_no_page_idx, Dbtup::Disk_undo::Update::m_file_no_page_idx, Dbtup::Disk_undo::Alloc::m_file_no_page_idx, Dbtup::Disk_undo::Free::m_gci, Dbtup::Disk_undo::Update::m_gci, Dbtup::Disk_undo::Free::m_page_no, Dbtup::Disk_undo::Update::m_page_no, Dbtup::Disk_undo::Alloc::m_page_no, File_formats::Undofile::Zero_page::m_undo_pages, ndbout(), ndbout_c(), page, pos(), File_formats::Undofile::UNDO_LCP, File_formats::Undofile::UNDO_LCP_FIRST, File_formats::Undofile::UNDO_NEXT_LSN, File_formats::Undofile::UNDO_TUP_ALLOC, File_formats::Undofile::UNDO_TUP_FREE, and File_formats::Undofile::UNDO_TUP_UPDATE.
Referenced by print_zero_page().
00253 { 00254 if(count > g_uf_zero.m_undo_pages + 1) 00255 { 00256 ndbout_c(" ERROR to many pages in file!!"); 00257 return 1; 00258 } 00259 00260 File_formats::Undofile::Undo_page * page = 00261 (File_formats::Undofile::Undo_page*)ptr; 00262 00263 if(page->m_page_header.m_page_lsn_hi != 0 || 00264 page->m_page_header.m_page_lsn_lo != 0) 00265 { 00266 ndbout << "Undo page: " << count 00267 << ", lsn = [ " 00268 << page->m_page_header.m_page_lsn_hi << " " 00269 << page->m_page_header.m_page_lsn_lo << "] " 00270 << "words used: " << page->m_words_used << endl; 00271 00272 Uint64 lsn= 0; 00273 lsn += page->m_page_header.m_page_lsn_hi; 00274 lsn <<= 32; 00275 lsn += page->m_page_header.m_page_lsn_lo; 00276 lsn++; 00277 00278 if(g_verbosity >= 3) 00279 { 00280 Uint32 pos= page->m_words_used - 1; 00281 while(pos + 1 != 0) 00282 { 00283 Uint32 len= page->m_data[pos] & 0xFFFF; 00284 Uint32 type= page->m_data[pos] >> 16; 00285 const Uint32* src= page->m_data + pos - len + 1; 00286 Uint32 next_pos= pos - len; 00287 if(type & File_formats::Undofile::UNDO_NEXT_LSN) 00288 { 00289 type &= ~(Uint32)File_formats::Undofile::UNDO_NEXT_LSN; 00290 lsn--; 00291 } 00292 else 00293 { 00294 lsn = 0; 00295 lsn += * (src - 2); 00296 lsn <<= 32; 00297 lsn += * (src - 1); 00298 next_pos -= 2; 00299 } 00300 if(g_verbosity > 3) 00301 printf(" %.4d - %.4d : ", pos - len + 1, pos); 00302 switch(type){ 00303 case File_formats::Undofile::UNDO_LCP_FIRST: 00304 case File_formats::Undofile::UNDO_LCP: 00305 printf("[ %lld LCP %d tab: %d frag: %d ]", lsn, 00306 src[0], src[1] >> 16, src[1] & 0xFFFF); 00307 break; 00308 case File_formats::Undofile::UNDO_TUP_ALLOC: 00309 if(g_verbosity > 3) 00310 { 00311 Dbtup::Disk_undo::Alloc *req= (Dbtup::Disk_undo::Alloc*)src; 00312 printf("[ %lld A %d %d %d ]", 00313 lsn, 00314 req->m_file_no_page_idx >> 16, 00315 req->m_file_no_page_idx & 0xFFFF, 00316 req->m_page_no); 00317 } 00318 break; 00319 case File_formats::Undofile::UNDO_TUP_UPDATE: 00320 if(g_verbosity > 3) 00321 { 00322 Dbtup::Disk_undo::Update *req= (Dbtup::Disk_undo::Update*)src; 00323 printf("[ %lld U %d %d %d gci: %d ]", 00324 lsn, 00325 req->m_file_no_page_idx >> 16, 00326 req->m_file_no_page_idx & 0xFFFF, 00327 req->m_page_no, 00328 req->m_gci); 00329 } 00330 break; 00331 case File_formats::Undofile::UNDO_TUP_FREE: 00332 if(g_verbosity > 3) 00333 { 00334 Dbtup::Disk_undo::Free *req= (Dbtup::Disk_undo::Free*)src; 00335 printf("[ %lld F %d %d %d gci: %d ]", 00336 lsn, 00337 req->m_file_no_page_idx >> 16, 00338 req->m_file_no_page_idx & 0xFFFF, 00339 req->m_page_no, 00340 req->m_gci); 00341 } 00342 break; 00343 default: 00344 ndbout_c("[ Unknown type %d len: %d, pos: %d ]", type, len, pos); 00345 if(!(len && type)) 00346 { 00347 pos= 0; 00348 while(pos < page->m_words_used) 00349 { 00350 printf("%.8x ", page->m_data[pos]); 00351 if((pos + 1) % 7 == 0) 00352 ndbout_c(""); 00353 pos++; 00354 } 00355 } 00356 assert(len && type); 00357 } 00358 pos = next_pos; 00359 if(g_verbosity > 3) 00360 printf("\n"); 00361 } 00362 } 00363 } 00364 00365 if(count == g_uf_zero.m_undo_pages + 1) 00366 { 00367 } 00368 00369 return 0; 00370 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void print_usage | ( | const char * | ) | [static] |
Definition at line 101 of file print_file.cpp.
References ndbout().
Referenced by main().
00102 { 00103 ndbout << prg << " [-v]+ [-q]+ <file>+" << endl; 00104 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int print_zero_page | ( | int | , | |
| void * | , | |||
| Uint32 | sz | |||
| ) | [static] |
Definition at line 107 of file print_file.cpp.
References File_formats::FT_Datafile, File_formats::FT_Undofile, g_df_zero, g_page_size, g_print_page, g_uf_zero, memcmp(), ndbout(), page, print_extent_page(), and print_undo_page().
00107 { 00108 File_formats::Zero_page_header* page = (File_formats::Zero_page_header*)ptr; 00109 if(memcmp(page->m_magic, "NDBDISK", 8) != 0) 00110 { 00111 ndbout << "Invalid magic: file is not ndb disk data file" << endl; 00112 return 1; 00113 } 00114 00115 if(page->m_byte_order != 0x12345678) 00116 { 00117 ndbout << "Unhandled byteorder" << endl; 00118 return 1; 00119 } 00120 00121 switch(page->m_file_type) 00122 { 00123 case File_formats::FT_Datafile: 00124 { 00125 g_df_zero = (* (File_formats::Datafile::Zero_page*)ptr); 00126 ndbout << "-- Datafile -- " << endl; 00127 ndbout << g_df_zero << endl; 00128 g_print_page = print_extent_page; 00129 return 0; 00130 } 00131 break; 00132 case File_formats::FT_Undofile: 00133 { 00134 g_uf_zero = (* (File_formats::Undofile::Zero_page*)ptr); 00135 ndbout << "-- Undofile -- " << endl; 00136 ndbout << g_uf_zero << endl; 00137 g_print_page = print_undo_page; 00138 return 0; 00139 } 00140 break; 00141 default: 00142 ndbout << "Unhandled file type: " << page->m_file_type << endl; 00143 return 1; 00144 } 00145 00146 if(page->m_page_size !=g_page_size) 00147 { 00153 ndbout << "Unhandled page size: " << page->m_page_size << endl; 00154 return 1; 00155 } 00156 00157 return 0; 00158 }
Here is the call graph for this function:

Definition at line 40 of file print_file.cpp.
Referenced by operator<<(), print_extent_page(), and print_zero_page().
| int g_page_size = File_formats::NDB_PAGE_SIZE |
| int(* ) g_print_page(int count, void *, Uint32 sz) = print_zero_page |
Definition at line 37 of file print_file.cpp.
Referenced by main(), print_extent_page(), and print_zero_page().
Definition at line 39 of file print_file.cpp.
Referenced by print_undo_page(), and print_zero_page().
| int g_verbosity = 1 |
Definition at line 35 of file print_file.cpp.
Referenced by main(), print_data_page(), and print_undo_page().
1.4.7

