Change page cache loading by lookup/no_lookup

By default load the first 4 levels of the ledger into the page cache of lookup is to be supported, but just levels 0 and 1 otherwise.
This commit is contained in:
Martin Sumner 2019-07-18 14:00:19 +01:00
parent 85bfa7fbb4
commit 7862a6c523
3 changed files with 33 additions and 13 deletions

View file

@ -51,7 +51,8 @@
:: leveled_sst:press_method(),
log_options = leveled_log:get_opts()
:: leveled_log:log_options(),
max_sstslots = 256 :: pos_integer()}).
max_sstslots = 256 :: pos_integer(),
pagecache_level = 1 :: pos_integer()}).
-record(inker_options,
{cdb_max_size :: integer() | undefined,

View file

@ -127,6 +127,8 @@
-define(OPEN_LASTMOD_RANGE, {0, infinity}).
-define(SNAPTIMEOUT_SHORT, 900). % 15 minutes
-define(SNAPTIMEOUT_LONG, 43200). % 12 hours
-define(SST_PAGECACHELEVEL_NOLOOKUP, 1).
-define(SST_PAGECACHELEVEL_LOOKUP, 4).
-define(OPTION_DEFAULTS,
[{root_path, undefined},
{snapshot_bookie, undefined},
@ -1177,15 +1179,22 @@ init([Opts]) ->
ok
end,
{HeadOnly, HeadLookup} =
{HeadOnly, HeadLookup, SSTPageCacheLevel} =
case proplists:get_value(head_only, Opts) of
false ->
{false, true};
{false, true, ?SST_PAGECACHELEVEL_LOOKUP};
with_lookup ->
{true, true};
{true, true, ?SST_PAGECACHELEVEL_LOOKUP};
no_lookup ->
{true, false}
{true, false, ?SST_PAGECACHELEVEL_NOLOOKUP}
end,
% Override the default page cache level - we want to load into the
% page cache many levels if we intend to support lookups, and only
% levels 0 and 1 otherwise
SSTOpts = PencillerOpts#penciller_options.sst_options,
SSTOpts0 = SSTOpts#sst_options{pagecache_level = SSTPageCacheLevel},
PencillerOpts0 =
PencillerOpts#penciller_options{sst_options = SSTOpts0},
State0 = #state{cache_size=CacheSize,
is_snapshot=false,
@ -1193,7 +1202,7 @@ init([Opts]) ->
head_lookup = HeadLookup},
{Inker, Penciller} =
startup(InkerOpts, PencillerOpts, State0),
startup(InkerOpts, PencillerOpts0, State0),
NewETS = ets:new(mem, [ordered_set]),
leveled_log:log("B0001", [Inker, Penciller]),

View file

@ -486,7 +486,9 @@ init([]) ->
starting({sst_open, RootPath, Filename, OptsSST, Level}, _From, State) ->
leveled_log:save(OptsSST#sst_options.log_options),
{UpdState, Bloom} =
read_file(Filename, State#state{root_path=RootPath}),
read_file(Filename,
State#state{root_path=RootPath},
OptsSST#sst_options.pagecache_level >= Level),
Summary = UpdState#state.summary,
{reply,
{ok, {Summary#summary.first_key, Summary#summary.last_key}, Bloom},
@ -509,7 +511,8 @@ starting({sst_new,
YBQ = Level =< 2,
{UpdState, Bloom} =
read_file(ActualFilename,
State#state{root_path=RootPath, yield_blockquery=YBQ}),
State#state{root_path=RootPath, yield_blockquery=YBQ},
OptsSST#sst_options.pagecache_level >= Level),
Summary = UpdState#state.summary,
leveled_log:log_timer("SST08",
[ActualFilename, Level, Summary#summary.max_sqn],
@ -573,7 +576,8 @@ starting(complete_l0startup, State) ->
% Important to empty this from state rather
% than carry it through to the next stage
new_slots=undefined,
deferred_startup_tuple=undefined}),
deferred_startup_tuple=undefined},
true),
Summary = UpdState#state.summary,
Time4 = timer:now_diff(os:timestamp(), SW4),
@ -1215,9 +1219,10 @@ write_file(RootPath, Filename, SummaryBin, SlotsBin,
filename:join(RootPath, FinalName)),
FinalName.
read_file(Filename, State) ->
read_file(Filename, State, LoadPageCache) ->
{Handle, FileVersion, SummaryBin} =
open_reader(filename:join(State#state.root_path, Filename)),
open_reader(filename:join(State#state.root_path, Filename),
LoadPageCache),
UpdState0 = imp_fileversion(FileVersion, State),
{Summary, Bloom, SlotList} = read_table_summary(SummaryBin),
BlockIndexCache = array:new([{size, Summary#summary.size},
@ -1269,13 +1274,18 @@ imp_fileversion(VersionInt, State) ->
end,
UpdState1.
open_reader(Filename) ->
open_reader(Filename, LoadPageCache) ->
{ok, Handle} = file:open(Filename, [binary, raw, read]),
{ok, Lengths} = file:pread(Handle, 0, 9),
<<FileVersion:8/integer,
SlotsLength:32/integer,
SummaryLength:32/integer>> = Lengths,
ok = file:advise(Handle, 9, SlotsLength, will_need),
case LoadPageCache of
true ->
file:advise(Handle, 9, SlotsLength, will_need);
false ->
ok
end,
{ok, SummaryBin} = file:pread(Handle, SlotsLength + 9, SummaryLength),
{Handle, FileVersion, SummaryBin}.