Commit 836df9b0 authored by John Esmet's avatar John Esmet Committed by Yoni Fogel

close[t:3751] compression now switchable via makefile, via make COMPRESS=0....

close[t:3751] compression now switchable via makefile, via make COMPRESS=0. also, tokudb can installed into a local prefix, via make install

git-svn-id: file:///svn/toku/tokudb@35780 c7de825b-a66e-492c-adef-691d508d4ae1
parent 2df5b227
......@@ -84,8 +84,27 @@ clean: $(patsubst %,%.dir.clean,$(SRCDIRS)) cleanlib
cleanlib:
rm -rf lib/*.$(SOEXT) lib/*.$(AEXT) lib/*.bundle
install:
./install.bash
# This does not work, and probably hasn't worked since revision ~2000
# install:
# ./install.bash
# Default to building locally in one's home directory
PREFIX = $(HOME)/local
# This is a quick hack for an install rule
install: release
mkdir -p $(PREFIX)/lib $(PREFIX)/include
/bin/cp release/lib/libtokudb.so $(PREFIX)/lib
/bin/cp release/lib/libtokuportability.so $(PREFIX)/lib
/bin/cp release/include/db.h $(PREFIX)/include/tokudb.h
/bin/cp release/include/tdb-internal.h $(PREFIX)/include
/bin/cp release/include/toku_list.h $(PREFIX)/include
uninstall:
/bin/rm -f $(PREFIX)/lib/libtokudb.so $(PREFIX)/lib/libtokuportability.so
/bin/rm -f $(PREFIX)/lib/libtokuportability.so
/bin/rm -f $(PREFIX)/include/tokudb.h $(PREFIX)/include/tdb-internal.h
/bin/rm -f $(PREFIX)/include/toku_list.h
# maybe we should have a coverage target in each makefile
build-coverage:
......
......@@ -7,6 +7,11 @@ ifneq ($(COMBINE),0)
COMBINE=1
endif
COMPRESS = 1
ifneq ($(COMPRESS), 1)
CFLAGS += -DTOKU_CONFIG_NO_COMPRESSION
endif
#TODO: Replace DEPEND_COMPILE with auto-dependancy generation.
DEPEND_COMPILE += \
$(wildcard *.h) \
......
......@@ -13,10 +13,12 @@ size_t toku_compress_bound (enum toku_compression_method a, size_t size)
// See compress.h for the specification of this function.
{
switch (a) {
case TOKU_NO_COMPRESSION:
return size + 1;
case TOKU_QUICKLZ_METHOD:
return size+400 + 1; // quicklz manual says 400 bytes is enough. We need one more byte for the rfc1950-style header byte. bits 0-3 are 9, bits 4-7 are the QLZ_COMPRESSION_LEVEL.
return size+400 + 1; // quicklz manual says 400 bytes is enough. We need one more byte for the rfc1950-style header byte. bits 0-3 are 9, bits 4-7 are the QLZ_COMPRESSION_LEVEL.
case TOKU_ZLIB_METHOD:
return compressBound (size);
return compressBound (size);
}
// fall through for bad enum (thus compiler can warn us if we didn't use all the enums
assert(0); return 0;
......@@ -25,63 +27,71 @@ size_t toku_compress_bound (enum toku_compression_method a, size_t size)
static const int zlib_compression_level = 5;
void toku_compress (enum toku_compression_method a,
// the following types and naming conventions come from zlib.h
Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen)
// the following types and naming conventions come from zlib.h
Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen)
// See compress.h for the specification of this function.
{
assert(sourceLen < (1LL << 32));
switch (a) {
case TOKU_NO_COMPRESSION:
dest[0] = TOKU_NO_COMPRESSION;
memcpy(dest + 1, source, sourceLen);
*destLen = sourceLen + 1;
return;
case TOKU_ZLIB_METHOD: {
int r = compress2(dest, destLen, source, sourceLen, zlib_compression_level);
assert(r == Z_OK);
assert((dest[0]&0xF) == TOKU_ZLIB_METHOD);
return;
int r = compress2(dest, destLen, source, sourceLen, zlib_compression_level);
assert(r == Z_OK);
assert((dest[0]&0xF) == TOKU_ZLIB_METHOD);
return;
}
case TOKU_QUICKLZ_METHOD: {
if (sourceLen==0) {
// quicklz requires at least one byte, so we handle this ourselves
assert(1 <= *destLen);
*destLen = 1;
} else {
qlz_state_compress *XMALLOC(qsc);
size_t actual_destlen = qlz_compress(source, (char*)(dest+1), sourceLen, qsc);
assert(actual_destlen +1 <= *destLen);
*destLen = actual_destlen+1; // add one for the rfc1950-style header byte.
toku_free(qsc);
}
// Fill in that first byte
dest[0] = TOKU_QUICKLZ_METHOD + (QLZ_COMPRESSION_LEVEL << 4);
return;
if (sourceLen==0) {
// quicklz requires at least one byte, so we handle this ourselves
assert(1 <= *destLen);
*destLen = 1;
} else {
qlz_state_compress *XMALLOC(qsc);
size_t actual_destlen = qlz_compress(source, (char*)(dest+1), sourceLen, qsc);
assert(actual_destlen +1 <= *destLen);
*destLen = actual_destlen+1; // add one for the rfc1950-style header byte.
toku_free(qsc);
}
// Fill in that first byte
dest[0] = TOKU_QUICKLZ_METHOD + (QLZ_COMPRESSION_LEVEL << 4);
return;
}}
// default fall through to error.
assert(0);
}
void toku_decompress (Bytef *dest, uLongf destLen,
const Bytef *source, uLongf sourceLen)
const Bytef *source, uLongf sourceLen)
// See compress.h for the specification of this function.
{
assert(sourceLen>=1); // need at least one byte for the RFC header.
switch (source[0] & 0xF) {
case TOKU_NO_COMPRESSION:
memcpy(dest, source + 1, sourceLen - 1);
return;
case TOKU_ZLIB_METHOD: {
uLongf actual_destlen = destLen;
int r = uncompress(dest, &actual_destlen, source, sourceLen);
assert(r == Z_OK);
assert(actual_destlen == destLen);
return;
uLongf actual_destlen = destLen;
int r = uncompress(dest, &actual_destlen, source, sourceLen);
assert(r == Z_OK);
assert(actual_destlen == destLen);
return;
}
case TOKU_QUICKLZ_METHOD:
if (sourceLen>1) {
qlz_state_decompress *XMALLOC(qsd);
uLongf actual_destlen = qlz_decompress((char*)source+1, dest, qsd);
assert(actual_destlen == destLen);
toku_free(qsd);
} else {
// length 1 means there is no data, so do nothing.
assert(destLen==0);
}
return;
if (sourceLen>1) {
qlz_state_decompress *XMALLOC(qsd);
uLongf actual_destlen = qlz_decompress((char*)source+1, dest, qsd);
assert(actual_destlen == destLen);
toku_free(qsd);
} else {
// length 1 means there is no data, so do nothing.
assert(destLen==0);
}
return;
}
// default fall through to error.
assert(0);
......
......@@ -11,6 +11,7 @@
// The resulting byte string includes enough information for us to decompress it. That is, we can tell whether it's z-compressed or qz-compressed.
enum toku_compression_method {
TOKU_NO_COMPRESSION = 0, // "identity" compression
TOKU_ZLIB_METHOD = 8, // RFC 1950 says use 8 for zlib. It reserves 15 to allow more bytes.
TOKU_QUICKLZ_METHOD = 9 // We use 9 for QUICKLZ with compression level = 3. I couldn't find any standard for any other numbers, so I just use 9. -Bradley
};
......
......@@ -144,9 +144,16 @@ compress_work_init(struct compress_work *w, struct sub_block *sub_block) {
w->sub_block = sub_block;
}
// Allow the makefile to optionally configure for no compression
#ifdef TOKU_CONFIG_NO_COMPRESSION
static enum toku_compression_method toku_compress_method = TOKU_NO_COMPRESSION;
#else
static enum toku_compression_method toku_compress_method = TOKU_QUICKLZ_METHOD;
#endif
void toku_set_default_compression_method (enum toku_compression_method a) {
switch (a) {
case TOKU_NO_COMPRESSION:
case TOKU_ZLIB_METHOD:
case TOKU_QUICKLZ_METHOD:
toku_compress_method = a;
......
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