Enable lz4 compression

This commit is contained in:
Kresten Krab Thorup 2012-09-26 16:05:51 +02:00
parent 923dbe3852
commit 35de7a3300
3 changed files with 13 additions and 13 deletions

View file

@ -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"}}}

View file

@ -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()}

View file

@ -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(<<?NO_COMPRESSION, Data/binary>>) ->
uncompress(<<?SNAPPY_COMPRESSION, Data/binary>>) ->
{ok, UncompressedData} = snappy:decompress(Data),
UncompressedData;
%%uncompress(<<?LZ4_COMPRESSION, Data/binary>>) ->
%% lz4:uncompress(Data);
uncompress(<<?LZ4_COMPRESSION, Data/binary>>) ->
lz4:uncompress(Data);
uncompress(<<?GZIP_COMPRESSION, Data/binary>>) ->
zlib:gunzip(Data).