Commit 89737476 authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

#3168 print decompression block information including the raw block to stderr refs[t:3168]

git-svn-id: file:///svn/toku/tokudb@27079 c7de825b-a66e-492c-adef-691d508d4ae1
parent dc90c838
......@@ -904,6 +904,32 @@ deserialize_brtnode_from_rbuf (BLOCKNUM blocknum, u_int32_t fullhash, BRTNODE *b
return 0;
}
// dump a buffer to stderr
// no locking around this for now
static void
dump_bad_block(unsigned char *vp, u_int64_t size) {
const u_int64_t linesize = 64;
u_int64_t n = size / linesize;
for (u_int64_t i = 0; i < n; i++) {
fprintf(stderr, "%p: ", vp);
for (u_int64_t j = 0; j < linesize; j++) {
unsigned char c = vp[j];
fprintf(stderr, "%2.2X", c);
}
fprintf(stderr, "\n");
vp += linesize;
}
size = size % linesize;
for (u_int64_t i=0; i<size; i++) {
if ((i % linesize) == 0)
fprintf(stderr, "%p: ", vp+i);
fprintf(stderr, "%2.2X", vp[i]);
if (((i+1) % linesize) == 0)
fprintf(stderr, "\n");
}
fprintf(stderr, "\n");
}
static int
decompress_from_raw_block_into_rbuf(u_int8_t *raw_block, size_t raw_block_size, struct rbuf *rb, BLOCKNUM blocknum) {
toku_trace("decompress");
......@@ -964,6 +990,10 @@ decompress_from_raw_block_into_rbuf(u_int8_t *raw_block, size_t raw_block_size,
// decompress all the compressed sub blocks into the uncompressed buffer
r = decompress_all_sub_blocks(n_sub_blocks, sub_block, compressed_data, uncompressed_data, num_cores, brt_pool);
if (r != 0) {
fprintf(stderr, "%s:%d block %"PRId64" failed %d at %p size %lu\n", __FUNCTION__, __LINE__, blocknum.b, r, raw_block, raw_block_size);
dump_bad_block(raw_block, raw_block_size);
}
lazy_assert_zero(r);
toku_trace("decompress done");
......
......@@ -333,6 +333,11 @@ dump_file(int f, u_int64_t offset, u_int64_t size, FILE *outfp) {
toku_free(vp);
}
static void
set_file(int f, u_int64_t offset, unsigned char newc) {
toku_os_pwrite(f, &newc, sizeof newc, offset);
}
static void
readline (char *line, int maxline) {
int i = 0;
......@@ -412,7 +417,7 @@ main (int argc, const char *const argv[]) {
if (argc != 1) return usage(arg0);
const char *n = argv[0];
int f = open(n, O_RDONLY + O_BINARY); assert(f>=0);
int f = open(n, O_RDWR + O_BINARY); assert(f>=0);
struct brt_header *h;
// create a cachefile for the header
int r = toku_create_cachetable(&ct, 1<<25, (LSN){0}, 0);
......@@ -462,6 +467,10 @@ main (int argc, const char *const argv[]) {
if (nfields >= 4)
outfp = fopen(fields[3], "w");
dump_file(f, offset, size, outfp);
} else if (strcmp(fields[0], "setfile") == 0 && nfields == 3) {
u_int64_t offset = getuint64(fields[1]);
unsigned char newc = getuint64(fields[2]);
set_file(f, offset, newc);
} else if (strcmp(fields[0], "quit") == 0 || strcmp(fields[0], "q") == 0) {
break;
}
......
......@@ -221,21 +221,30 @@ decompress_work_init(struct decompress_work *dw,
dw->error = 0;
}
int verbose_decompress_sub_block = 1;
// decompress one block
int
decompress_sub_block(void *compress_ptr, u_int32_t compress_size, void *uncompress_ptr, u_int32_t uncompress_size, u_int32_t expected_xsum) {
int result = 0;
// verify checksum
u_int32_t xsum = x1764_memory(compress_ptr, compress_size);
if (xsum != expected_xsum)
return EINVAL;
if (xsum != expected_xsum) {
if (verbose_decompress_sub_block) fprintf(stderr, "%s:%d xsum %u expected %u\n", __FUNCTION__, __LINE__, xsum, expected_xsum);
result = EINVAL;
} else {
// decompress
uLongf destlen = uncompress_size;
int r = uncompress(uncompress_ptr, &destlen, compress_ptr, compress_size);
if (r != Z_OK || destlen != uncompress_size)
return EINVAL;
// decompress
uLongf destlen = uncompress_size;
int r = uncompress(uncompress_ptr, &destlen, compress_ptr, compress_size);
if (r != Z_OK || destlen != uncompress_size) {
if (verbose_decompress_sub_block) fprintf(stderr, "%s:%d uncompress %d %lu %u\n", __FUNCTION__, __LINE__, r, destlen, uncompress_size);
result = EINVAL;
}
}
return 0;
return result;
}
// decompress blocks until there is no more work to do
......
......@@ -106,6 +106,8 @@ decompress_worker(void *arg);
int
decompress_all_sub_blocks(int n_sub_blocks, struct sub_block sub_block[], unsigned char *compressed_data, unsigned char *uncompressed_data, int num_cores, struct toku_thread_pool *pool);
extern int verbose_decompress_sub_block;
#if defined(__cplusplus) || defined(__cilkplusplus)
}
#endif
......
......@@ -113,6 +113,11 @@ test_main (int argc, const char *argv[]) {
const char *arg = argv[i];
if (strcmp(arg, "-v") == 0 || strcmp(arg, "--verbose") == 0) {
verbose++;
verbose_decompress_sub_block = 1;
continue;
}
if (strcmp(arg, "-q") == 0) {
verbose_decompress_sub_block = 0;
continue;
}
if (strcmp(arg, "-n") == 0) {
......
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