Revert "Don't use fetch_cache below the page_cache level"

This reverts commit 656900e9ec.
This commit is contained in:
Martin Sumner 2022-03-11 11:07:01 +00:00
parent 5eae8e441f
commit 75edb7293d

View file

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