Don't use fetch_cache below the page_cache level

This commit is contained in:
Martin Sumner 2022-03-10 11:23:53 +00:00
parent 79e0af27f6
commit 656900e9ec

View file

@ -184,6 +184,7 @@
-type sst_summary() -type sst_summary()
:: #summary{}. :: #summary{}.
-type blockindex_cache() :: array:array(). -type blockindex_cache() :: array:array().
-type fetch_cache() :: array:array()|no_cache.
%% yield_blockquery is used to determine if the work necessary to process a %% yield_blockquery is used to determine if the work necessary to process a
%% range query beyond the fetching the slot should be managed from within %% range query beyond the fetching the slot should be managed from within
@ -207,7 +208,7 @@
timings_countdown = 0 :: integer(), timings_countdown = 0 :: integer(),
starting_pid :: pid()|undefined, starting_pid :: pid()|undefined,
fetch_cache = array:new([{size, ?CACHE_SIZE}]) :: fetch_cache = array:new([{size, ?CACHE_SIZE}]) ::
array:array() | redacted, array:array() | redacted | no_cache,
new_slots :: list()|undefined, new_slots :: list()|undefined,
deferred_startup_tuple :: tuple()|undefined, deferred_startup_tuple :: tuple()|undefined,
level :: non_neg_integer()|undefined, level :: non_neg_integer()|undefined,
@ -1102,6 +1103,24 @@ extract_hash(NotHash) ->
cache_hash({_SegHash, ExtraHash}) when is_integer(ExtraHash) -> cache_hash({_SegHash, ExtraHash}) when is_integer(ExtraHash) ->
ExtraHash band (?CACHE_SIZE - 1). ExtraHash band (?CACHE_SIZE - 1).
-spec fetch_from_cache(
non_neg_integer(),
fetch_cache()) -> undefined|leveled_codec:ledger_kv().
fetch_from_cache(_CacheHash, no_cache) ->
undefined;
fetch_from_cache(CacheHash, Cache) ->
array:get(CacheHash, Cache).
-spec add_to_cache(
non_neg_integer(),
leveled_codec:ledger_kv()
fetch_cache()) -> fetch_cache().
add_to_cache(_CacheHash, _KV, no_cache) ->
no_cache;
add_to_cache(CacheHash, KV, FetchCache) ->
array:set(CacheHash, KV, FetchCache).
-spec tune_hash(non_neg_integer()) -> non_neg_integer(). -spec tune_hash(non_neg_integer()) -> non_neg_integer().
%% @doc %% @doc
%% Only 15 bits of the hash is ever interesting %% Only 15 bits of the hash is ever interesting
@ -1238,7 +1257,7 @@ fetch(LedgerKey, Hash, State, Timings0) ->
update_timings(SW2, Timings2, slot_index, true), update_timings(SW2, Timings2, slot_index, true),
FetchCache = State#state.fetch_cache, FetchCache = State#state.fetch_cache,
CacheHash = cache_hash(Hash), CacheHash = cache_hash(Hash),
case array:get(CacheHash, FetchCache) of case fetch_from_cache(CacheHash, FetchCache) of
{LedgerKey, V} -> {LedgerKey, V} ->
{_SW4, Timings4} = {_SW4, Timings4} =
update_timings(SW3, update_timings(SW3,
@ -1258,7 +1277,7 @@ fetch(LedgerKey, Hash, State, Timings0) ->
IdxModDate, IdxModDate,
not_present), not_present),
FetchCache0 = FetchCache0 =
array:set(CacheHash, Result, FetchCache), add_to_cache(CacheHash, Result, FetchCache),
{_SW4, Timings4} = {_SW4, Timings4} =
update_timings(SW3, update_timings(SW3,
Timings3, Timings3,
@ -1382,10 +1401,10 @@ write_file(RootPath, Filename, SummaryBin, SlotsBin,
false), false),
FinalName. FinalName.
read_file(Filename, State, LoadPageCache) -> read_file(Filename, State, CacheFile) ->
{Handle, FileVersion, SummaryBin} = {Handle, FileVersion, SummaryBin} =
open_reader(filename:join(State#state.root_path, Filename), open_reader(filename:join(State#state.root_path, Filename),
LoadPageCache), CacheFile),
UpdState0 = imp_fileversion(FileVersion, State), UpdState0 = imp_fileversion(FileVersion, State),
{Summary, Bloom, SlotList, TombCount} = {Summary, Bloom, SlotList, TombCount} =
read_table_summary(SummaryBin, UpdState0#state.tomb_count), read_table_summary(SummaryBin, UpdState0#state.tomb_count),
@ -1396,10 +1415,18 @@ read_file(Filename, State, LoadPageCache) ->
leveled_log:log("SST03", [Filename, leveled_log:log("SST03", [Filename,
Summary#summary.size, Summary#summary.size,
Summary#summary.max_sqn]), Summary#summary.max_sqn]),
FetchCache =
case CacheFile of
true ->
State#state.fetch_cache;
false ->
no_cache
end,
{UpdState1#state{summary = UpdSummary, {UpdState1#state{summary = UpdSummary,
handle = Handle, handle = Handle,
filename = Filename, filename = Filename,
tomb_count = TombCount}, tomb_count = TombCount,
fetch_cache = FetchCache},
Bloom}. Bloom}.
gen_fileversion(PressMethod, IdxModDate, CountOfTombs) -> gen_fileversion(PressMethod, IdxModDate, CountOfTombs) ->