Commit 160199eb authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

put the log print functions in log_print.c refs[t:2193]

git-svn-id: file:///svn/toku/tokudb@16447 c7de825b-a66e-492c-adef-691d508d4ae1
parent 41f1d7ab
...@@ -54,6 +54,7 @@ BRT_SOURCES = \ ...@@ -54,6 +54,7 @@ BRT_SOURCES = \
logfilemgr \ logfilemgr \
logger \ logger \
log_code \ log_code \
log_print \
logcursor \ logcursor \
memarena \ memarena \
mempool \ mempool \
......
...@@ -187,7 +187,7 @@ static void __attribute__((format (printf, 3, 4))) fprintf2 (FILE *f1, FILE *f2, ...@@ -187,7 +187,7 @@ static void __attribute__((format (printf, 3, 4))) fprintf2 (FILE *f1, FILE *f2,
va_end(ap); va_end(ap);
} }
FILE *hf=0, *cf=0; FILE *hf=0, *cf=0, *pf=0;
static void static void
generate_enum_internal (char *enum_name, char *enum_prefix, const struct logtype *lts) { generate_enum_internal (char *enum_name, char *enum_prefix, const struct logtype *lts) {
...@@ -446,54 +446,54 @@ generate_log_reader (void) { ...@@ -446,54 +446,54 @@ generate_log_reader (void) {
static void static void
generate_logprint (void) { generate_logprint (void) {
unsigned maxnamelen=0; unsigned maxnamelen=0;
fprintf2(cf, hf, "int toku_logprint_one_record(FILE *outf, FILE *f)"); fprintf2(pf, hf, "int toku_logprint_one_record(FILE *outf, FILE *f)");
fprintf(hf, ";\n"); fprintf(hf, ";\n");
fprintf(cf, " {\n"); fprintf(pf, " {\n");
fprintf(cf, " int cmd, r;\n"); fprintf(pf, " int cmd, r;\n");
fprintf(cf, " u_int32_t len1, crc_in_file;\n"); fprintf(pf, " u_int32_t len1, crc_in_file;\n");
fprintf(cf, " u_int32_t ignorelen=0;\n"); fprintf(pf, " u_int32_t ignorelen=0;\n");
fprintf(cf, " struct x1764 checksum;\n"); fprintf(pf, " struct x1764 checksum;\n");
fprintf(cf, " x1764_init(&checksum);\n"); fprintf(pf, " x1764_init(&checksum);\n");
fprintf(cf, " r=toku_fread_u_int32_t(f, &len1, &checksum, &ignorelen);\n"); fprintf(pf, " r=toku_fread_u_int32_t(f, &len1, &checksum, &ignorelen);\n");
fprintf(cf, " if (r==EOF) return EOF;\n"); fprintf(pf, " if (r==EOF) return EOF;\n");
fprintf(cf, " cmd=fgetc(f);\n"); fprintf(pf, " cmd=fgetc(f);\n");
fprintf(cf, " if (cmd==EOF) return DB_BADFORMAT;\n"); fprintf(pf, " if (cmd==EOF) return DB_BADFORMAT;\n");
fprintf(cf, " u_int32_t len_in_file, len=1+4; // cmd + len1\n"); fprintf(pf, " u_int32_t len_in_file, len=1+4; // cmd + len1\n");
fprintf(cf, " char charcmd = (char)cmd;\n"); fprintf(pf, " char charcmd = (char)cmd;\n");
fprintf(cf, " x1764_add(&checksum, &charcmd, 1);\n"); fprintf(pf, " x1764_add(&checksum, &charcmd, 1);\n");
fprintf(cf, " switch ((enum lt_cmd)cmd) {\n"); fprintf(pf, " switch ((enum lt_cmd)cmd) {\n");
DO_LOGTYPES(lt, { if (strlen(lt->name)>maxnamelen) maxnamelen=strlen(lt->name); }); DO_LOGTYPES(lt, { if (strlen(lt->name)>maxnamelen) maxnamelen=strlen(lt->name); });
DO_LOGTYPES(lt, { DO_LOGTYPES(lt, {
unsigned char cmd = (unsigned char)(0xff&lt->command_and_flags); unsigned char cmd = (unsigned char)(0xff&lt->command_and_flags);
fprintf(cf, " case LT_%s: \n", lt->name); fprintf(pf, " case LT_%s: \n", lt->name);
// We aren't using the log reader here because we want better diagnostics as soon as things go wrong. // We aren't using the log reader here because we want better diagnostics as soon as things go wrong.
fprintf(cf, " fprintf(outf, \"%%-%us \", \"%s\");\n", maxnamelen, lt->name); fprintf(pf, " fprintf(outf, \"%%-%us \", \"%s\");\n", maxnamelen, lt->name);
if (isprint(cmd)) fprintf(cf," fprintf(outf, \" '%c':\");\n", cmd); if (isprint(cmd)) fprintf(pf," fprintf(outf, \" '%c':\");\n", cmd);
else fprintf(cf," fprintf(outf, \"0%03o:\");\n", cmd); else fprintf(pf," fprintf(outf, \"0%03o:\");\n", cmd);
fprintf(cf, " r = toku_logprint_%-16s(outf, f, \"lsn\", &checksum, &len, 0); if (r!=0) return r;\n", "LSN"); fprintf(pf, " r = toku_logprint_%-16s(outf, f, \"lsn\", &checksum, &len, 0); if (r!=0) return r;\n", "LSN");
DO_FIELDS(ft, lt, { DO_FIELDS(ft, lt, {
fprintf(cf, " r = toku_logprint_%-16s(outf, f, \"%s\", &checksum, &len,", ft->type, ft->name); fprintf(pf, " r = toku_logprint_%-16s(outf, f, \"%s\", &checksum, &len,", ft->type, ft->name);
if (ft->format) fprintf(cf, "\"%s\"", ft->format); if (ft->format) fprintf(pf, "\"%s\"", ft->format);
else fprintf(cf, "0"); else fprintf(pf, "0");
fprintf(cf, "); if (r!=0) return r;\n"); fprintf(pf, "); if (r!=0) return r;\n");
}); });
fprintf(cf, " {\n"); fprintf(pf, " {\n");
fprintf(cf, " u_int32_t actual_murmur = x1764_finish(&checksum);\n"); fprintf(pf, " u_int32_t actual_murmur = x1764_finish(&checksum);\n");
fprintf(cf, " r = toku_fread_u_int32_t_nocrclen (f, &crc_in_file); len+=4; if (r!=0) return r;\n"); fprintf(pf, " r = toku_fread_u_int32_t_nocrclen (f, &crc_in_file); len+=4; if (r!=0) return r;\n");
fprintf(cf, " fprintf(outf, \" crc=%%08x\", crc_in_file);\n"); fprintf(pf, " fprintf(outf, \" crc=%%08x\", crc_in_file);\n");
fprintf(cf, " if (crc_in_file!=actual_murmur) fprintf(outf, \" actual_fingerprint=%%08x\", actual_murmur);\n"); fprintf(pf, " if (crc_in_file!=actual_murmur) fprintf(outf, \" actual_fingerprint=%%08x\", actual_murmur);\n");
fprintf(cf, " r = toku_fread_u_int32_t_nocrclen (f, &len_in_file); len+=4; if (r!=0) return r;\n"); fprintf(pf, " r = toku_fread_u_int32_t_nocrclen (f, &len_in_file); len+=4; if (r!=0) return r;\n");
fprintf(cf, " fprintf(outf, \" len=%%u\", len_in_file);\n"); fprintf(pf, " fprintf(outf, \" len=%%u\", len_in_file);\n");
fprintf(cf, " if (len_in_file!=len) fprintf(outf, \" actual_len=%%u\", len);\n"); fprintf(pf, " if (len_in_file!=len) fprintf(outf, \" actual_len=%%u\", len);\n");
fprintf(cf, " if (len_in_file!=len || crc_in_file!=actual_murmur) return DB_BADFORMAT;\n"); fprintf(pf, " if (len_in_file!=len || crc_in_file!=actual_murmur) return DB_BADFORMAT;\n");
fprintf(cf, " };\n"); fprintf(pf, " };\n");
fprintf(cf, " fprintf(outf, \"\\n\");\n"); fprintf(pf, " fprintf(outf, \"\\n\");\n");
fprintf(cf, " return 0;;\n\n"); fprintf(pf, " return 0;;\n\n");
}); });
fprintf(cf, " }\n"); fprintf(pf, " }\n");
fprintf(cf, " fprintf(outf, \"Unknown command %%d ('%%c')\", cmd, cmd);\n"); fprintf(pf, " fprintf(outf, \"Unknown command %%d ('%%c')\", cmd, cmd);\n");
fprintf(cf, " return DB_BADFORMAT;\n"); fprintf(pf, " return DB_BADFORMAT;\n");
fprintf(cf, "}\n\n"); fprintf(pf, "}\n\n");
} }
static void static void
...@@ -592,6 +592,7 @@ generate_log_entry_functions(void) { ...@@ -592,6 +592,7 @@ generate_log_entry_functions(void) {
} }
const char *codepath = "log_code.c"; const char *codepath = "log_code.c";
const char *printpath = "log_print.c";
const char *headerpath = "log_header.h"; const char *headerpath = "log_header.h";
int main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__unused__))) { int main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__unused__))) {
chmod(codepath, S_IRUSR|S_IWUSR); chmod(codepath, S_IRUSR|S_IWUSR);
...@@ -602,11 +603,12 @@ int main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__u ...@@ -602,11 +603,12 @@ int main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__u
if (cf==0) { int r = errno; printf("fopen of %s failed because of errno=%d (%s)\n", codepath, r, strerror(r)); } // sometimes this is failing, so let's make a better diagnostic if (cf==0) { int r = errno; printf("fopen of %s failed because of errno=%d (%s)\n", codepath, r, strerror(r)); } // sometimes this is failing, so let's make a better diagnostic
assert(cf!=0); assert(cf!=0);
hf = fopen(headerpath, "w"); assert(hf!=0); hf = fopen(headerpath, "w"); assert(hf!=0);
pf = fopen(printpath, "w"); assert(pf!=0);
fprintf(hf, "#ifndef LOG_HEADER_H\n"); fprintf(hf, "#ifndef LOG_HEADER_H\n");
fprintf(hf, "#define LOG_HEADER_H\n"); fprintf(hf, "#define LOG_HEADER_H\n");
fprintf2(cf, hf, "/* Do not edit this file. This code generated by logformat.c. Copyright 2007, 2008 Tokutek. */\n"); fprintf2(cf, hf, "/* Do not edit this file. This code generated by logformat.c. Copyright 2007, 2008 Tokutek. */\n");
fprintf2(cf, hf, "#ident \"Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved.\"\n"); fprintf2(cf, hf, "#ident \"Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved.\"\n");
fprintf(cf, "#include \"includes.h\"\n"); fprintf2(cf, pf, "#include \"includes.h\"\n");
fprintf(hf, "#include \"brt-internal.h\"\n"); fprintf(hf, "#include \"brt-internal.h\"\n");
fprintf(hf, "#include \"memarena.h\"\n"); fprintf(hf, "#include \"memarena.h\"\n");
generate_enum(); generate_enum();
...@@ -614,15 +616,14 @@ int main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__u ...@@ -614,15 +616,14 @@ int main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__u
generate_dispatch(); generate_dispatch();
generate_log_writer(); generate_log_writer();
generate_log_reader(); generate_log_reader();
generate_logprint();
generate_rollbacks(); generate_rollbacks();
generate_log_entry_functions(); generate_log_entry_functions();
generate_logprint();
fprintf(hf, "#endif\n"); fprintf(hf, "#endif\n");
{ {
int r=fclose(hf); int r=fclose(hf); assert(r==0);
assert(r==0); r=fclose(cf); assert(r==0);
r=fclose(cf); r=fclose(pf); assert(r==0);
assert(r==0);
// Make it tougher to modify by mistake // Make it tougher to modify by mistake
chmod(codepath, S_IRUSR|S_IRGRP|S_IROTH); chmod(codepath, S_IRUSR|S_IRGRP|S_IROTH);
chmod(headerpath, S_IRUSR|S_IRGRP|S_IROTH); chmod(headerpath, S_IRUSR|S_IRGRP|S_IROTH);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment