2013-04-17 00:00:36 -04:00
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
2013-04-16 23:57:48 -04:00
# ident "$Id$"
2013-04-16 23:59:09 -04:00
# ident "Copyright (c) 2007-2010 Tokutek Inc. All rights reserved."
2013-04-16 23:57:48 -04:00
# ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11 / 760379 and to the patents and / or patent applications resulting from it."
2007-11-29 14:18:54 +00:00
2007-09-28 17:11:22 +00:00
/* Dump the log from stdin to stdout. */
2013-04-16 23:57:20 -04:00
# include "includes.h"
2007-11-29 15:17:46 +00:00
#if 0
static u_int32_t crc = 0 ;
static u_int32_t actual_len = 0 ;
2007-11-14 22:32:53 +00:00
2007-11-29 15:17:46 +00:00
static int get_char ( void ) {
2007-11-14 22:32:53 +00:00
int v = getchar ( ) ;
2007-11-14 22:50:15 +00:00
if ( v = = EOF ) return v ;
2007-11-14 22:32:53 +00:00
unsigned char c = v ;
2007-11-22 20:35:21 +00:00
crc = toku_crc32 ( crc , & c , 1 ) ;
2007-11-14 22:32:53 +00:00
actual_len + + ;
2007-11-14 22:50:15 +00:00
return v ;
2007-11-14 22:32:53 +00:00
}
2007-11-29 15:17:46 +00:00
static u_int32_t get_uint32 ( void ) {
2007-11-14 22:32:53 +00:00
u_int32_t a = get_char ( ) ;
u_int32_t b = get_char ( ) ;
u_int32_t c = get_char ( ) ;
u_int32_t d = get_char ( ) ;
2007-09-28 17:11:22 +00:00
return ( a < < 24 ) | ( b < < 16 ) | ( c < < 8 ) | d ;
}
2007-11-29 15:17:46 +00:00
static u_int64_t get_uint64 ( void ) {
2007-09-28 17:11:22 +00:00
u_int32_t hi = get_uint32 ( ) ;
u_int32_t lo = get_uint32 ( ) ;
return ( ( ( ( long long ) hi ) < < 32 )
|
lo ) ;
}
2007-11-29 15:17:46 +00:00
static void transcribe_lsn ( void ) {
2007-11-14 22:32:53 +00:00
long long value = get_uint64 ( ) ;
printf ( " lsn=%lld " , value ) ;
}
2007-11-29 15:17:46 +00:00
static void transcribe_txnid ( void ) {
2007-09-28 17:11:22 +00:00
long long value = get_uint64 ( ) ;
printf ( " txnid=%lld " , value ) ;
}
2007-11-29 15:17:46 +00:00
static void transcribe_fileid ( void ) {
2007-11-14 22:32:53 +00:00
u_int32_t value = get_uint32 ( ) ;
printf ( " fileid=%d " , value ) ;
2013-04-16 23:57:41 -04:00
}
2007-11-14 22:32:53 +00:00
2007-11-29 15:17:46 +00:00
static void transcribe_diskoff ( void ) {
2007-09-28 17:11:22 +00:00
long long value = get_uint64 ( ) ;
printf ( " diskoff=%lld " , value ) ;
2013-04-16 23:57:41 -04:00
}
2007-09-28 17:11:22 +00:00
2007-11-29 15:17:46 +00:00
static void transcribe_crc32 ( void ) {
2007-11-14 22:32:53 +00:00
u_int32_t oldcrc = crc ;
u_int32_t l = get_uint32 ( ) ;
printf ( " crc=%08x " , l ) ;
assert ( l = = oldcrc ) ;
}
2007-11-29 15:17:46 +00:00
static void transcribe_mode ( void ) {
2007-11-20 13:58:47 +00:00
u_int32_t value = get_uint32 ( ) ;
printf ( " mode=0%o " , value ) ;
}
2007-11-29 15:17:46 +00:00
static void transcribe_filenum ( void ) {
2007-11-20 21:20:05 +00:00
u_int32_t value = get_uint32 ( ) ;
printf ( " filenum=%d " , value ) ;
}
2007-11-29 15:17:46 +00:00
static u_int32_t len1 ;
static void transcribe_len1 ( void ) {
2007-11-24 23:21:02 +00:00
len1 = get_uint32 ( ) ;
//printf(" len=%d", len1);
}
2007-11-29 15:17:46 +00:00
static void transcribe_len ( void ) {
2007-11-14 22:32:53 +00:00
u_int32_t l = get_uint32 ( ) ;
printf ( " len=%d " , l ) ;
if ( l ! = actual_len ) printf ( " actual_len=%d " , actual_len ) ;
assert ( l = = actual_len ) ;
2007-11-24 23:21:02 +00:00
assert ( len1 = = actual_len ) ;
2007-11-14 22:32:53 +00:00
}
2007-11-29 15:17:46 +00:00
static void transcribe_key_or_data ( char * what ) {
2007-09-28 17:11:22 +00:00
u_int32_t l = get_uint32 ( ) ;
unsigned int i ;
printf ( " %s(%d): \" " , what , l ) ;
for ( i = 0 ; i < l ; i + + ) {
2007-11-14 22:32:53 +00:00
u_int32_t c = get_char ( ) ;
2007-09-28 17:11:22 +00:00
if ( c = = ' \\ ' ) printf ( " \\ \\ " ) ;
else if ( c = = ' \n ' ) printf ( " \\ n " ) ;
else if ( c = = ' ' ) printf ( " \\ " ) ;
else if ( c = = ' " ' ) printf ( " \" \" " ) ;
else if ( isprint ( c ) ) printf ( " %c " , c ) ;
else printf ( " \\ %02x " , c ) ;
}
printf ( " \" " ) ;
}
2007-11-29 15:17:46 +00:00
static void transcribe_header ( void ) {
2007-11-21 18:46:43 +00:00
printf ( " {size=%d " , get_uint32 ( ) ) ;
printf ( " flags=%d " , get_uint32 ( ) ) ;
printf ( " nodesize=%d " , get_uint32 ( ) ) ;
2007-11-26 18:47:44 +00:00
printf ( " freelist=% " PRId64 , get_uint64 ( ) ) ;
printf ( " unused_memory=% " PRId64 , get_uint64 ( ) ) ;
2007-11-21 18:46:43 +00:00
int n_roots = get_uint32 ( ) ;
printf ( " n_named_roots=%d " , n_roots ) ;
if ( n_roots > 0 ) {
abort ( ) ;
} else {
2007-11-26 18:47:44 +00:00
printf ( " root=% " PRId64 , get_uint64 ( ) ) ;
2007-11-21 18:46:43 +00:00
}
printf ( " } " ) ;
}
2007-11-29 15:17:46 +00:00
# endif
2007-09-28 17:11:22 +00:00
2007-11-23 17:16:26 +00:00
static void newmain ( int count ) {
2007-11-22 20:35:21 +00:00
int i ;
2007-11-23 18:27:50 +00:00
u_int32_t version ;
2007-11-28 19:09:24 +00:00
int r = toku_read_and_print_logmagic ( stdin , & version ) ;
2007-11-22 20:35:21 +00:00
for ( i = 0 ; i ! = count ; i + + ) {
2007-11-23 18:27:50 +00:00
r = toku_logprint_one_record ( stdout , stdin ) ;
2007-11-23 17:16:26 +00:00
if ( r = = EOF ) break ;
2007-11-22 20:35:21 +00:00
if ( r ! = 0 ) {
fflush ( stdout ) ;
fprintf ( stderr , " Problem in log err=%d \n " , r ) ;
exit ( 1 ) ;
}
}
}
2013-04-16 23:59:01 -04:00
int main ( int argc , char * const argv [ ] ) {
2007-11-23 17:16:26 +00:00
int count = - 1 ;
while ( argc > 1 ) {
if ( strcmp ( argv [ 1 ] , " --oldcode " ) = = 0 ) {
2007-11-27 10:48:31 +00:00
fprintf ( stderr , " Old code no longer works. \n " ) ;
exit ( 1 ) ;
2007-11-23 17:16:26 +00:00
} else {
count = atoi ( argv [ 1 ] ) ;
}
argc - - ; argv + + ;
}
2007-11-27 10:48:31 +00:00
newmain ( count ) ;
2007-09-28 17:11:22 +00:00
return 0 ;
}
2007-11-23 17:16:26 +00:00