Remove SST blooms

This commit is contained in:
martinsumner 2017-01-03 09:12:41 +00:00
parent 5b4c903d53
commit d28e5d639c

View file

@ -72,7 +72,7 @@
-define(SLOT_SIZE, 128). % This is not configurable -define(SLOT_SIZE, 128). % This is not configurable
-define(COMPRESSION_LEVEL, 1). -define(COMPRESSION_LEVEL, 1).
-define(BINARY_SETTINGS, [{compressed, ?COMPRESSION_LEVEL}]). -define(BINARY_SETTINGS, [{compressed, ?COMPRESSION_LEVEL}]).
-define(LEVEL_BLOOM_BITS, [{0, 8}, {1, 10}, {2, 8}, {default, 6}]). % -define(LEVEL_BLOOM_BITS, [{0, 8}, {1, 10}, {2, 8}, {default, 6}]).
-define(MERGE_SCANWIDTH, 16). -define(MERGE_SCANWIDTH, 16).
-define(DISCARD_EXT, ".discarded"). -define(DISCARD_EXT, ".discarded").
-define(DELETE_TIMEOUT, 10000). -define(DELETE_TIMEOUT, 10000).
@ -117,8 +117,7 @@
last_key :: tuple(), last_key :: tuple(),
index :: list(), % leveled_skiplist index :: list(), % leveled_skiplist
size :: integer(), size :: integer(),
max_sqn :: integer(), max_sqn :: integer()}).
bloom}).
-record(state, {summary, -record(state, {summary,
handle :: file:fd(), handle :: file:fd(),
@ -417,11 +416,6 @@ code_change(_OldVsn, StateName, State, _Extra) ->
fetch(LedgerKey, Hash, State) -> fetch(LedgerKey, Hash, State) ->
Summary = State#state.summary, Summary = State#state.summary,
case leveled_tinybloom:check({hash, Hash},
Summary#summary.bloom) of
false ->
{not_present, summary_bloom, null, State};
true ->
Slot = lookup_slot(LedgerKey, Summary#summary.index), Slot = lookup_slot(LedgerKey, Summary#summary.index),
SlotID = Slot#slot_index_value.slot_id, SlotID = Slot#slot_index_value.slot_id,
CachedBlockIdx = array:get(SlotID - 1, CachedBlockIdx = array:get(SlotID - 1,
@ -447,10 +441,7 @@ fetch(LedgerKey, Hash, State) ->
0), 0),
case PosList of case PosList of
[] -> [] ->
{not_present, {not_present, slot_bloom, SlotID, State};
slot_bloom,
SlotID,
State};
_ -> _ ->
LastKV = array:get(SlotID - 1, LastKV = array:get(SlotID - 1,
State#state.lastfetch_cache), State#state.lastfetch_cache),
@ -458,17 +449,12 @@ fetch(LedgerKey, Hash, State) ->
{LedgerKey, _} -> {LedgerKey, _} ->
{LastKV, slot_cache, SlotID, State}; {LastKV, slot_cache, SlotID, State};
_ -> _ ->
SlotBin = read_slot(State#state.handle, SlotBin = read_slot(State#state.handle, Slot),
Slot),
Result = binaryslot_get(SlotBin, Result = binaryslot_get(SlotBin,
LedgerKey, LedgerKey,
Hash, Hash,
{true, PosList}), {true, PosList}),
{element(1, Result), {element(1, Result), slot_fetch, SlotID, State}
slot_fetch,
SlotID,
State}
end
end end
end end
end. end.
@ -613,26 +599,12 @@ open_reader(Filename) ->
{ok, SummaryBin} = file:pread(Handle, SlotsLength + 8, SummaryLength), {ok, SummaryBin} = file:pread(Handle, SlotsLength + 8, SummaryLength),
{Handle, SummaryBin}. {Handle, SummaryBin}.
build_table_summary(SlotIndex, AllHashes, Level, FirstKey, L, MaxSQN) -> build_table_summary(SlotIndex, _AllHashes, _Level, FirstKey, L, MaxSQN) ->
BloomBits =
case lists:keyfind(Level, 1, ?LEVEL_BLOOM_BITS) of
{Level, N} ->
N;
false ->
element(2, lists:keyfind(default, 1, ?LEVEL_BLOOM_BITS))
end,
BloomSlots = max((length(AllHashes) * BloomBits) div 4096, 1),
BloomAddFun =
fun({H, _K}, Bloom) -> leveled_tinybloom:enter(H, Bloom) end,
Bloom = lists:foldr(BloomAddFun,
leveled_tinybloom:empty(BloomSlots),
AllHashes),
[{LastKey, _LastV}|_Rest] = SlotIndex, [{LastKey, _LastV}|_Rest] = SlotIndex,
Summary = #summary{first_key = FirstKey, Summary = #summary{first_key = FirstKey,
last_key = LastKey, last_key = LastKey,
size = L, size = L,
index = lists:reverse(SlotIndex), index = lists:reverse(SlotIndex),
bloom = Bloom,
max_sqn = MaxSQN}, max_sqn = MaxSQN},
SummBin = term_to_binary(Summary, ?BINARY_SETTINGS), SummBin = term_to_binary(Summary, ?BINARY_SETTINGS),
SummCRC = erlang:crc32(SummBin), SummCRC = erlang:crc32(SummBin),