diff --git a/rebar.config b/rebar.config index 09bc631..859c738 100644 --- a/rebar.config +++ b/rebar.config @@ -30,7 +30,7 @@ , {plain_fsm, "1.1.*", {git, "git://github.com/gburd/plain_fsm", {branch, "master"}}} , {basho_bench, ".*", {git, "git://github.com/basho/basho_bench", {branch, "master"}}} , {triq, ".*", {git, "git://github.com/krestenkrab/triq", {branch, "master"}}} -% , {lz4, ".*", {git, "git://github.com/gburd/erlang-lz4.git", {branch, "master"}}} + , {lz4, ".*", {git, "git://github.com/krestenkrab/erlang-lz4.git", {branch, "master"}}} % , {edown, "0.3.*", {git, "git://github.com/esl/edown.git", {branch, "master"}}} % , {asciiedoc, "0.1.*", {git, "git://github.com/norton/asciiedoc.git", {branch, "master"}}} % , {triq, ".*", {git, "git://github.com/krestenkrab/triq.git", {branch, "master"}}} diff --git a/src/hanoidb.erl b/src/hanoidb.erl index 7e847d8..6666887 100644 --- a/src/hanoidb.erl +++ b/src/hanoidb.erl @@ -62,7 +62,7 @@ -type hanoidb() :: pid(). -type key_range() :: #key_range{}. --type config_option() :: {compress, none | gzip | snappy} %lz4 +-type config_option() :: {compress, none | gzip | snappy | lz4} | {page_size, pos_integer()} | {read_buffer_size, pos_integer()} | {write_buffer_size, pos_integer()} diff --git a/src/hanoidb_util.erl b/src/hanoidb_util.erl index 861b673..47c7a9a 100644 --- a/src/hanoidb_util.erl +++ b/src/hanoidb_util.erl @@ -89,7 +89,7 @@ estimate_node_size_increment(_KVList, Key, Value) -define(NO_COMPRESSION, 0). -define(SNAPPY_COMPRESSION, 1). -define(GZIP_COMPRESSION, 2). -%%-define(LZ4_COMPRESSION, 3). +-define(LZ4_COMPRESSION, 3). use_compressed(UncompressedSize, CompressedSize) when CompressedSize < UncompressedSize -> true; @@ -104,14 +104,14 @@ compress(snappy, Bin) -> false -> {?NO_COMPRESSION, Bin} end; -%% compress(lz4, Bin) -> -%% {ok, CompressedBin} = lz4:compress(Bin), -%% case use_compressed(erlang:iolist_size(Bin), erlang:iolist_size(CompressedBin)) of -%% true -> -%% {?LZ4_COMPRESSION, CompressedBin}; -%% false -> -%% {?NO_COMPRESSION, Bin} -%% end; +compress(lz4, Bin) -> + {ok, CompressedBin} = lz4:compress(erlang:iolist_to_binary(Bin)), + case use_compressed(erlang:iolist_size(Bin), erlang:iolist_size(CompressedBin)) of + true -> + {?LZ4_COMPRESSION, CompressedBin}; + false -> + {?NO_COMPRESSION, Bin} + end; compress(gzip, Bin) -> CompressedBin = zlib:gzip(Bin), case use_compressed(erlang:iolist_size(Bin), erlang:iolist_size(CompressedBin)) of @@ -128,8 +128,8 @@ uncompress(<>) -> uncompress(<>) -> {ok, UncompressedData} = snappy:decompress(Data), UncompressedData; -%%uncompress(<>) -> -%% lz4:uncompress(Data); +uncompress(<>) -> + lz4:uncompress(Data); uncompress(<>) -> zlib:gunzip(Data).