18 #include <ndb_global.h>
21 #include <UtilBuffer.hpp>
22 #include "diskpage.hpp"
23 #include <ndb_limits.h>
24 #include <dbtup/tuppage.hpp>
26 static void print_usage(
const char*);
27 static int print_zero_page(
int,
void *, Uint32 sz);
28 static int print_extent_page(
int,
void*, Uint32 sz);
29 static int print_undo_page(
int,
void*, Uint32 sz);
30 static int print_data_page(
int,
void*, Uint32 sz);
31 static bool print_page(
int page_no)
37 unsigned g_page_size = File_formats::NDB_PAGE_SIZE;
38 int (* g_print_page)(
int count,
void*, Uint32 sz) = print_zero_page;
43 int main(
int argc,
char ** argv)
45 for(
int i = 1;
i<argc;
i++){
46 if(!strncmp(argv[
i],
"-v", 2))
51 }
while(argv[i][pos++] ==
'v');
54 else if(!strcmp(argv[i],
"-q"))
59 else if(!strcmp(argv[i],
"-?") ||
60 !strcmp(argv[i],
"--?") ||
61 !strcmp(argv[i],
"-h") ||
62 !strcmp(argv[i],
"--help"))
68 const char * filename = argv[
i];
71 if(stat(filename, &sbuf) != 0)
73 ndbout <<
"Could not find file: \"" << filename <<
"\"" << endl;
80 FILE * f = fopen(filename,
"rb");
82 ndbout <<
"Failed to open file" << endl;
89 buffer.grow(g_page_size);
90 sz = (Uint32)fread(buffer.get_data(), 1, g_page_size, f);
91 if((* g_print_page)(j++, buffer.get_data(), sz))
93 }
while(sz == g_page_size);
102 print_usage(
const char* prg)
104 ndbout << prg <<
" [-v]+ [-q]+ <file>+" << endl;
108 print_zero_page(
int i,
void * ptr, Uint32 sz){
110 if(memcmp(page->m_magic,
"NDBDISK", 8) != 0)
112 ndbout <<
"Invalid magic: file is not ndb disk data file" << endl;
116 if(page->m_byte_order != 0x12345678)
118 ndbout <<
"Unhandled byteorder" << endl;
122 switch(page->m_file_type)
124 case File_formats::FT_Datafile:
127 ndbout <<
"-- Datafile -- " << endl;
128 ndbout << g_df_zero << endl;
129 g_print_page = print_extent_page;
133 case File_formats::FT_Undofile:
136 ndbout <<
"-- Undofile -- " << endl;
137 ndbout << g_uf_zero << endl;
138 g_print_page = print_undo_page;
143 ndbout <<
"Unhandled file type: " << page->m_file_type << endl;
147 if(page->m_page_size !=g_page_size)
154 ndbout <<
"Unhandled page size: " << page->m_page_size << endl;
164 if(obj.m_table == RNIL)
166 if(obj.m_next_free_extent != RNIL)
167 out <<
" FREE, next free: " << obj.m_next_free_extent;
169 out <<
" FREE, next free: RNIL";
173 out <<
"table: " << obj.m_table
174 <<
" fragment: " << obj.m_fragment_id <<
" ";
175 for(Uint32 i = 0; i<g_df_zero.m_extent_size; i++)
186 print_extent_page(
int count,
void* ptr, Uint32 sz){
187 if((
unsigned)count == g_df_zero.m_extent_pages)
189 g_print_page = print_data_page;
191 Uint32 header_words =
193 Uint32 per_page = File_formats::Datafile::EXTENT_PAGE_WORDS / header_words;
195 int no = count * per_page;
197 const int max = count < int(g_df_zero.m_extent_pages) ?
198 per_page : g_df_zero.m_extent_count - (g_df_zero.m_extent_count - 1) * per_page;
203 ndbout <<
"Extent page: " << count
205 << page->m_page_header.m_page_lsn_hi <<
" "
206 << page->m_page_header.m_page_lsn_lo <<
"] "
208 for(
int i = 0; i<max; i++)
210 ndbout <<
" extent " << no+i <<
": "
211 << (* page->get_header(i, g_df_zero.m_extent_size)) << endl;
217 print_data_page(
int count,
void* ptr, Uint32 sz){
222 ndbout <<
"Data page: " << count
224 << page->m_page_header.m_page_lsn_hi <<
" "
225 << page->m_page_header.m_page_lsn_lo <<
"]" ;
227 if(g_verbosity > 1 || print_page(count))
229 switch(page->m_page_header.m_page_type){
230 case File_formats::PT_Unallocated:
232 case File_formats::PT_Tup_fixsize_page:
234 if(g_verbosity > 2 || print_page(count))
237 case File_formats::PT_Tup_varsize_page:
239 if(g_verbosity > 2 || print_page(count))
243 ndbout <<
" unknown page type: %d" << page->m_page_header.m_page_type;
251 #include "dbtup/Dbtup.hpp"
254 print_undo_page(
int count,
void* ptr, Uint32 sz){
255 if(count >
int(g_uf_zero.m_undo_pages + 1))
257 ndbout_c(
" ERROR to many pages in file!!");
264 if(page->m_page_header.m_page_lsn_hi != 0 ||
265 page->m_page_header.m_page_lsn_lo != 0)
267 ndbout <<
"Undo page: " << count
269 << page->m_page_header.m_page_lsn_hi <<
" "
270 << page->m_page_header.m_page_lsn_lo <<
"] "
271 <<
"words used: " << page->m_words_used << endl;
274 lsn += page->m_page_header.m_page_lsn_hi;
276 lsn += page->m_page_header.m_page_lsn_lo;
281 Uint32 pos= page->m_words_used - 1;
284 Uint32 len= page->m_data[pos] & 0xFFFF;
285 Uint32
type= page->m_data[pos] >> 16;
286 const Uint32* src= page->m_data + pos - len + 1;
287 Uint32 next_pos= pos - len;
288 if(type & File_formats::Undofile::UNDO_NEXT_LSN)
290 type &= ~(Uint32)File_formats::Undofile::UNDO_NEXT_LSN;
302 printf(
" %.4d - %.4d : ", pos - len + 1, pos);
304 case File_formats::Undofile::UNDO_LCP_FIRST:
305 case File_formats::Undofile::UNDO_LCP:
306 printf(
"[ %lld LCP %d tab: %d frag: %d ]", lsn,
307 src[0], src[1] >> 16, src[1] & 0xFFFF);
311 case File_formats::Undofile::UNDO_TUP_ALLOC:
315 printf(
"[ %lld A %d %d %d ]",
317 req->m_file_no_page_idx >> 16,
318 req->m_file_no_page_idx & 0xFFFF,
322 case File_formats::Undofile::UNDO_TUP_UPDATE:
326 printf(
"[ %lld U %d %d %d gci: %d ]",
328 req->m_file_no_page_idx >> 16,
329 req->m_file_no_page_idx & 0xFFFF,
334 case File_formats::Undofile::UNDO_TUP_FREE:
338 printf(
"[ %lld F %d %d %d gci: %d ]",
340 req->m_file_no_page_idx >> 16,
341 req->m_file_no_page_idx & 0xFFFF,
346 case File_formats::Undofile::UNDO_TUP_CREATE:
349 printf(
"[ %lld Create %d ]", lsn, req->m_table);
354 case File_formats::Undofile::UNDO_TUP_DROP:
357 printf(
"[ %lld Drop %d ]", lsn, req->m_table);
362 case File_formats::Undofile::UNDO_TUP_ALLOC_EXTENT:
365 printf(
"[ %lld AllocExtent tab: %d frag: %d file: %d page: %d ]",
375 case File_formats::Undofile::UNDO_TUP_FREE_EXTENT:
378 printf(
"[ %lld FreeExtent tab: %d frag: %d file: %d page: %d ]",
389 ndbout_c(
"[ Unknown type %d len: %d, pos: %d ]", type, len, pos);
393 while(pos < page->m_words_used)
395 printf(
"%.8x ", page->m_data[pos]);
396 if((pos + 1) % 7 == 0)
410 if((
unsigned)count == g_uf_zero.m_undo_pages + 1)