From 063624d0d379111e39acb337a2e2c345bb1def7a Mon Sep 17 00:00:00 2001 From: Moinak Ghosh Date: Mon, 24 Dec 2012 23:21:02 +0530 Subject: [PATCH] Fix Delta2 decode handling when not compressing. More debug statements and other minor changes. --- delta2/delta2.c | 12 ++++++------ main.c | 10 ++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/delta2/delta2.c b/delta2/delta2.c index d93afc9..1a019b7 100644 --- a/delta2/delta2.c +++ b/delta2/delta2.c @@ -27,7 +27,7 @@ * (3, 5, 7, 8) are tried to find the one that gives the maximum * reduction. A span length threshold in bytes is used. Byte spans * less than this threshold are ignored. - * Bytes are packed into integers in big-endian format. + * Bytes are packed into integers in little-endian format. * * After an optimal stride length has been identified the encoder * performs a delta run length encoding on the spans. Two types of @@ -71,7 +71,7 @@ #define MSB_SHIFT (56) /* - * Delta2 algorithm processes data in chunks. The 4K size below is somewhat + * Delta2 algorithm processes data in blocks. The 4K size below is somewhat * adhoc but a couple of considerations were looked at: * 1) Balance between number of headers and delta runs. Too small chunks * will increase header counts for long delta runs spanning chunks. @@ -86,8 +86,8 @@ * and interpreted in little-endian order. */ #if BYTE_ORDER == BIG_ENDIAN -#define HTONLL __bswap_64(x) -#define NTOHLL __bswap_64(x) +#define HTONLL htonll +#define NTOHLL ntohll #else #define HTONLL #define NTOHLL @@ -249,14 +249,14 @@ delta2_encode_real(uchar_t *src, uint64_t srclen, uchar_t *dst, uint64_t *dstlen gtot2 += DELTA_HDR; /* * If this ended into another table reset next scan - * point to before the table. + * point to beginning of the table. */ val = cnt - snum; } else { gtot2 += snum; /* * If this ended into another table reset next scan - * point to before the table. + * point to beginning of the table. */ if (snum >= (MIN_THRESH>>1)) val = cnt - snum; diff --git a/main.c b/main.c index 7a4c3e1..b62aea2 100644 --- a/main.c +++ b/main.c @@ -247,6 +247,7 @@ preproc_compress(compress_func_ptr cmp_func, void *src, uint64_t srclen, void *d *dstlen = _dstlen + 9; DEBUG_STAT_EN(fprintf(stderr, "Chunk compression speed %.3f MB/s\n", get_mb_s(srclen, strt, en))); } else { + DEBUG_STAT_EN(fprintf(stderr, "Chunk did not compress.\n")); memcpy(dest+1, src, srclen); *dstlen = srclen + 1; result = 0; @@ -274,10 +275,13 @@ preproc_decompress(compress_func_ptr dec_func, void *src, uint64_t srclen, void DEBUG_STAT_EN(strt = get_wtime_millis()); result = dec_func(sorc, srclen, dst, dstlen, level, chdr, data); DEBUG_STAT_EN(en = get_wtime_millis()); + if (result < 0) return (result); DEBUG_STAT_EN(fprintf(stderr, "Chunk decompression speed %.3f MB/s\n", get_mb_s(srclen, strt, en))); memcpy(src, dst, *dstlen); srclen = *dstlen; + } else { + src = sorc; } if (type & PREPROC_TYPE_DELTA2) { @@ -1253,8 +1257,14 @@ plain_compress: compressed_chunk, &_chunksize, tdat->level, 0, tdat->data, tdat->props); } else { + DEBUG_STAT_EN(double strt, en); + + DEBUG_STAT_EN(strt = get_wtime_millis()); rv = tdat->compress(tdat->uncompressed_chunk, tdat->rbytes, compressed_chunk, &_chunksize, tdat->level, 0, tdat->data); + DEBUG_STAT_EN(en = get_wtime_millis()); + DEBUG_STAT_EN(fprintf(stderr, "Chunk compression speed %.3f MB/s\n", + get_mb_s(_chunksize, strt, en))); } }