Commit 949b94c5 authored by marko's avatar marko

branches/zip: Enable excessive binary logging of page_zip_compress(),

for the purpose of comparing different compression algorithms.

PAGE_ZIP_COMPRESS_DBG: New preprocessor condition, to see if deflate()
is wrapped.

page_zip_compress_log: Log file counter.  If set to nonzero, logging
is enabled.

page_zip_compress_deflate(): Add the parameter logfile.

FILE_LOGFILE, LOGFILE: Macros for declaring and passing the parameter logfile.

page_zip_compress(): Open and close the logfile if needed.  Write the
uncompressed page and the size of the compressed data.  The data passed
to deflate() is written by the wrapper page_zip_compress_deflate().
parent 36a5b2cd
...@@ -658,10 +658,19 @@ page_zip_set_alloc( ...@@ -658,10 +658,19 @@ page_zip_set_alloc(
strm->opaque = heap; strm->opaque = heap;
} }
#if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG #if 0 || defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
# define PAGE_ZIP_COMPRESS_DBG
#endif
#ifdef PAGE_ZIP_COMPRESS_DBG
/* Set this variable in a debugger to enable /* Set this variable in a debugger to enable
excessive logging in page_zip_compress(). */ excessive logging in page_zip_compress(). */
UNIV_INTERN ibool page_zip_compress_dbg; UNIV_INTERN ibool page_zip_compress_dbg;
/* Set this variable in a debugger to enable
binary logging of the data passed to deflate().
When this variable is nonzero, it will act
as a log file name generator. */
UNIV_INTERN unsigned page_zip_compress_log = 1;
/************************************************************************** /**************************************************************************
Wrapper for deflate(). Log the operation if page_zip_compress_dbg is set. */ Wrapper for deflate(). Log the operation if page_zip_compress_dbg is set. */
...@@ -669,6 +678,7 @@ static ...@@ -669,6 +678,7 @@ static
ibool ibool
page_zip_compress_deflate( page_zip_compress_deflate(
/*======================*/ /*======================*/
FILE* logfile,/* in: log file, or NULL */
z_streamp strm, /* in/out: compressed stream for deflate() */ z_streamp strm, /* in/out: compressed stream for deflate() */
int flush) /* in: deflate() flushing method */ int flush) /* in: deflate() flushing method */
{ {
...@@ -676,6 +686,9 @@ page_zip_compress_deflate( ...@@ -676,6 +686,9 @@ page_zip_compress_deflate(
if (UNIV_UNLIKELY(page_zip_compress_dbg)) { if (UNIV_UNLIKELY(page_zip_compress_dbg)) {
ut_print_buf(stderr, strm->next_in, strm->avail_in); ut_print_buf(stderr, strm->next_in, strm->avail_in);
} }
if (UNIV_LIKELY_NULL(logfile)) {
fwrite(strm->next_in, 1, strm->avail_in, logfile);
}
status = deflate(strm, flush); status = deflate(strm, flush);
if (UNIV_UNLIKELY(page_zip_compress_dbg)) { if (UNIV_UNLIKELY(page_zip_compress_dbg)) {
fprintf(stderr, " -> %d\n", status); fprintf(stderr, " -> %d\n", status);
...@@ -685,8 +698,13 @@ page_zip_compress_deflate( ...@@ -685,8 +698,13 @@ page_zip_compress_deflate(
/* Redefine deflate(). */ /* Redefine deflate(). */
# undef deflate # undef deflate
# define deflate page_zip_compress_deflate # define deflate(strm, flush) page_zip_compress_deflate(logfile, strm, flush)
#endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */ # define FILE_LOGFILE FILE* logfile,
# define LOGFILE logfile,
#else /* PAGE_ZIP_COMPRESS_DBG */
# define FILE_LOGFILE
# define LOGFILE
#endif /* PAGE_ZIP_COMPRESS_DBG */
/************************************************************************** /**************************************************************************
Compress the records of a node pointer page. */ Compress the records of a node pointer page. */
...@@ -695,6 +713,7 @@ int ...@@ -695,6 +713,7 @@ int
page_zip_compress_node_ptrs( page_zip_compress_node_ptrs(
/*========================*/ /*========================*/
/* out: Z_OK, or a zlib error code */ /* out: Z_OK, or a zlib error code */
FILE_LOGFILE
z_stream* c_stream, /* in/out: compressed page stream */ z_stream* c_stream, /* in/out: compressed page stream */
const rec_t** recs, /* in: dense page directory const rec_t** recs, /* in: dense page directory
sorted by address */ sorted by address */
...@@ -759,6 +778,7 @@ int ...@@ -759,6 +778,7 @@ int
page_zip_compress_sec( page_zip_compress_sec(
/*==================*/ /*==================*/
/* out: Z_OK, or a zlib error code */ /* out: Z_OK, or a zlib error code */
FILE_LOGFILE
z_stream* c_stream, /* in/out: compressed page stream */ z_stream* c_stream, /* in/out: compressed page stream */
const rec_t** recs, /* in: dense page directory const rec_t** recs, /* in: dense page directory
sorted by address */ sorted by address */
...@@ -803,6 +823,7 @@ int ...@@ -803,6 +823,7 @@ int
page_zip_compress_clust_ext( page_zip_compress_clust_ext(
/*========================*/ /*========================*/
/* out: Z_OK, or a zlib error code */ /* out: Z_OK, or a zlib error code */
FILE_LOGFILE
z_stream* c_stream, /* in/out: compressed page stream */ z_stream* c_stream, /* in/out: compressed page stream */
const rec_t* rec, /* in: record */ const rec_t* rec, /* in: record */
const ulint* offsets, /* in: rec_get_offsets(rec) */ const ulint* offsets, /* in: rec_get_offsets(rec) */
...@@ -929,6 +950,7 @@ int ...@@ -929,6 +950,7 @@ int
page_zip_compress_clust( page_zip_compress_clust(
/*====================*/ /*====================*/
/* out: Z_OK, or a zlib error code */ /* out: Z_OK, or a zlib error code */
FILE_LOGFILE
z_stream* c_stream, /* in/out: compressed page stream */ z_stream* c_stream, /* in/out: compressed page stream */
const rec_t** recs, /* in: dense page directory const rec_t** recs, /* in: dense page directory
sorted by address */ sorted by address */
...@@ -986,6 +1008,7 @@ page_zip_compress_clust( ...@@ -986,6 +1008,7 @@ page_zip_compress_clust(
ut_ad(dict_index_is_clust(index)); ut_ad(dict_index_is_clust(index));
err = page_zip_compress_clust_ext( err = page_zip_compress_clust_ext(
LOGFILE
c_stream, rec, offsets, trx_id_col, c_stream, rec, offsets, trx_id_col,
deleted, storage, &externs, n_blobs); deleted, storage, &externs, n_blobs);
...@@ -1081,6 +1104,9 @@ page_zip_compress( ...@@ -1081,6 +1104,9 @@ page_zip_compress(
ulint* offsets = NULL; ulint* offsets = NULL;
ulint n_blobs = 0; ulint n_blobs = 0;
byte* storage;/* storage of uncompressed columns */ byte* storage;/* storage of uncompressed columns */
#ifdef PAGE_ZIP_COMPRESS_DBG
FILE* logfile = NULL;
#endif
ut_a(page_is_comp(page)); ut_a(page_is_comp(page));
ut_a(fil_page_get_type(page) == FIL_PAGE_INDEX); ut_a(fil_page_get_type(page) == FIL_PAGE_INDEX);
...@@ -1113,18 +1139,41 @@ page_zip_compress( ...@@ -1113,18 +1139,41 @@ page_zip_compress(
/* The dense directory excludes the infimum and supremum records. */ /* The dense directory excludes the infimum and supremum records. */
n_dense = page_dir_get_n_heap(page) - PAGE_HEAP_NO_USER_LOW; n_dense = page_dir_get_n_heap(page) - PAGE_HEAP_NO_USER_LOW;
#if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG #ifdef PAGE_ZIP_COMPRESS_DBG
if (UNIV_UNLIKELY(page_zip_compress_dbg)) { if (UNIV_UNLIKELY(page_zip_compress_dbg)) {
fprintf(stderr, "compress %p %p %lu %lu %lu\n", fprintf(stderr, "compress %p %p %lu %lu %lu\n",
(void*) page_zip, (void*) page, (void*) page_zip, (void*) page,
page_is_leaf(page), page_is_leaf(page),
n_fields, n_dense); n_fields, n_dense);
} }
#endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */ if (UNIV_UNLIKELY(page_zip_compress_log)) {
/* Create a log file for every compression attempt. */
char logfilename[9];
ut_snprintf(logfilename, sizeof logfilename,
"%08x", page_zip_compress_log++);
logfile = fopen(logfilename, "wb");
if (logfile) {
/* Write the uncompressed page to the log. */
fwrite(page, 1, UNIV_PAGE_SIZE, logfile);
/* Record the compressed size as zero.
This will be overwritten at successful exit. */
putc(0, logfile);
putc(0, logfile);
putc(0, logfile);
putc(0, logfile);
}
}
#endif /* PAGE_ZIP_COMPRESS_DBG */
page_zip_compress_count[page_zip->ssize]++; page_zip_compress_count[page_zip->ssize]++;
if (UNIV_UNLIKELY(n_dense * PAGE_ZIP_DIR_SLOT_SIZE if (UNIV_UNLIKELY(n_dense * PAGE_ZIP_DIR_SLOT_SIZE
>= page_zip_get_size(page_zip))) { >= page_zip_get_size(page_zip))) {
#ifdef PAGE_ZIP_COMPRESS_DBG
if (logfile) {
fclose(logfile);
}
#endif /* PAGE_ZIP_COMPRESS_DBG */
return(FALSE); return(FALSE);
} }
...@@ -1208,20 +1257,23 @@ page_zip_compress( ...@@ -1208,20 +1257,23 @@ page_zip_compress(
if (UNIV_UNLIKELY(!n_dense)) { if (UNIV_UNLIKELY(!n_dense)) {
} else if (!page_is_leaf(page)) { } else if (!page_is_leaf(page)) {
/* This is a node pointer page. */ /* This is a node pointer page. */
err = page_zip_compress_node_ptrs(&c_stream, recs, n_dense, err = page_zip_compress_node_ptrs(LOGFILE
&c_stream, recs, n_dense,
index, storage, heap); index, storage, heap);
if (UNIV_UNLIKELY(err != Z_OK)) { if (UNIV_UNLIKELY(err != Z_OK)) {
goto zlib_error; goto zlib_error;
} }
} else if (UNIV_LIKELY(trx_id_col == ULINT_UNDEFINED)) { } else if (UNIV_LIKELY(trx_id_col == ULINT_UNDEFINED)) {
/* This is a leaf page in a secondary index. */ /* This is a leaf page in a secondary index. */
err = page_zip_compress_sec(&c_stream, recs, n_dense); err = page_zip_compress_sec(LOGFILE
&c_stream, recs, n_dense);
if (UNIV_UNLIKELY(err != Z_OK)) { if (UNIV_UNLIKELY(err != Z_OK)) {
goto zlib_error; goto zlib_error;
} }
} else { } else {
/* This is a leaf page in a clustered index. */ /* This is a leaf page in a clustered index. */
err = page_zip_compress_clust(&c_stream, recs, n_dense, err = page_zip_compress_clust(LOGFILE
&c_stream, recs, n_dense,
index, &n_blobs, trx_id_col, index, &n_blobs, trx_id_col,
buf_end - PAGE_ZIP_DIR_SLOT_SIZE buf_end - PAGE_ZIP_DIR_SLOT_SIZE
* page_get_n_recs(page), * page_get_n_recs(page),
...@@ -1248,6 +1300,11 @@ page_zip_compress( ...@@ -1248,6 +1300,11 @@ page_zip_compress(
zlib_error: zlib_error:
deflateEnd(&c_stream); deflateEnd(&c_stream);
mem_heap_free(heap); mem_heap_free(heap);
#ifdef PAGE_ZIP_COMPRESS_DBG
if (logfile) {
fclose(logfile);
}
#endif /* PAGE_ZIP_COMPRESS_DBG */
return(FALSE); return(FALSE);
} }
...@@ -1295,6 +1352,16 @@ zlib_error: ...@@ -1295,6 +1352,16 @@ zlib_error:
UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip)); UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip));
#ifdef PAGE_ZIP_COMPRESS_DBG
if (logfile) {
/* Record the compressed size of the block. */
byte sz[4];
mach_write_to_4(sz, c_stream.total_out);
fseek(logfile, UNIV_PAGE_SIZE, SEEK_SET);
fwrite(sz, 1, sizeof sz, logfile);
fclose(logfile);
}
#endif /* PAGE_ZIP_COMPRESS_DBG */
return(TRUE); return(TRUE);
} }
......
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