2016-10-25 01:57:12 +01:00
|
|
|
%% -------- Inker's Clerk ---------
|
|
|
|
%%
|
|
|
|
%% The Inker's clerk runs compaction jobs on behalf of the Inker, informing the
|
|
|
|
%% Inker of any manifest changes when complete.
|
|
|
|
%%
|
|
|
|
%% -------- Value Compaction ---------
|
|
|
|
%%
|
|
|
|
%% Compaction requires the Inker to have four different types of keys
|
|
|
|
%% * stnd - A standard key of the form {SQN, stnd, LedgerKey} which maps to a
|
|
|
|
%% value of {Object, KeyDeltas}
|
|
|
|
%% * tomb - A tombstone for a LedgerKey {SQN, tomb, LedgerKey}
|
|
|
|
%% * keyd - An object containing key deltas only of the form
|
|
|
|
%% {SQN, keyd, LedgerKey} which maps to a value of {KeyDeltas}
|
|
|
|
%%
|
|
|
|
%% Each LedgerKey has a Tag, and for each Tag there should be a compaction
|
|
|
|
%% strategy, which will be set to one of the following:
|
|
|
|
%% * retain - KeyDeltas must be retained permanently, only values can be
|
|
|
|
%% compacted (if replaced or not_present in the ledger)
|
|
|
|
%% * recalc - The full object can be removed through comapction (if replaced or
|
|
|
|
%% not_present in the ledger), as each object with that tag can have the Key
|
|
|
|
%% Deltas recreated by passing into an assigned recalc function {LedgerKey,
|
|
|
|
%% SQN, Object, KeyDeltas, PencillerSnapshot}
|
|
|
|
%% * recovr - At compaction time this is equivalent to recalc, only KeyDeltas
|
|
|
|
%% are lost when reloading the Ledger from the Journal, and it is assumed that
|
|
|
|
%% those deltas will be resolved through external anti-entropy (e.g. read
|
|
|
|
%% repair or AAE) - or alternatively the risk of loss of persisted data from
|
|
|
|
%% the ledger is accepted for this data type
|
|
|
|
%%
|
|
|
|
%% During the compaction process for the Journal, the file chosen for
|
|
|
|
%% compaction is scanned in SQN order, and a FilterFun is passed (which will
|
|
|
|
%% normally perform a check against a snapshot of the persisted part of the
|
|
|
|
%% Ledger). If the given key is of type stnd, and this object is no longer the
|
|
|
|
%% active object under the LedgerKey, then the object can be compacted out of
|
|
|
|
%% the journal. This will lead to either its removal (if the strategy for the
|
|
|
|
%% Tag is recovr or recalc), or its replacement with a KeyDelta object.
|
|
|
|
%%
|
|
|
|
%% Tombstones cannot be reaped through this compaction process.
|
|
|
|
%%
|
|
|
|
%% Currently, KeyDeltas are also reaped if the LedgerKey has been updated and
|
|
|
|
%% the Tag has a recovr strategy. This may be the case when KeyDeltas are used
|
|
|
|
%% as a way of directly representing a change, and where anti-entropy can
|
|
|
|
%% recover from a loss.
|
|
|
|
%%
|
2016-11-14 11:17:14 +00:00
|
|
|
%% -------- Removing Compacted Files ---------
|
|
|
|
%%
|
|
|
|
%% Once a compaction job is complete, and the manifest change has been
|
|
|
|
%% committed, the individual journal files will get a deletion prompt. The
|
|
|
|
%% Journal processes should copy the file to the waste folder, before erasing
|
|
|
|
%% themselves.
|
|
|
|
%%
|
|
|
|
%% The Inker will have a waste duration setting, and before running compaction
|
|
|
|
%% should delete all over-age items (using the file modified date) from the
|
|
|
|
%% waste.
|
|
|
|
%%
|
2016-10-25 01:57:12 +01:00
|
|
|
%% -------- Tombstone Reaping ---------
|
|
|
|
%%
|
|
|
|
%% Value compaction does not remove tombstones from the database, and so a
|
|
|
|
%% separate compaction job is required for this.
|
|
|
|
%%
|
|
|
|
%% Tombstones can only be reaped for Tags set to recovr or recalc.
|
|
|
|
%%
|
|
|
|
%% The tombstone reaping process should select a file to compact, and then
|
|
|
|
%% take that file and discover the LedgerKeys of all reapable tombstones.
|
|
|
|
%% The lesger should then be scanned from SQN 0 looking for unreaped objects
|
|
|
|
%% before the tombstone. If no ushc objects exist for that tombstone, it can
|
|
|
|
%% now be reaped as part of the compaction job.
|
|
|
|
%%
|
2016-11-14 11:17:14 +00:00
|
|
|
%% Other tombstones cannot be reaped, as otherwise on laoding a ledger an old
|
2016-10-25 01:57:12 +01:00
|
|
|
%% version of the object may re-emerge.
|
2016-09-20 16:13:36 +01:00
|
|
|
|
|
|
|
-module(leveled_iclerk).
|
|
|
|
|
|
|
|
-behaviour(gen_server).
|
|
|
|
|
2024-09-06 11:18:24 +01:00
|
|
|
-include("leveled.hrl").
|
2016-09-20 16:13:36 +01:00
|
|
|
|
|
|
|
-export([init/1,
|
|
|
|
handle_call/3,
|
|
|
|
handle_cast/2,
|
|
|
|
handle_info/2,
|
|
|
|
terminate/2,
|
2018-12-11 21:59:57 +00:00
|
|
|
code_change/3]).
|
|
|
|
|
|
|
|
-export([clerk_new/1,
|
2019-01-24 21:32:54 +00:00
|
|
|
clerk_compact/6,
|
2016-10-14 13:36:12 +01:00
|
|
|
clerk_hashtablecalc/3,
|
2018-02-15 16:14:46 +00:00
|
|
|
clerk_trim/3,
|
2016-09-20 16:13:36 +01:00
|
|
|
clerk_stop/1,
|
2018-12-11 21:59:57 +00:00
|
|
|
clerk_loglevel/2,
|
|
|
|
clerk_addlogs/2,
|
|
|
|
clerk_removelogs/2]).
|
2016-09-20 16:13:36 +01:00
|
|
|
|
2017-03-30 15:46:37 +01:00
|
|
|
-export([schedule_compaction/3]).
|
|
|
|
|
2020-11-27 20:03:44 +00:00
|
|
|
-define(SAMPLE_SIZE, 192).
|
2016-10-26 11:50:59 +01:00
|
|
|
-define(BATCH_SIZE, 32).
|
2016-10-08 22:15:48 +01:00
|
|
|
-define(CRC_SIZE, 4).
|
2016-10-25 23:13:14 +01:00
|
|
|
-define(DEFAULT_RELOAD_STRATEGY, leveled_codec:inker_reload_strategy([])).
|
2017-03-30 15:46:37 +01:00
|
|
|
-define(INTERVALS_PER_HOUR, 4).
|
2018-07-23 12:46:42 +01:00
|
|
|
-define(MAX_COMPACTION_RUN, 8).
|
|
|
|
-define(SINGLEFILE_COMPACTION_TARGET, 50.0).
|
|
|
|
-define(MAXRUNLENGTH_COMPACTION_TARGET, 75.0).
|
2016-09-27 14:58:26 +01:00
|
|
|
|
2017-07-31 19:53:01 +02:00
|
|
|
-record(state, {inker :: pid() | undefined,
|
|
|
|
max_run_length :: integer() | undefined,
|
2018-12-11 21:59:57 +00:00
|
|
|
cdb_options = #cdb_options{} :: #cdb_options{},
|
2017-07-31 19:53:01 +02:00
|
|
|
waste_retention_period :: integer() | undefined,
|
|
|
|
waste_path :: string() | undefined,
|
2017-11-06 15:54:58 +00:00
|
|
|
reload_strategy = ?DEFAULT_RELOAD_STRATEGY :: list(),
|
2018-07-23 12:46:42 +01:00
|
|
|
singlefile_compactionperc = ?SINGLEFILE_COMPACTION_TARGET :: float(),
|
|
|
|
maxrunlength_compactionperc = ?MAXRUNLENGTH_COMPACTION_TARGET ::float(),
|
2023-11-07 14:58:43 +00:00
|
|
|
compression_method = native :: lz4|native|none,
|
2019-01-25 12:11:42 +00:00
|
|
|
scored_files = [] :: list(candidate()),
|
2020-11-27 02:35:27 +00:00
|
|
|
scoring_state :: scoring_state()|undefined,
|
|
|
|
score_onein = 1 :: pos_integer()}).
|
2016-09-27 14:58:26 +01:00
|
|
|
|
2017-07-31 19:53:01 +02:00
|
|
|
-record(candidate, {low_sqn :: integer() | undefined,
|
|
|
|
filename :: string() | undefined,
|
|
|
|
journal :: pid() | undefined,
|
|
|
|
compaction_perc :: float() | undefined}).
|
2016-09-20 16:13:36 +01:00
|
|
|
|
2020-11-29 15:43:29 +00:00
|
|
|
-record(scoring_state, {filter_fun :: leveled_inker:filterfun(),
|
|
|
|
filter_server :: leveled_inker:filterserver(),
|
2019-01-25 12:11:42 +00:00
|
|
|
max_sqn :: non_neg_integer(),
|
2020-11-29 15:43:29 +00:00
|
|
|
close_fun :: leveled_inker:filterclosefun(),
|
2019-01-25 12:11:42 +00:00
|
|
|
start_time :: erlang:timestamp()}).
|
|
|
|
|
2017-11-09 12:42:49 +00:00
|
|
|
-type iclerk_options() :: #iclerk_options{}.
|
2018-09-26 14:07:44 +01:00
|
|
|
-type candidate() :: #candidate{}.
|
2019-01-25 12:11:42 +00:00
|
|
|
-type scoring_state() :: #scoring_state{}.
|
2018-09-26 14:07:44 +01:00
|
|
|
-type score_parameters() :: {integer(), float(), float()}.
|
|
|
|
% Score parameters are a tuple
|
|
|
|
% - of maximum run length; how long a run of consecutive files can be for
|
|
|
|
% one compaction run
|
|
|
|
% - maximum run compaction target; percentage space which should be
|
|
|
|
% released from a compaction run of the maximum length to make it a run
|
|
|
|
% worthwhile of compaction (released space is 100.0 - target e.g. 70.0
|
|
|
|
% means that 30.0% should be released)
|
|
|
|
% - single_file compaction target; percentage space which should be
|
|
|
|
% released from a compaction run of a single file to make it a run
|
|
|
|
% worthwhile of compaction (released space is 100.0 - target e.g. 70.0
|
|
|
|
% means that 30.0% should be released)
|
2020-03-15 22:14:42 +00:00
|
|
|
-type key_size() ::
|
|
|
|
{{non_neg_integer(),
|
|
|
|
leveled_codec:journal_key_tag(),
|
|
|
|
leveled_codec:ledger_key()}, non_neg_integer()}.
|
|
|
|
-type corrupted_test_key_size() ::
|
|
|
|
{{non_neg_integer(),
|
|
|
|
leveled_codec:journal_key_tag(),
|
|
|
|
leveled_codec:ledger_key(),
|
|
|
|
null}, non_neg_integer()}.
|
2016-09-20 16:13:36 +01:00
|
|
|
|
|
|
|
%%%============================================================================
|
|
|
|
%%% API
|
|
|
|
%%%============================================================================
|
|
|
|
|
2017-11-09 12:42:49 +00:00
|
|
|
-spec clerk_new(iclerk_options()) -> {ok, pid()}.
|
|
|
|
%% @doc
|
|
|
|
%% Generate a new clerk
|
2016-09-27 14:58:26 +01:00
|
|
|
clerk_new(InkerClerkOpts) ->
|
2018-12-10 16:09:11 +01:00
|
|
|
gen_server:start_link(?MODULE, [leveled_log:get_opts(), InkerClerkOpts], []).
|
2017-11-09 12:42:49 +00:00
|
|
|
|
2020-11-29 15:43:29 +00:00
|
|
|
-spec clerk_compact(pid(),
|
|
|
|
pid(),
|
|
|
|
leveled_inker:filterinitfun(),
|
|
|
|
leveled_inker:filterclosefun(),
|
|
|
|
leveled_inker:filterfun(),
|
2019-01-24 21:32:54 +00:00
|
|
|
list()) -> ok.
|
2017-11-09 12:42:49 +00:00
|
|
|
%% @doc
|
|
|
|
%% Trigger a compaction for this clerk if the threshold of data recovery has
|
|
|
|
%% been met
|
2019-01-24 21:32:54 +00:00
|
|
|
clerk_compact(Pid, Checker, InitiateFun, CloseFun, FilterFun, Manifest) ->
|
2016-09-28 18:26:52 +01:00
|
|
|
gen_server:cast(Pid,
|
|
|
|
{compact,
|
|
|
|
Checker,
|
|
|
|
InitiateFun,
|
2017-05-26 10:51:30 +01:00
|
|
|
CloseFun,
|
2016-09-28 18:26:52 +01:00
|
|
|
FilterFun,
|
2019-01-24 21:32:54 +00:00
|
|
|
Manifest}).
|
2016-09-26 10:55:08 +01:00
|
|
|
|
2019-01-24 21:32:54 +00:00
|
|
|
-spec clerk_trim(pid(), integer(), list()) -> ok.
|
2018-02-15 16:14:46 +00:00
|
|
|
%% @doc
|
|
|
|
%% Trim the Inker back to the persisted SQN
|
2019-01-24 21:32:54 +00:00
|
|
|
clerk_trim(Pid, PersistedSQN, ManifestAsList) ->
|
|
|
|
gen_server:cast(Pid, {trim, PersistedSQN, ManifestAsList}).
|
|
|
|
|
2017-11-09 12:42:49 +00:00
|
|
|
-spec clerk_hashtablecalc(ets:tid(), integer(), pid()) -> ok.
|
|
|
|
%% @doc
|
|
|
|
%% Spawn a dedicated clerk for the process of calculating the binary view
|
|
|
|
%% of the hastable in the CDB file - so that the file is not blocked during
|
|
|
|
%% this calculation
|
2016-10-14 13:36:12 +01:00
|
|
|
clerk_hashtablecalc(HashTree, StartPos, CDBpid) ->
|
2018-12-10 16:09:11 +01:00
|
|
|
{ok, Clerk} = gen_server:start_link(?MODULE, [leveled_log:get_opts(),
|
|
|
|
#iclerk_options{}], []),
|
2016-10-14 13:36:12 +01:00
|
|
|
gen_server:cast(Clerk, {hashtable_calc, HashTree, StartPos, CDBpid}).
|
|
|
|
|
2017-11-09 12:42:49 +00:00
|
|
|
-spec clerk_stop(pid()) -> ok.
|
|
|
|
%% @doc
|
|
|
|
%% Stop the clerk
|
2016-09-20 16:13:36 +01:00
|
|
|
clerk_stop(Pid) ->
|
2019-01-25 12:11:42 +00:00
|
|
|
gen_server:call(Pid, stop, infinity).
|
2016-09-20 16:13:36 +01:00
|
|
|
|
2018-12-11 21:59:57 +00:00
|
|
|
-spec clerk_loglevel(pid(), leveled_log:log_level()) -> ok.
|
|
|
|
%% @doc
|
|
|
|
%% Change the log level of the Journal
|
|
|
|
clerk_loglevel(Pid, LogLevel) ->
|
|
|
|
gen_server:cast(Pid, {log_level, LogLevel}).
|
|
|
|
|
|
|
|
-spec clerk_addlogs(pid(), list(string())) -> ok.
|
|
|
|
%% @doc
|
|
|
|
%% Add to the list of forced logs, a list of more forced logs
|
|
|
|
clerk_addlogs(Pid, ForcedLogs) ->
|
|
|
|
gen_server:cast(Pid, {add_logs, ForcedLogs}).
|
|
|
|
|
|
|
|
-spec clerk_removelogs(pid(), list(string())) -> ok.
|
|
|
|
%% @doc
|
|
|
|
%% Remove from the list of forced logs, a list of forced logs
|
|
|
|
clerk_removelogs(Pid, ForcedLogs) ->
|
|
|
|
gen_server:cast(Pid, {remove_logs, ForcedLogs}).
|
|
|
|
|
2019-01-25 12:11:42 +00:00
|
|
|
|
|
|
|
-spec clerk_scorefilelist(pid(), list(candidate())) -> ok.
|
|
|
|
%% @doc
|
|
|
|
%% Score the file at the head of the list and then send the tail of the list to
|
|
|
|
%% be scored
|
|
|
|
clerk_scorefilelist(Pid, []) ->
|
|
|
|
gen_server:cast(Pid, scoring_complete);
|
|
|
|
clerk_scorefilelist(Pid, CandidateList) ->
|
|
|
|
gen_server:cast(Pid, {score_filelist, CandidateList}).
|
|
|
|
|
2019-01-25 14:32:41 +00:00
|
|
|
|
2016-09-20 16:13:36 +01:00
|
|
|
%%%============================================================================
|
|
|
|
%%% gen_server callbacks
|
|
|
|
%%%============================================================================
|
|
|
|
|
2018-12-10 16:09:11 +01:00
|
|
|
init([LogOpts, IClerkOpts]) ->
|
|
|
|
leveled_log:save(LogOpts),
|
2016-10-25 23:13:14 +01:00
|
|
|
ReloadStrategy = IClerkOpts#iclerk_options.reload_strategy,
|
2016-11-14 11:17:14 +00:00
|
|
|
CDBopts = IClerkOpts#iclerk_options.cdb_options,
|
|
|
|
WP = CDBopts#cdb_options.waste_path,
|
2017-11-08 12:58:09 +00:00
|
|
|
WRP = IClerkOpts#iclerk_options.waste_retention_period,
|
|
|
|
|
|
|
|
MRL =
|
|
|
|
case IClerkOpts#iclerk_options.max_run_length of
|
|
|
|
undefined ->
|
|
|
|
?MAX_COMPACTION_RUN;
|
|
|
|
MRL0 ->
|
|
|
|
MRL0
|
|
|
|
end,
|
2018-07-23 12:46:42 +01:00
|
|
|
|
|
|
|
SFL_CompPerc =
|
|
|
|
case IClerkOpts#iclerk_options.singlefile_compactionperc of
|
|
|
|
undefined ->
|
|
|
|
?SINGLEFILE_COMPACTION_TARGET;
|
|
|
|
SFLCP when is_float(SFLCP) ->
|
|
|
|
SFLCP
|
|
|
|
end,
|
|
|
|
MRL_CompPerc =
|
|
|
|
case IClerkOpts#iclerk_options.maxrunlength_compactionperc of
|
|
|
|
undefined ->
|
|
|
|
?MAXRUNLENGTH_COMPACTION_TARGET;
|
|
|
|
MRLCP when is_float(MRLCP) ->
|
|
|
|
MRLCP
|
|
|
|
end,
|
2020-11-27 02:35:27 +00:00
|
|
|
|
2016-11-14 11:17:14 +00:00
|
|
|
{ok, #state{max_run_length = MRL,
|
2016-09-27 14:58:26 +01:00
|
|
|
inker = IClerkOpts#iclerk_options.inker,
|
2016-11-14 11:17:14 +00:00
|
|
|
cdb_options = CDBopts,
|
|
|
|
reload_strategy = ReloadStrategy,
|
|
|
|
waste_path = WP,
|
2017-11-06 15:54:58 +00:00
|
|
|
waste_retention_period = WRP,
|
2018-07-23 12:46:42 +01:00
|
|
|
singlefile_compactionperc = SFL_CompPerc,
|
|
|
|
maxrunlength_compactionperc = MRL_CompPerc,
|
2017-11-06 15:54:58 +00:00
|
|
|
compression_method =
|
2020-11-27 02:35:27 +00:00
|
|
|
IClerkOpts#iclerk_options.compression_method,
|
|
|
|
score_onein =
|
|
|
|
IClerkOpts#iclerk_options.score_onein
|
|
|
|
}}.
|
2016-09-20 16:13:36 +01:00
|
|
|
|
2019-01-24 21:32:54 +00:00
|
|
|
handle_call(stop, _From, State) ->
|
2019-01-25 12:11:42 +00:00
|
|
|
case State#state.scoring_state of
|
|
|
|
undefined ->
|
|
|
|
ok;
|
|
|
|
ScoringState ->
|
|
|
|
% Closed when scoring files, and so need to shutdown FilterServer
|
|
|
|
% to close down neatly
|
|
|
|
CloseFun = ScoringState#scoring_state.close_fun,
|
|
|
|
FilterServer = ScoringState#scoring_state.filter_server,
|
|
|
|
CloseFun(FilterServer)
|
|
|
|
end,
|
2019-01-24 21:32:54 +00:00
|
|
|
{stop, normal, ok, State}.
|
2016-09-20 16:13:36 +01:00
|
|
|
|
2019-01-24 21:32:54 +00:00
|
|
|
handle_cast({compact, Checker, InitiateFun, CloseFun, FilterFun, Manifest0},
|
2016-09-28 18:26:52 +01:00
|
|
|
State) ->
|
Develop 3.1 d30update (#386)
* Mas i370 patch d (#383)
* Refactor penciller memory
In high-volume tests on large key-count clusters, so significant variation in the P0031 time has been seen:
TimeBucket PatchA
a.0ms_to_1ms 18554
b.1ms_to_2ms 51778
c.2ms_to_3ms 696
d.3ms_to_5ms 220
e.5ms_to_8ms 59
f.8ms_to_13ms 40
g.13ms_to_21ms 364
h.21ms_to_34ms 277
i.34ms_to_55ms 34
j.55ms_to_89ms 17
k.89ms_to_144ms 21
l.144ms_to_233ms 31
m.233ms_to_377ms 45
n.377ms_to_610ms 52
o.610ms_to_987ms 59
p.987ms_to_1597ms 55
q.1597ms_to_2684ms 54
r.2684ms_to_4281ms 29
s.4281ms_to_6965ms 7
t.6295ms_to_11246ms 1
It is unclear why this varies so much. The time to add to the cache appears to be minimal (but perhaps there is an issue with timing points in the code), whereas the time to add to the index is much more significant and variable. There is also variable time when the memory is rolled (although the actual activity here appears to be minimal.
The refactoring here is two-fold:
- tidy and simplify by keeping LoopState managed within handle_call, and add more helpful dialyzer specs;
- change the update to the index to be a simple extension of a list, rather than any conversion.
This alternative version of the pmem index in unit test is orders of magnitude faster to add - and is the same order of magnitude to check. Anticipation is that it may be more efficient in terms of memory changes.
* Compress SST index
Reduces the size of the leveled_sst index with two changes:
1 - Where there is a common prefix of tuple elements (e.g. Bucket) across the whole leveled_sst file - only the non-common part is indexed, and a function is used to compare.
2 - There is less "indexing" of the index i.e. only 1 in 16 keys are passed into the gb_trees part instead of 1 in 4
* Immediate hibernate
Reasons for delay in hibernate were not clear.
Straight after creation the process will not be in receipt of messages (must wait for the manifest to be updated), so better to hibernate now. This also means the log PC023 provides more accurate information.
* Refactor BIC
This patch avoids the following:
- repeated replacement of the same element in the BIC (via get_kvrange), by checking presence via GET before sing SET
- Stops re-reading of all elements to discover high modified date
Also there appears to have been a bug where a missing HMD for the file is required to add to the cache. However, now the cache may be erased without erasing the HMD. This means that the cache can never be rebuilt
* Use correct size in test results
erts_debug:flat_size/1 returns size in words (i.e. 8 bytes on 64-bit CPU) not bytes
* Don't change summary record
As it is persisted as part of the file write, any change to the summary record cannot be rolled back
* Clerk to prompt L0 write
Simplifies the logic if the clerk request work for the penciller prompts L0 writes as well as Manifest changes.
The advantage now is that if the penciller memory is full, and PUT load stops, the clerk should still be able to prompt persistence. the penciller can therefore make use of dead time this way
* Add push on journal compact
If there has been a backlog, followed by a quiet period - there may be a large ledger cache left unpushed. Journal compaction events are about once per hour, so the performance overhead of a false push should be minimal, with the advantage of clearing any backlog before load starts again.
This is only relevant to riak users with very off/full batch type workloads.
* Extend tests
To more consistently trigger all overload scenarios
* Fix range keys smaller than prefix
Can't make end key an empty binary in this case, as it may be bigger than any keys within the range, but will appear to be smaller.
Unit tests and ct tests added to expose the potential issue
* Tidy-up
- Remove penciller logs which are no longer called
- Get pclerk to only wait MIN_TIMEOUT after doing work, in case there is a backlog
- Remove update_levelzero_cache function as it is unique to handle_call of push_mem, and simple enough to be inline
- Alight testutil slow offer with standard slow offer used
* Tidy-up
Remove pre-otp20 references.
Reinstate the check that the starting pid is still active, this was added to tidy up shutdown.
Resolve failure to run on otp20 due to `-if` sttaement
* Tidy up
Using null rather then {null, Key} is potentially clearer as it is not a concern what they Key is in this case, and removes a comparison step from the leveled_codec:endkey_passed/2 function.
There were issues with coverage in eunit tests as the leveled_pclerk shut down. This prompted a general tidy of leveled_pclerk (remove passing of LoopState into internal functions, and add dialyzer specs.
* Remove R16 relic
* Further testing another issue
The StartKey must always be less than or equal to the prefix when the first N characters are stripped, but this is not true of the EndKey (for the query) which does not have to be between the FirstKey and the LastKey.
If the EndKey query does not match it must be greater than the Prefix (as otherwise it would not have been greater than the FirstKey - so set to null.
* Fix unit test
Unit test had a typo - and result interpretation had a misunderstanding.
* Code and spec tidy
Also look to the cover the situation when the FirstKey is the same as the Prefix with tests.
This is, in theory, not an issue as it is the EndKey for each sublist which is indexed in leveled_tree. However, guard against it mapping to null here, just in case there are dangers lurking (note that tests will still pass without `M > N` guard in place.
* Hibernate on BIC complete
There are three situations when the BIC becomes complete:
- In a file created as part of a merge the BIS is learned in the merge
- After startup, files below L1 learn the block cache through reads that happen to read the block, eventually the while cache will be read, unless...
- Either before/after the cache is complete, it can get whiped by a timeout after a get_sqn request (e.g. as prompted by a journal compaction) ... it will then be re-filled of the back of get/get-range requests.
In all these situations we want to hibernate after the BIC is fill - to reflect the fact that the LoopState should now be relatively stable, so it is a good point to GC and rationalise location of data.
Previously on the the first base was covered. Now all three are covered through the bic_complete message.
* Test all index keys have same term
This works functionally, but is not optimised (the term is replicated in the index)
* Summaries with same index term
If the summary index all have the same index term - only the object keys need to be indexes
* Simplify case statements
We either match the pattern of <<Prefix:N, Suffix>> or the answer should be null
* OK for M == N
If M = N for the first key, it will have a suffix of <<>>. This will match (as expected) a query Start Key of the sam size, and be smaller than any query Start Key that has the same prefix.
If the query Start Key does not match the prefix - it will be null - as it must be smaller than the Prefix (as other wise the query Start Key would be bigger than the Last Key).
The constraint of M > N was introduced before the *_prefix_filter functions were checking the prefix, to avoid issues. Now the prefix is being checked, then M == N is ok.
* Simplify
Correct the test to use a binary field in the range.
To avoid further issue, only apply filter when everything is a binary() type.
* Add test for head_only mode
When leveled is used as a tictacaae key store (in parallel mode), the keys will be head_only entries. Double check they are handled as expected like object keys
* Revert previous change - must support typed buckets
Add assertion to confirm worthwhile optimisation
* Add support for configurable cache multiple (#375)
* Mas i370 patch e (#385)
Improvement to monitoring for efficiency and improved readability of logs and stats.
As part of this, where possible, tried to avoid updating loop state on READ messages in leveled processes (as was the case when tracking stats within each process).
No performance benefits found with change, but improved stats has helped discover other potential gains.
2022-12-18 20:18:03 +00:00
|
|
|
leveled_log:log(ic014, [State#state.reload_strategy,
|
2020-03-23 16:45:28 +00:00
|
|
|
State#state.max_run_length]),
|
2016-11-14 11:17:14 +00:00
|
|
|
% Empty the waste folder
|
|
|
|
clear_waste(State),
|
2018-09-26 10:19:24 +01:00
|
|
|
SW = os:timestamp(),
|
|
|
|
% Clock to record the time it takes to calculate the potential for
|
|
|
|
% compaction
|
|
|
|
|
2016-09-27 14:58:26 +01:00
|
|
|
% Need to fetch manifest at start rather than have it be passed in
|
|
|
|
% Don't want to process a queued call waiting on an old manifest
|
2019-01-24 21:32:54 +00:00
|
|
|
[_Active|Manifest] = Manifest0,
|
2016-10-05 18:28:31 +01:00
|
|
|
{FilterServer, MaxSQN} = InitiateFun(Checker),
|
2020-03-16 21:41:47 +00:00
|
|
|
NotRollingFun =
|
|
|
|
fun({_LowSQN, _FN, Pid, _LK}) ->
|
|
|
|
not leveled_cdb:cdb_isrolling(Pid)
|
|
|
|
end,
|
|
|
|
ok = clerk_scorefilelist(self(), lists:filter(NotRollingFun, Manifest)),
|
2019-01-25 12:11:42 +00:00
|
|
|
ScoringState =
|
|
|
|
#scoring_state{filter_fun = FilterFun,
|
|
|
|
filter_server = FilterServer,
|
|
|
|
max_sqn = MaxSQN,
|
|
|
|
close_fun = CloseFun,
|
|
|
|
start_time = SW},
|
|
|
|
{noreply, State#state{scored_files = [], scoring_state = ScoringState}};
|
|
|
|
handle_cast({score_filelist, [Entry|Tail]}, State) ->
|
|
|
|
Candidates = State#state.scored_files,
|
|
|
|
{LowSQN, FN, JournalP, _LK} = Entry,
|
|
|
|
ScoringState = State#state.scoring_state,
|
2020-11-27 02:35:27 +00:00
|
|
|
CpctPerc =
|
2020-11-27 13:56:47 +00:00
|
|
|
case {leveled_cdb:cdb_getcachedscore(JournalP, os:timestamp()),
|
2020-11-27 20:03:44 +00:00
|
|
|
leveled_rand:uniform(State#state.score_onein) == 1,
|
|
|
|
State#state.score_onein} of
|
|
|
|
{CachedScore, _UseNewScore, ScoreOneIn}
|
|
|
|
when CachedScore == undefined; ScoreOneIn == 1 ->
|
|
|
|
% If caches are not used, always use the current score
|
2020-11-27 02:35:27 +00:00
|
|
|
check_single_file(JournalP,
|
2019-01-25 12:11:42 +00:00
|
|
|
ScoringState#scoring_state.filter_fun,
|
|
|
|
ScoringState#scoring_state.filter_server,
|
|
|
|
ScoringState#scoring_state.max_sqn,
|
|
|
|
?SAMPLE_SIZE,
|
2020-03-15 22:14:42 +00:00
|
|
|
?BATCH_SIZE,
|
2020-11-27 02:35:27 +00:00
|
|
|
State#state.reload_strategy);
|
2020-11-27 20:03:44 +00:00
|
|
|
{CachedScore, true, _ScoreOneIn} ->
|
|
|
|
% If caches are used roll the score towards the current score
|
|
|
|
% Expectation is that this will reduce instances of individual
|
|
|
|
% files being compacted when a run is missed due to cached
|
|
|
|
% scores being used in surrounding journals
|
|
|
|
NewScore =
|
|
|
|
check_single_file(JournalP,
|
|
|
|
ScoringState#scoring_state.filter_fun,
|
|
|
|
ScoringState#scoring_state.filter_server,
|
|
|
|
ScoringState#scoring_state.max_sqn,
|
|
|
|
?SAMPLE_SIZE,
|
|
|
|
?BATCH_SIZE,
|
|
|
|
State#state.reload_strategy),
|
|
|
|
(NewScore + CachedScore) / 2;
|
|
|
|
{CachedScore, false, _ScoreOneIn} ->
|
2020-11-27 02:35:27 +00:00
|
|
|
CachedScore
|
|
|
|
end,
|
|
|
|
ok = leveled_cdb:cdb_putcachedscore(JournalP, CpctPerc),
|
2019-01-25 12:11:42 +00:00
|
|
|
Candidate =
|
|
|
|
#candidate{low_sqn = LowSQN,
|
|
|
|
filename = FN,
|
|
|
|
journal = JournalP,
|
|
|
|
compaction_perc = CpctPerc},
|
|
|
|
ok = clerk_scorefilelist(self(), Tail),
|
|
|
|
{noreply, State#state{scored_files = [Candidate|Candidates]}};
|
|
|
|
handle_cast(scoring_complete, State) ->
|
|
|
|
MaxRunLength = State#state.max_run_length,
|
2016-09-28 11:41:56 +01:00
|
|
|
CDBopts = State#state.cdb_options,
|
2019-01-25 12:11:42 +00:00
|
|
|
Candidates = lists:reverse(State#state.scored_files),
|
|
|
|
ScoringState = State#state.scoring_state,
|
|
|
|
FilterFun = ScoringState#scoring_state.filter_fun,
|
|
|
|
FilterServer = ScoringState#scoring_state.filter_server,
|
|
|
|
MaxSQN = ScoringState#scoring_state.max_sqn,
|
|
|
|
CloseFun = ScoringState#scoring_state.close_fun,
|
|
|
|
SW = ScoringState#scoring_state.start_time,
|
2018-07-23 12:46:42 +01:00
|
|
|
ScoreParams =
|
|
|
|
{MaxRunLength,
|
|
|
|
State#state.maxrunlength_compactionperc,
|
|
|
|
State#state.singlefile_compactionperc},
|
2018-09-26 12:56:28 +01:00
|
|
|
{BestRun0, Score} = assess_candidates(Candidates, ScoreParams),
|
Develop 3.1 d30update (#386)
* Mas i370 patch d (#383)
* Refactor penciller memory
In high-volume tests on large key-count clusters, so significant variation in the P0031 time has been seen:
TimeBucket PatchA
a.0ms_to_1ms 18554
b.1ms_to_2ms 51778
c.2ms_to_3ms 696
d.3ms_to_5ms 220
e.5ms_to_8ms 59
f.8ms_to_13ms 40
g.13ms_to_21ms 364
h.21ms_to_34ms 277
i.34ms_to_55ms 34
j.55ms_to_89ms 17
k.89ms_to_144ms 21
l.144ms_to_233ms 31
m.233ms_to_377ms 45
n.377ms_to_610ms 52
o.610ms_to_987ms 59
p.987ms_to_1597ms 55
q.1597ms_to_2684ms 54
r.2684ms_to_4281ms 29
s.4281ms_to_6965ms 7
t.6295ms_to_11246ms 1
It is unclear why this varies so much. The time to add to the cache appears to be minimal (but perhaps there is an issue with timing points in the code), whereas the time to add to the index is much more significant and variable. There is also variable time when the memory is rolled (although the actual activity here appears to be minimal.
The refactoring here is two-fold:
- tidy and simplify by keeping LoopState managed within handle_call, and add more helpful dialyzer specs;
- change the update to the index to be a simple extension of a list, rather than any conversion.
This alternative version of the pmem index in unit test is orders of magnitude faster to add - and is the same order of magnitude to check. Anticipation is that it may be more efficient in terms of memory changes.
* Compress SST index
Reduces the size of the leveled_sst index with two changes:
1 - Where there is a common prefix of tuple elements (e.g. Bucket) across the whole leveled_sst file - only the non-common part is indexed, and a function is used to compare.
2 - There is less "indexing" of the index i.e. only 1 in 16 keys are passed into the gb_trees part instead of 1 in 4
* Immediate hibernate
Reasons for delay in hibernate were not clear.
Straight after creation the process will not be in receipt of messages (must wait for the manifest to be updated), so better to hibernate now. This also means the log PC023 provides more accurate information.
* Refactor BIC
This patch avoids the following:
- repeated replacement of the same element in the BIC (via get_kvrange), by checking presence via GET before sing SET
- Stops re-reading of all elements to discover high modified date
Also there appears to have been a bug where a missing HMD for the file is required to add to the cache. However, now the cache may be erased without erasing the HMD. This means that the cache can never be rebuilt
* Use correct size in test results
erts_debug:flat_size/1 returns size in words (i.e. 8 bytes on 64-bit CPU) not bytes
* Don't change summary record
As it is persisted as part of the file write, any change to the summary record cannot be rolled back
* Clerk to prompt L0 write
Simplifies the logic if the clerk request work for the penciller prompts L0 writes as well as Manifest changes.
The advantage now is that if the penciller memory is full, and PUT load stops, the clerk should still be able to prompt persistence. the penciller can therefore make use of dead time this way
* Add push on journal compact
If there has been a backlog, followed by a quiet period - there may be a large ledger cache left unpushed. Journal compaction events are about once per hour, so the performance overhead of a false push should be minimal, with the advantage of clearing any backlog before load starts again.
This is only relevant to riak users with very off/full batch type workloads.
* Extend tests
To more consistently trigger all overload scenarios
* Fix range keys smaller than prefix
Can't make end key an empty binary in this case, as it may be bigger than any keys within the range, but will appear to be smaller.
Unit tests and ct tests added to expose the potential issue
* Tidy-up
- Remove penciller logs which are no longer called
- Get pclerk to only wait MIN_TIMEOUT after doing work, in case there is a backlog
- Remove update_levelzero_cache function as it is unique to handle_call of push_mem, and simple enough to be inline
- Alight testutil slow offer with standard slow offer used
* Tidy-up
Remove pre-otp20 references.
Reinstate the check that the starting pid is still active, this was added to tidy up shutdown.
Resolve failure to run on otp20 due to `-if` sttaement
* Tidy up
Using null rather then {null, Key} is potentially clearer as it is not a concern what they Key is in this case, and removes a comparison step from the leveled_codec:endkey_passed/2 function.
There were issues with coverage in eunit tests as the leveled_pclerk shut down. This prompted a general tidy of leveled_pclerk (remove passing of LoopState into internal functions, and add dialyzer specs.
* Remove R16 relic
* Further testing another issue
The StartKey must always be less than or equal to the prefix when the first N characters are stripped, but this is not true of the EndKey (for the query) which does not have to be between the FirstKey and the LastKey.
If the EndKey query does not match it must be greater than the Prefix (as otherwise it would not have been greater than the FirstKey - so set to null.
* Fix unit test
Unit test had a typo - and result interpretation had a misunderstanding.
* Code and spec tidy
Also look to the cover the situation when the FirstKey is the same as the Prefix with tests.
This is, in theory, not an issue as it is the EndKey for each sublist which is indexed in leveled_tree. However, guard against it mapping to null here, just in case there are dangers lurking (note that tests will still pass without `M > N` guard in place.
* Hibernate on BIC complete
There are three situations when the BIC becomes complete:
- In a file created as part of a merge the BIS is learned in the merge
- After startup, files below L1 learn the block cache through reads that happen to read the block, eventually the while cache will be read, unless...
- Either before/after the cache is complete, it can get whiped by a timeout after a get_sqn request (e.g. as prompted by a journal compaction) ... it will then be re-filled of the back of get/get-range requests.
In all these situations we want to hibernate after the BIC is fill - to reflect the fact that the LoopState should now be relatively stable, so it is a good point to GC and rationalise location of data.
Previously on the the first base was covered. Now all three are covered through the bic_complete message.
* Test all index keys have same term
This works functionally, but is not optimised (the term is replicated in the index)
* Summaries with same index term
If the summary index all have the same index term - only the object keys need to be indexes
* Simplify case statements
We either match the pattern of <<Prefix:N, Suffix>> or the answer should be null
* OK for M == N
If M = N for the first key, it will have a suffix of <<>>. This will match (as expected) a query Start Key of the sam size, and be smaller than any query Start Key that has the same prefix.
If the query Start Key does not match the prefix - it will be null - as it must be smaller than the Prefix (as other wise the query Start Key would be bigger than the Last Key).
The constraint of M > N was introduced before the *_prefix_filter functions were checking the prefix, to avoid issues. Now the prefix is being checked, then M == N is ok.
* Simplify
Correct the test to use a binary field in the range.
To avoid further issue, only apply filter when everything is a binary() type.
* Add test for head_only mode
When leveled is used as a tictacaae key store (in parallel mode), the keys will be head_only entries. Double check they are handled as expected like object keys
* Revert previous change - must support typed buckets
Add assertion to confirm worthwhile optimisation
* Add support for configurable cache multiple (#375)
* Mas i370 patch e (#385)
Improvement to monitoring for efficiency and improved readability of logs and stats.
As part of this, where possible, tried to avoid updating loop state on READ messages in leveled processes (as was the case when tracking stats within each process).
No performance benefits found with change, but improved stats has helped discover other potential gains.
2022-12-18 20:18:03 +00:00
|
|
|
leveled_log:log_timer(ic003, [Score, length(BestRun0)], SW),
|
2018-09-26 12:56:28 +01:00
|
|
|
case Score > 0.0 of
|
|
|
|
true ->
|
2016-10-27 00:57:19 +01:00
|
|
|
BestRun1 = sort_run(BestRun0),
|
2018-07-23 12:46:42 +01:00
|
|
|
print_compaction_run(BestRun1, ScoreParams),
|
2016-11-14 11:40:02 +00:00
|
|
|
ManifestSlice = compact_files(BestRun1,
|
|
|
|
CDBopts,
|
|
|
|
FilterFun,
|
|
|
|
FilterServer,
|
|
|
|
MaxSQN,
|
2017-11-06 21:16:46 +00:00
|
|
|
State#state.reload_strategy,
|
|
|
|
State#state.compression_method),
|
2016-09-27 14:58:26 +01:00
|
|
|
FilesToDelete = lists:map(fun(C) ->
|
|
|
|
{C#candidate.low_sqn,
|
|
|
|
C#candidate.filename,
|
2017-01-18 15:23:06 +00:00
|
|
|
C#candidate.journal,
|
|
|
|
undefined}
|
2016-09-27 14:58:26 +01:00
|
|
|
end,
|
2016-10-27 00:57:19 +01:00
|
|
|
BestRun1),
|
Develop 3.1 d30update (#386)
* Mas i370 patch d (#383)
* Refactor penciller memory
In high-volume tests on large key-count clusters, so significant variation in the P0031 time has been seen:
TimeBucket PatchA
a.0ms_to_1ms 18554
b.1ms_to_2ms 51778
c.2ms_to_3ms 696
d.3ms_to_5ms 220
e.5ms_to_8ms 59
f.8ms_to_13ms 40
g.13ms_to_21ms 364
h.21ms_to_34ms 277
i.34ms_to_55ms 34
j.55ms_to_89ms 17
k.89ms_to_144ms 21
l.144ms_to_233ms 31
m.233ms_to_377ms 45
n.377ms_to_610ms 52
o.610ms_to_987ms 59
p.987ms_to_1597ms 55
q.1597ms_to_2684ms 54
r.2684ms_to_4281ms 29
s.4281ms_to_6965ms 7
t.6295ms_to_11246ms 1
It is unclear why this varies so much. The time to add to the cache appears to be minimal (but perhaps there is an issue with timing points in the code), whereas the time to add to the index is much more significant and variable. There is also variable time when the memory is rolled (although the actual activity here appears to be minimal.
The refactoring here is two-fold:
- tidy and simplify by keeping LoopState managed within handle_call, and add more helpful dialyzer specs;
- change the update to the index to be a simple extension of a list, rather than any conversion.
This alternative version of the pmem index in unit test is orders of magnitude faster to add - and is the same order of magnitude to check. Anticipation is that it may be more efficient in terms of memory changes.
* Compress SST index
Reduces the size of the leveled_sst index with two changes:
1 - Where there is a common prefix of tuple elements (e.g. Bucket) across the whole leveled_sst file - only the non-common part is indexed, and a function is used to compare.
2 - There is less "indexing" of the index i.e. only 1 in 16 keys are passed into the gb_trees part instead of 1 in 4
* Immediate hibernate
Reasons for delay in hibernate were not clear.
Straight after creation the process will not be in receipt of messages (must wait for the manifest to be updated), so better to hibernate now. This also means the log PC023 provides more accurate information.
* Refactor BIC
This patch avoids the following:
- repeated replacement of the same element in the BIC (via get_kvrange), by checking presence via GET before sing SET
- Stops re-reading of all elements to discover high modified date
Also there appears to have been a bug where a missing HMD for the file is required to add to the cache. However, now the cache may be erased without erasing the HMD. This means that the cache can never be rebuilt
* Use correct size in test results
erts_debug:flat_size/1 returns size in words (i.e. 8 bytes on 64-bit CPU) not bytes
* Don't change summary record
As it is persisted as part of the file write, any change to the summary record cannot be rolled back
* Clerk to prompt L0 write
Simplifies the logic if the clerk request work for the penciller prompts L0 writes as well as Manifest changes.
The advantage now is that if the penciller memory is full, and PUT load stops, the clerk should still be able to prompt persistence. the penciller can therefore make use of dead time this way
* Add push on journal compact
If there has been a backlog, followed by a quiet period - there may be a large ledger cache left unpushed. Journal compaction events are about once per hour, so the performance overhead of a false push should be minimal, with the advantage of clearing any backlog before load starts again.
This is only relevant to riak users with very off/full batch type workloads.
* Extend tests
To more consistently trigger all overload scenarios
* Fix range keys smaller than prefix
Can't make end key an empty binary in this case, as it may be bigger than any keys within the range, but will appear to be smaller.
Unit tests and ct tests added to expose the potential issue
* Tidy-up
- Remove penciller logs which are no longer called
- Get pclerk to only wait MIN_TIMEOUT after doing work, in case there is a backlog
- Remove update_levelzero_cache function as it is unique to handle_call of push_mem, and simple enough to be inline
- Alight testutil slow offer with standard slow offer used
* Tidy-up
Remove pre-otp20 references.
Reinstate the check that the starting pid is still active, this was added to tidy up shutdown.
Resolve failure to run on otp20 due to `-if` sttaement
* Tidy up
Using null rather then {null, Key} is potentially clearer as it is not a concern what they Key is in this case, and removes a comparison step from the leveled_codec:endkey_passed/2 function.
There were issues with coverage in eunit tests as the leveled_pclerk shut down. This prompted a general tidy of leveled_pclerk (remove passing of LoopState into internal functions, and add dialyzer specs.
* Remove R16 relic
* Further testing another issue
The StartKey must always be less than or equal to the prefix when the first N characters are stripped, but this is not true of the EndKey (for the query) which does not have to be between the FirstKey and the LastKey.
If the EndKey query does not match it must be greater than the Prefix (as otherwise it would not have been greater than the FirstKey - so set to null.
* Fix unit test
Unit test had a typo - and result interpretation had a misunderstanding.
* Code and spec tidy
Also look to the cover the situation when the FirstKey is the same as the Prefix with tests.
This is, in theory, not an issue as it is the EndKey for each sublist which is indexed in leveled_tree. However, guard against it mapping to null here, just in case there are dangers lurking (note that tests will still pass without `M > N` guard in place.
* Hibernate on BIC complete
There are three situations when the BIC becomes complete:
- In a file created as part of a merge the BIS is learned in the merge
- After startup, files below L1 learn the block cache through reads that happen to read the block, eventually the while cache will be read, unless...
- Either before/after the cache is complete, it can get whiped by a timeout after a get_sqn request (e.g. as prompted by a journal compaction) ... it will then be re-filled of the back of get/get-range requests.
In all these situations we want to hibernate after the BIC is fill - to reflect the fact that the LoopState should now be relatively stable, so it is a good point to GC and rationalise location of data.
Previously on the the first base was covered. Now all three are covered through the bic_complete message.
* Test all index keys have same term
This works functionally, but is not optimised (the term is replicated in the index)
* Summaries with same index term
If the summary index all have the same index term - only the object keys need to be indexes
* Simplify case statements
We either match the pattern of <<Prefix:N, Suffix>> or the answer should be null
* OK for M == N
If M = N for the first key, it will have a suffix of <<>>. This will match (as expected) a query Start Key of the sam size, and be smaller than any query Start Key that has the same prefix.
If the query Start Key does not match the prefix - it will be null - as it must be smaller than the Prefix (as other wise the query Start Key would be bigger than the Last Key).
The constraint of M > N was introduced before the *_prefix_filter functions were checking the prefix, to avoid issues. Now the prefix is being checked, then M == N is ok.
* Simplify
Correct the test to use a binary field in the range.
To avoid further issue, only apply filter when everything is a binary() type.
* Add test for head_only mode
When leveled is used as a tictacaae key store (in parallel mode), the keys will be head_only entries. Double check they are handled as expected like object keys
* Revert previous change - must support typed buckets
Add assertion to confirm worthwhile optimisation
* Add support for configurable cache multiple (#375)
* Mas i370 patch e (#385)
Improvement to monitoring for efficiency and improved readability of logs and stats.
As part of this, where possible, tried to avoid updating loop state on READ messages in leveled processes (as was the case when tracking stats within each process).
No performance benefits found with change, but improved stats has helped discover other potential gains.
2022-12-18 20:18:03 +00:00
|
|
|
leveled_log:log(ic002, [length(FilesToDelete)]),
|
2019-01-25 14:32:41 +00:00
|
|
|
ok = CloseFun(FilterServer),
|
2019-01-25 12:11:42 +00:00
|
|
|
ok = leveled_inker:ink_clerkcomplete(State#state.inker,
|
2019-01-24 21:32:54 +00:00
|
|
|
ManifestSlice,
|
2019-07-18 13:10:11 +01:00
|
|
|
FilesToDelete);
|
2018-09-26 12:56:28 +01:00
|
|
|
false ->
|
2017-05-26 10:51:30 +01:00
|
|
|
ok = CloseFun(FilterServer),
|
2019-07-18 13:10:11 +01:00
|
|
|
ok = leveled_inker:ink_clerkcomplete(State#state.inker, [], [])
|
|
|
|
end,
|
|
|
|
{noreply, State#state{scoring_state = undefined}, hibernate};
|
2019-01-24 21:32:54 +00:00
|
|
|
handle_cast({trim, PersistedSQN, ManifestAsList}, State) ->
|
2018-02-15 16:14:46 +00:00
|
|
|
FilesToDelete =
|
2018-02-16 14:16:28 +00:00
|
|
|
leveled_imanifest:find_persistedentries(PersistedSQN, ManifestAsList),
|
Develop 3.1 d30update (#386)
* Mas i370 patch d (#383)
* Refactor penciller memory
In high-volume tests on large key-count clusters, so significant variation in the P0031 time has been seen:
TimeBucket PatchA
a.0ms_to_1ms 18554
b.1ms_to_2ms 51778
c.2ms_to_3ms 696
d.3ms_to_5ms 220
e.5ms_to_8ms 59
f.8ms_to_13ms 40
g.13ms_to_21ms 364
h.21ms_to_34ms 277
i.34ms_to_55ms 34
j.55ms_to_89ms 17
k.89ms_to_144ms 21
l.144ms_to_233ms 31
m.233ms_to_377ms 45
n.377ms_to_610ms 52
o.610ms_to_987ms 59
p.987ms_to_1597ms 55
q.1597ms_to_2684ms 54
r.2684ms_to_4281ms 29
s.4281ms_to_6965ms 7
t.6295ms_to_11246ms 1
It is unclear why this varies so much. The time to add to the cache appears to be minimal (but perhaps there is an issue with timing points in the code), whereas the time to add to the index is much more significant and variable. There is also variable time when the memory is rolled (although the actual activity here appears to be minimal.
The refactoring here is two-fold:
- tidy and simplify by keeping LoopState managed within handle_call, and add more helpful dialyzer specs;
- change the update to the index to be a simple extension of a list, rather than any conversion.
This alternative version of the pmem index in unit test is orders of magnitude faster to add - and is the same order of magnitude to check. Anticipation is that it may be more efficient in terms of memory changes.
* Compress SST index
Reduces the size of the leveled_sst index with two changes:
1 - Where there is a common prefix of tuple elements (e.g. Bucket) across the whole leveled_sst file - only the non-common part is indexed, and a function is used to compare.
2 - There is less "indexing" of the index i.e. only 1 in 16 keys are passed into the gb_trees part instead of 1 in 4
* Immediate hibernate
Reasons for delay in hibernate were not clear.
Straight after creation the process will not be in receipt of messages (must wait for the manifest to be updated), so better to hibernate now. This also means the log PC023 provides more accurate information.
* Refactor BIC
This patch avoids the following:
- repeated replacement of the same element in the BIC (via get_kvrange), by checking presence via GET before sing SET
- Stops re-reading of all elements to discover high modified date
Also there appears to have been a bug where a missing HMD for the file is required to add to the cache. However, now the cache may be erased without erasing the HMD. This means that the cache can never be rebuilt
* Use correct size in test results
erts_debug:flat_size/1 returns size in words (i.e. 8 bytes on 64-bit CPU) not bytes
* Don't change summary record
As it is persisted as part of the file write, any change to the summary record cannot be rolled back
* Clerk to prompt L0 write
Simplifies the logic if the clerk request work for the penciller prompts L0 writes as well as Manifest changes.
The advantage now is that if the penciller memory is full, and PUT load stops, the clerk should still be able to prompt persistence. the penciller can therefore make use of dead time this way
* Add push on journal compact
If there has been a backlog, followed by a quiet period - there may be a large ledger cache left unpushed. Journal compaction events are about once per hour, so the performance overhead of a false push should be minimal, with the advantage of clearing any backlog before load starts again.
This is only relevant to riak users with very off/full batch type workloads.
* Extend tests
To more consistently trigger all overload scenarios
* Fix range keys smaller than prefix
Can't make end key an empty binary in this case, as it may be bigger than any keys within the range, but will appear to be smaller.
Unit tests and ct tests added to expose the potential issue
* Tidy-up
- Remove penciller logs which are no longer called
- Get pclerk to only wait MIN_TIMEOUT after doing work, in case there is a backlog
- Remove update_levelzero_cache function as it is unique to handle_call of push_mem, and simple enough to be inline
- Alight testutil slow offer with standard slow offer used
* Tidy-up
Remove pre-otp20 references.
Reinstate the check that the starting pid is still active, this was added to tidy up shutdown.
Resolve failure to run on otp20 due to `-if` sttaement
* Tidy up
Using null rather then {null, Key} is potentially clearer as it is not a concern what they Key is in this case, and removes a comparison step from the leveled_codec:endkey_passed/2 function.
There were issues with coverage in eunit tests as the leveled_pclerk shut down. This prompted a general tidy of leveled_pclerk (remove passing of LoopState into internal functions, and add dialyzer specs.
* Remove R16 relic
* Further testing another issue
The StartKey must always be less than or equal to the prefix when the first N characters are stripped, but this is not true of the EndKey (for the query) which does not have to be between the FirstKey and the LastKey.
If the EndKey query does not match it must be greater than the Prefix (as otherwise it would not have been greater than the FirstKey - so set to null.
* Fix unit test
Unit test had a typo - and result interpretation had a misunderstanding.
* Code and spec tidy
Also look to the cover the situation when the FirstKey is the same as the Prefix with tests.
This is, in theory, not an issue as it is the EndKey for each sublist which is indexed in leveled_tree. However, guard against it mapping to null here, just in case there are dangers lurking (note that tests will still pass without `M > N` guard in place.
* Hibernate on BIC complete
There are three situations when the BIC becomes complete:
- In a file created as part of a merge the BIS is learned in the merge
- After startup, files below L1 learn the block cache through reads that happen to read the block, eventually the while cache will be read, unless...
- Either before/after the cache is complete, it can get whiped by a timeout after a get_sqn request (e.g. as prompted by a journal compaction) ... it will then be re-filled of the back of get/get-range requests.
In all these situations we want to hibernate after the BIC is fill - to reflect the fact that the LoopState should now be relatively stable, so it is a good point to GC and rationalise location of data.
Previously on the the first base was covered. Now all three are covered through the bic_complete message.
* Test all index keys have same term
This works functionally, but is not optimised (the term is replicated in the index)
* Summaries with same index term
If the summary index all have the same index term - only the object keys need to be indexes
* Simplify case statements
We either match the pattern of <<Prefix:N, Suffix>> or the answer should be null
* OK for M == N
If M = N for the first key, it will have a suffix of <<>>. This will match (as expected) a query Start Key of the sam size, and be smaller than any query Start Key that has the same prefix.
If the query Start Key does not match the prefix - it will be null - as it must be smaller than the Prefix (as other wise the query Start Key would be bigger than the Last Key).
The constraint of M > N was introduced before the *_prefix_filter functions were checking the prefix, to avoid issues. Now the prefix is being checked, then M == N is ok.
* Simplify
Correct the test to use a binary field in the range.
To avoid further issue, only apply filter when everything is a binary() type.
* Add test for head_only mode
When leveled is used as a tictacaae key store (in parallel mode), the keys will be head_only entries. Double check they are handled as expected like object keys
* Revert previous change - must support typed buckets
Add assertion to confirm worthwhile optimisation
* Add support for configurable cache multiple (#375)
* Mas i370 patch e (#385)
Improvement to monitoring for efficiency and improved readability of logs and stats.
As part of this, where possible, tried to avoid updating loop state on READ messages in leveled processes (as was the case when tracking stats within each process).
No performance benefits found with change, but improved stats has helped discover other potential gains.
2022-12-18 20:18:03 +00:00
|
|
|
leveled_log:log(ic007, []),
|
2019-01-24 21:32:54 +00:00
|
|
|
ok = leveled_inker:ink_clerkcomplete(State#state.inker, [], FilesToDelete),
|
|
|
|
{noreply, State};
|
2016-10-14 13:36:12 +01:00
|
|
|
handle_cast({hashtable_calc, HashTree, StartPos, CDBpid}, State) ->
|
|
|
|
{IndexList, HashTreeBin} = leveled_cdb:hashtable_calc(HashTree, StartPos),
|
|
|
|
ok = leveled_cdb:cdb_returnhashtable(CDBpid, IndexList, HashTreeBin),
|
|
|
|
{stop, normal, State};
|
2018-12-11 21:59:57 +00:00
|
|
|
handle_cast({log_level, LogLevel}, State) ->
|
|
|
|
ok = leveled_log:set_loglevel(LogLevel),
|
|
|
|
CDBopts = State#state.cdb_options,
|
|
|
|
CDBopts0 = CDBopts#cdb_options{log_options = leveled_log:get_opts()},
|
|
|
|
{noreply, State#state{cdb_options = CDBopts0}};
|
|
|
|
handle_cast({add_logs, ForcedLogs}, State) ->
|
|
|
|
ok = leveled_log:add_forcedlogs(ForcedLogs),
|
|
|
|
CDBopts = State#state.cdb_options,
|
|
|
|
CDBopts0 = CDBopts#cdb_options{log_options = leveled_log:get_opts()},
|
|
|
|
{noreply, State#state{cdb_options = CDBopts0}};
|
|
|
|
handle_cast({remove_logs, ForcedLogs}, State) ->
|
|
|
|
ok = leveled_log:remove_forcedlogs(ForcedLogs),
|
|
|
|
CDBopts = State#state.cdb_options,
|
|
|
|
CDBopts0 = CDBopts#cdb_options{log_options = leveled_log:get_opts()},
|
2019-01-24 21:32:54 +00:00
|
|
|
{noreply, State#state{cdb_options = CDBopts0}}.
|
2016-09-20 16:13:36 +01:00
|
|
|
|
|
|
|
handle_info(_Info, State) ->
|
|
|
|
{noreply, State}.
|
|
|
|
|
2016-11-14 19:34:11 +00:00
|
|
|
terminate(normal, _State) ->
|
|
|
|
ok;
|
|
|
|
terminate(Reason, _State) ->
|
Develop 3.1 d30update (#386)
* Mas i370 patch d (#383)
* Refactor penciller memory
In high-volume tests on large key-count clusters, so significant variation in the P0031 time has been seen:
TimeBucket PatchA
a.0ms_to_1ms 18554
b.1ms_to_2ms 51778
c.2ms_to_3ms 696
d.3ms_to_5ms 220
e.5ms_to_8ms 59
f.8ms_to_13ms 40
g.13ms_to_21ms 364
h.21ms_to_34ms 277
i.34ms_to_55ms 34
j.55ms_to_89ms 17
k.89ms_to_144ms 21
l.144ms_to_233ms 31
m.233ms_to_377ms 45
n.377ms_to_610ms 52
o.610ms_to_987ms 59
p.987ms_to_1597ms 55
q.1597ms_to_2684ms 54
r.2684ms_to_4281ms 29
s.4281ms_to_6965ms 7
t.6295ms_to_11246ms 1
It is unclear why this varies so much. The time to add to the cache appears to be minimal (but perhaps there is an issue with timing points in the code), whereas the time to add to the index is much more significant and variable. There is also variable time when the memory is rolled (although the actual activity here appears to be minimal.
The refactoring here is two-fold:
- tidy and simplify by keeping LoopState managed within handle_call, and add more helpful dialyzer specs;
- change the update to the index to be a simple extension of a list, rather than any conversion.
This alternative version of the pmem index in unit test is orders of magnitude faster to add - and is the same order of magnitude to check. Anticipation is that it may be more efficient in terms of memory changes.
* Compress SST index
Reduces the size of the leveled_sst index with two changes:
1 - Where there is a common prefix of tuple elements (e.g. Bucket) across the whole leveled_sst file - only the non-common part is indexed, and a function is used to compare.
2 - There is less "indexing" of the index i.e. only 1 in 16 keys are passed into the gb_trees part instead of 1 in 4
* Immediate hibernate
Reasons for delay in hibernate were not clear.
Straight after creation the process will not be in receipt of messages (must wait for the manifest to be updated), so better to hibernate now. This also means the log PC023 provides more accurate information.
* Refactor BIC
This patch avoids the following:
- repeated replacement of the same element in the BIC (via get_kvrange), by checking presence via GET before sing SET
- Stops re-reading of all elements to discover high modified date
Also there appears to have been a bug where a missing HMD for the file is required to add to the cache. However, now the cache may be erased without erasing the HMD. This means that the cache can never be rebuilt
* Use correct size in test results
erts_debug:flat_size/1 returns size in words (i.e. 8 bytes on 64-bit CPU) not bytes
* Don't change summary record
As it is persisted as part of the file write, any change to the summary record cannot be rolled back
* Clerk to prompt L0 write
Simplifies the logic if the clerk request work for the penciller prompts L0 writes as well as Manifest changes.
The advantage now is that if the penciller memory is full, and PUT load stops, the clerk should still be able to prompt persistence. the penciller can therefore make use of dead time this way
* Add push on journal compact
If there has been a backlog, followed by a quiet period - there may be a large ledger cache left unpushed. Journal compaction events are about once per hour, so the performance overhead of a false push should be minimal, with the advantage of clearing any backlog before load starts again.
This is only relevant to riak users with very off/full batch type workloads.
* Extend tests
To more consistently trigger all overload scenarios
* Fix range keys smaller than prefix
Can't make end key an empty binary in this case, as it may be bigger than any keys within the range, but will appear to be smaller.
Unit tests and ct tests added to expose the potential issue
* Tidy-up
- Remove penciller logs which are no longer called
- Get pclerk to only wait MIN_TIMEOUT after doing work, in case there is a backlog
- Remove update_levelzero_cache function as it is unique to handle_call of push_mem, and simple enough to be inline
- Alight testutil slow offer with standard slow offer used
* Tidy-up
Remove pre-otp20 references.
Reinstate the check that the starting pid is still active, this was added to tidy up shutdown.
Resolve failure to run on otp20 due to `-if` sttaement
* Tidy up
Using null rather then {null, Key} is potentially clearer as it is not a concern what they Key is in this case, and removes a comparison step from the leveled_codec:endkey_passed/2 function.
There were issues with coverage in eunit tests as the leveled_pclerk shut down. This prompted a general tidy of leveled_pclerk (remove passing of LoopState into internal functions, and add dialyzer specs.
* Remove R16 relic
* Further testing another issue
The StartKey must always be less than or equal to the prefix when the first N characters are stripped, but this is not true of the EndKey (for the query) which does not have to be between the FirstKey and the LastKey.
If the EndKey query does not match it must be greater than the Prefix (as otherwise it would not have been greater than the FirstKey - so set to null.
* Fix unit test
Unit test had a typo - and result interpretation had a misunderstanding.
* Code and spec tidy
Also look to the cover the situation when the FirstKey is the same as the Prefix with tests.
This is, in theory, not an issue as it is the EndKey for each sublist which is indexed in leveled_tree. However, guard against it mapping to null here, just in case there are dangers lurking (note that tests will still pass without `M > N` guard in place.
* Hibernate on BIC complete
There are three situations when the BIC becomes complete:
- In a file created as part of a merge the BIS is learned in the merge
- After startup, files below L1 learn the block cache through reads that happen to read the block, eventually the while cache will be read, unless...
- Either before/after the cache is complete, it can get whiped by a timeout after a get_sqn request (e.g. as prompted by a journal compaction) ... it will then be re-filled of the back of get/get-range requests.
In all these situations we want to hibernate after the BIC is fill - to reflect the fact that the LoopState should now be relatively stable, so it is a good point to GC and rationalise location of data.
Previously on the the first base was covered. Now all three are covered through the bic_complete message.
* Test all index keys have same term
This works functionally, but is not optimised (the term is replicated in the index)
* Summaries with same index term
If the summary index all have the same index term - only the object keys need to be indexes
* Simplify case statements
We either match the pattern of <<Prefix:N, Suffix>> or the answer should be null
* OK for M == N
If M = N for the first key, it will have a suffix of <<>>. This will match (as expected) a query Start Key of the sam size, and be smaller than any query Start Key that has the same prefix.
If the query Start Key does not match the prefix - it will be null - as it must be smaller than the Prefix (as other wise the query Start Key would be bigger than the Last Key).
The constraint of M > N was introduced before the *_prefix_filter functions were checking the prefix, to avoid issues. Now the prefix is being checked, then M == N is ok.
* Simplify
Correct the test to use a binary field in the range.
To avoid further issue, only apply filter when everything is a binary() type.
* Add test for head_only mode
When leveled is used as a tictacaae key store (in parallel mode), the keys will be head_only entries. Double check they are handled as expected like object keys
* Revert previous change - must support typed buckets
Add assertion to confirm worthwhile optimisation
* Add support for configurable cache multiple (#375)
* Mas i370 patch e (#385)
Improvement to monitoring for efficiency and improved readability of logs and stats.
As part of this, where possible, tried to avoid updating loop state on READ messages in leveled processes (as was the case when tracking stats within each process).
No performance benefits found with change, but improved stats has helped discover other potential gains.
2022-12-18 20:18:03 +00:00
|
|
|
leveled_log:log(ic001, [Reason]).
|
2016-09-20 16:13:36 +01:00
|
|
|
|
|
|
|
code_change(_OldVsn, State, _Extra) ->
|
|
|
|
{ok, State}.
|
|
|
|
|
|
|
|
|
2017-03-30 15:46:37 +01:00
|
|
|
%%%============================================================================
|
|
|
|
%%% External functions
|
|
|
|
%%%============================================================================
|
|
|
|
|
2017-11-09 12:42:49 +00:00
|
|
|
-spec schedule_compaction(list(integer()),
|
|
|
|
integer(),
|
|
|
|
{integer(), integer(), integer()}) -> integer().
|
|
|
|
%% @doc
|
2017-03-30 15:46:37 +01:00
|
|
|
%% Schedule the next compaction event for this store. Chooses a random
|
|
|
|
%% interval, and then a random start time within the first third
|
|
|
|
%% of the interval.
|
|
|
|
%%
|
|
|
|
%% The number of Compaction runs per day can be set. This doesn't guaranteee
|
|
|
|
%% those runs, but uses the assumption there will be n runs when scheduling
|
|
|
|
%% the next one
|
|
|
|
%%
|
|
|
|
%% Compaction Hours should be the list of hours during the day (based on local
|
|
|
|
%% time when compcation can be scheduled to run)
|
|
|
|
%% e.g. [0, 1, 2, 3, 4, 21, 22, 23]
|
2017-05-18 14:09:45 +01:00
|
|
|
%% Runs per day is the number of compaction runs per day that should be
|
2017-03-30 15:46:37 +01:00
|
|
|
%% scheduled - expected to be a small integer, probably 1
|
|
|
|
%%
|
|
|
|
%% Current TS should be the outcome of os:timestamp()
|
|
|
|
%%
|
|
|
|
schedule_compaction(CompactionHours, RunsPerDay, CurrentTS) ->
|
2017-05-18 14:09:45 +01:00
|
|
|
% We chedule the next interval by acting as if we were scheduing all
|
|
|
|
% n intervals at random, but then only chose the next one. After each
|
|
|
|
% event is occurred the random process is repeated to determine the next
|
|
|
|
% event to schedule i.e. the unused schedule is discarded.
|
|
|
|
|
2017-03-30 15:46:37 +01:00
|
|
|
IntervalLength = 60 div ?INTERVALS_PER_HOUR,
|
|
|
|
TotalHours = length(CompactionHours),
|
|
|
|
|
|
|
|
LocalTime = calendar:now_to_local_time(CurrentTS),
|
|
|
|
{{NowY, NowMon, NowD},
|
|
|
|
{NowH, NowMin, _NowS}} = LocalTime,
|
|
|
|
CurrentInterval = {NowH, NowMin div IntervalLength + 1},
|
|
|
|
|
2017-05-18 14:09:45 +01:00
|
|
|
% Randomly select an hour and an interval for each of the runs expected
|
|
|
|
% today.
|
2017-03-30 15:46:37 +01:00
|
|
|
RandSelect =
|
|
|
|
fun(_X) ->
|
2017-07-31 20:20:39 +02:00
|
|
|
{lists:nth(leveled_rand:uniform(TotalHours), CompactionHours),
|
|
|
|
leveled_rand:uniform(?INTERVALS_PER_HOUR)}
|
2017-03-30 15:46:37 +01:00
|
|
|
end,
|
|
|
|
RandIntervals = lists:sort(lists:map(RandSelect,
|
|
|
|
lists:seq(1, RunsPerDay))),
|
|
|
|
|
2017-05-18 14:09:45 +01:00
|
|
|
% Pick the next interval from the list. The intervals before current time
|
|
|
|
% are considered as intervals tomorrow, so will only be next if there are
|
|
|
|
% no other today
|
2017-03-30 15:46:37 +01:00
|
|
|
CheckNotBefore = fun(A) -> A =< CurrentInterval end,
|
|
|
|
{TooEarly, MaybeOK} = lists:splitwith(CheckNotBefore, RandIntervals),
|
|
|
|
{NextDate, {NextH, NextI}} =
|
|
|
|
case MaybeOK of
|
|
|
|
[] ->
|
2017-05-18 14:09:45 +01:00
|
|
|
% Use first interval picked tomorrow if none of selected run times
|
2017-03-30 15:46:37 +01:00
|
|
|
% are today
|
|
|
|
Tmrw = calendar:date_to_gregorian_days(NowY, NowMon, NowD) + 1,
|
|
|
|
{calendar:gregorian_days_to_date(Tmrw),
|
|
|
|
lists:nth(1, TooEarly)};
|
|
|
|
_ ->
|
|
|
|
{{NowY, NowMon, NowD}, lists:nth(1, MaybeOK)}
|
|
|
|
end,
|
2017-05-18 14:09:45 +01:00
|
|
|
|
|
|
|
% Calculate the offset in seconds to this next interval
|
2017-03-30 15:46:37 +01:00
|
|
|
NextS0 = NextI * (IntervalLength * 60)
|
2017-07-31 20:20:39 +02:00
|
|
|
- leveled_rand:uniform(IntervalLength * 60),
|
2017-03-30 15:46:37 +01:00
|
|
|
NextM = NextS0 div 60,
|
|
|
|
NextS = NextS0 rem 60,
|
|
|
|
TimeDiff = calendar:time_difference(LocalTime,
|
|
|
|
{NextDate, {NextH, NextM, NextS}}),
|
|
|
|
{Days, {Hours, Mins, Secs}} = TimeDiff,
|
|
|
|
Days * 86400 + Hours * 3600 + Mins * 60 + Secs.
|
|
|
|
|
|
|
|
|
2016-09-20 16:13:36 +01:00
|
|
|
%%%============================================================================
|
|
|
|
%%% Internal functions
|
|
|
|
%%%============================================================================
|
|
|
|
|
2020-11-29 15:43:29 +00:00
|
|
|
-spec check_single_file(pid(),
|
|
|
|
leveled_inker:filterfun(),
|
|
|
|
leveled_inker:filterserver(),
|
|
|
|
leveled_codec:sqn(),
|
2020-03-15 22:14:42 +00:00
|
|
|
non_neg_integer(), non_neg_integer(),
|
|
|
|
leveled_codec:compaction_strategy()) ->
|
|
|
|
float().
|
2017-11-09 12:48:48 +00:00
|
|
|
%% @doc
|
|
|
|
%% Get a score for a single CDB file in the journal. This will pull out a bunch
|
|
|
|
%% of keys and sizes at random in an efficient way (by scanning the hashtable
|
2017-11-09 17:12:47 +00:00
|
|
|
%% then just picking the key and size information of disk).
|
2017-11-09 12:48:48 +00:00
|
|
|
%%
|
|
|
|
%% The score should represent a percentage which is the size of the file by
|
|
|
|
%% comparison to the original file if compaction was to be run. So if a file
|
|
|
|
%% can be reduced in size by 30% the score will be 70%.
|
|
|
|
%%
|
|
|
|
%% The score is based on a random sample - so will not be consistent between
|
|
|
|
%% calls.
|
2020-03-15 22:14:42 +00:00
|
|
|
check_single_file(CDB, FilterFun, FilterServer, MaxSQN,
|
|
|
|
SampleSize, BatchSize,
|
|
|
|
ReloadStrategy) ->
|
2016-10-05 18:28:31 +01:00
|
|
|
FN = leveled_cdb:cdb_filename(CDB),
|
2020-03-09 17:45:06 +00:00
|
|
|
SW = os:timestamp(),
|
2016-09-21 18:31:42 +01:00
|
|
|
PositionList = leveled_cdb:cdb_getpositions(CDB, SampleSize),
|
|
|
|
KeySizeList = fetch_inbatches(PositionList, BatchSize, CDB, []),
|
2017-11-09 12:42:49 +00:00
|
|
|
Score =
|
2020-03-15 22:14:42 +00:00
|
|
|
size_comparison_score(KeySizeList,
|
|
|
|
FilterFun,
|
|
|
|
FilterServer,
|
|
|
|
MaxSQN,
|
|
|
|
ReloadStrategy),
|
2020-03-09 17:45:06 +00:00
|
|
|
safely_log_filescore(PositionList, FN, Score, SW),
|
2017-11-09 12:42:49 +00:00
|
|
|
Score.
|
|
|
|
|
2020-03-09 17:45:06 +00:00
|
|
|
safely_log_filescore([], FN, Score, SW) ->
|
Develop 3.1 d30update (#386)
* Mas i370 patch d (#383)
* Refactor penciller memory
In high-volume tests on large key-count clusters, so significant variation in the P0031 time has been seen:
TimeBucket PatchA
a.0ms_to_1ms 18554
b.1ms_to_2ms 51778
c.2ms_to_3ms 696
d.3ms_to_5ms 220
e.5ms_to_8ms 59
f.8ms_to_13ms 40
g.13ms_to_21ms 364
h.21ms_to_34ms 277
i.34ms_to_55ms 34
j.55ms_to_89ms 17
k.89ms_to_144ms 21
l.144ms_to_233ms 31
m.233ms_to_377ms 45
n.377ms_to_610ms 52
o.610ms_to_987ms 59
p.987ms_to_1597ms 55
q.1597ms_to_2684ms 54
r.2684ms_to_4281ms 29
s.4281ms_to_6965ms 7
t.6295ms_to_11246ms 1
It is unclear why this varies so much. The time to add to the cache appears to be minimal (but perhaps there is an issue with timing points in the code), whereas the time to add to the index is much more significant and variable. There is also variable time when the memory is rolled (although the actual activity here appears to be minimal.
The refactoring here is two-fold:
- tidy and simplify by keeping LoopState managed within handle_call, and add more helpful dialyzer specs;
- change the update to the index to be a simple extension of a list, rather than any conversion.
This alternative version of the pmem index in unit test is orders of magnitude faster to add - and is the same order of magnitude to check. Anticipation is that it may be more efficient in terms of memory changes.
* Compress SST index
Reduces the size of the leveled_sst index with two changes:
1 - Where there is a common prefix of tuple elements (e.g. Bucket) across the whole leveled_sst file - only the non-common part is indexed, and a function is used to compare.
2 - There is less "indexing" of the index i.e. only 1 in 16 keys are passed into the gb_trees part instead of 1 in 4
* Immediate hibernate
Reasons for delay in hibernate were not clear.
Straight after creation the process will not be in receipt of messages (must wait for the manifest to be updated), so better to hibernate now. This also means the log PC023 provides more accurate information.
* Refactor BIC
This patch avoids the following:
- repeated replacement of the same element in the BIC (via get_kvrange), by checking presence via GET before sing SET
- Stops re-reading of all elements to discover high modified date
Also there appears to have been a bug where a missing HMD for the file is required to add to the cache. However, now the cache may be erased without erasing the HMD. This means that the cache can never be rebuilt
* Use correct size in test results
erts_debug:flat_size/1 returns size in words (i.e. 8 bytes on 64-bit CPU) not bytes
* Don't change summary record
As it is persisted as part of the file write, any change to the summary record cannot be rolled back
* Clerk to prompt L0 write
Simplifies the logic if the clerk request work for the penciller prompts L0 writes as well as Manifest changes.
The advantage now is that if the penciller memory is full, and PUT load stops, the clerk should still be able to prompt persistence. the penciller can therefore make use of dead time this way
* Add push on journal compact
If there has been a backlog, followed by a quiet period - there may be a large ledger cache left unpushed. Journal compaction events are about once per hour, so the performance overhead of a false push should be minimal, with the advantage of clearing any backlog before load starts again.
This is only relevant to riak users with very off/full batch type workloads.
* Extend tests
To more consistently trigger all overload scenarios
* Fix range keys smaller than prefix
Can't make end key an empty binary in this case, as it may be bigger than any keys within the range, but will appear to be smaller.
Unit tests and ct tests added to expose the potential issue
* Tidy-up
- Remove penciller logs which are no longer called
- Get pclerk to only wait MIN_TIMEOUT after doing work, in case there is a backlog
- Remove update_levelzero_cache function as it is unique to handle_call of push_mem, and simple enough to be inline
- Alight testutil slow offer with standard slow offer used
* Tidy-up
Remove pre-otp20 references.
Reinstate the check that the starting pid is still active, this was added to tidy up shutdown.
Resolve failure to run on otp20 due to `-if` sttaement
* Tidy up
Using null rather then {null, Key} is potentially clearer as it is not a concern what they Key is in this case, and removes a comparison step from the leveled_codec:endkey_passed/2 function.
There were issues with coverage in eunit tests as the leveled_pclerk shut down. This prompted a general tidy of leveled_pclerk (remove passing of LoopState into internal functions, and add dialyzer specs.
* Remove R16 relic
* Further testing another issue
The StartKey must always be less than or equal to the prefix when the first N characters are stripped, but this is not true of the EndKey (for the query) which does not have to be between the FirstKey and the LastKey.
If the EndKey query does not match it must be greater than the Prefix (as otherwise it would not have been greater than the FirstKey - so set to null.
* Fix unit test
Unit test had a typo - and result interpretation had a misunderstanding.
* Code and spec tidy
Also look to the cover the situation when the FirstKey is the same as the Prefix with tests.
This is, in theory, not an issue as it is the EndKey for each sublist which is indexed in leveled_tree. However, guard against it mapping to null here, just in case there are dangers lurking (note that tests will still pass without `M > N` guard in place.
* Hibernate on BIC complete
There are three situations when the BIC becomes complete:
- In a file created as part of a merge the BIS is learned in the merge
- After startup, files below L1 learn the block cache through reads that happen to read the block, eventually the while cache will be read, unless...
- Either before/after the cache is complete, it can get whiped by a timeout after a get_sqn request (e.g. as prompted by a journal compaction) ... it will then be re-filled of the back of get/get-range requests.
In all these situations we want to hibernate after the BIC is fill - to reflect the fact that the LoopState should now be relatively stable, so it is a good point to GC and rationalise location of data.
Previously on the the first base was covered. Now all three are covered through the bic_complete message.
* Test all index keys have same term
This works functionally, but is not optimised (the term is replicated in the index)
* Summaries with same index term
If the summary index all have the same index term - only the object keys need to be indexes
* Simplify case statements
We either match the pattern of <<Prefix:N, Suffix>> or the answer should be null
* OK for M == N
If M = N for the first key, it will have a suffix of <<>>. This will match (as expected) a query Start Key of the sam size, and be smaller than any query Start Key that has the same prefix.
If the query Start Key does not match the prefix - it will be null - as it must be smaller than the Prefix (as other wise the query Start Key would be bigger than the Last Key).
The constraint of M > N was introduced before the *_prefix_filter functions were checking the prefix, to avoid issues. Now the prefix is being checked, then M == N is ok.
* Simplify
Correct the test to use a binary field in the range.
To avoid further issue, only apply filter when everything is a binary() type.
* Add test for head_only mode
When leveled is used as a tictacaae key store (in parallel mode), the keys will be head_only entries. Double check they are handled as expected like object keys
* Revert previous change - must support typed buckets
Add assertion to confirm worthwhile optimisation
* Add support for configurable cache multiple (#375)
* Mas i370 patch e (#385)
Improvement to monitoring for efficiency and improved readability of logs and stats.
As part of this, where possible, tried to avoid updating loop state on READ messages in leveled processes (as was the case when tracking stats within each process).
No performance benefits found with change, but improved stats has helped discover other potential gains.
2022-12-18 20:18:03 +00:00
|
|
|
leveled_log:log_timer(ic004, [Score, empty, FN], SW);
|
2020-03-09 17:45:06 +00:00
|
|
|
safely_log_filescore(PositionList, FN, Score, SW) ->
|
|
|
|
AvgJump =
|
|
|
|
(lists:last(PositionList) - lists:nth(1, PositionList))
|
|
|
|
div length(PositionList),
|
Develop 3.1 d30update (#386)
* Mas i370 patch d (#383)
* Refactor penciller memory
In high-volume tests on large key-count clusters, so significant variation in the P0031 time has been seen:
TimeBucket PatchA
a.0ms_to_1ms 18554
b.1ms_to_2ms 51778
c.2ms_to_3ms 696
d.3ms_to_5ms 220
e.5ms_to_8ms 59
f.8ms_to_13ms 40
g.13ms_to_21ms 364
h.21ms_to_34ms 277
i.34ms_to_55ms 34
j.55ms_to_89ms 17
k.89ms_to_144ms 21
l.144ms_to_233ms 31
m.233ms_to_377ms 45
n.377ms_to_610ms 52
o.610ms_to_987ms 59
p.987ms_to_1597ms 55
q.1597ms_to_2684ms 54
r.2684ms_to_4281ms 29
s.4281ms_to_6965ms 7
t.6295ms_to_11246ms 1
It is unclear why this varies so much. The time to add to the cache appears to be minimal (but perhaps there is an issue with timing points in the code), whereas the time to add to the index is much more significant and variable. There is also variable time when the memory is rolled (although the actual activity here appears to be minimal.
The refactoring here is two-fold:
- tidy and simplify by keeping LoopState managed within handle_call, and add more helpful dialyzer specs;
- change the update to the index to be a simple extension of a list, rather than any conversion.
This alternative version of the pmem index in unit test is orders of magnitude faster to add - and is the same order of magnitude to check. Anticipation is that it may be more efficient in terms of memory changes.
* Compress SST index
Reduces the size of the leveled_sst index with two changes:
1 - Where there is a common prefix of tuple elements (e.g. Bucket) across the whole leveled_sst file - only the non-common part is indexed, and a function is used to compare.
2 - There is less "indexing" of the index i.e. only 1 in 16 keys are passed into the gb_trees part instead of 1 in 4
* Immediate hibernate
Reasons for delay in hibernate were not clear.
Straight after creation the process will not be in receipt of messages (must wait for the manifest to be updated), so better to hibernate now. This also means the log PC023 provides more accurate information.
* Refactor BIC
This patch avoids the following:
- repeated replacement of the same element in the BIC (via get_kvrange), by checking presence via GET before sing SET
- Stops re-reading of all elements to discover high modified date
Also there appears to have been a bug where a missing HMD for the file is required to add to the cache. However, now the cache may be erased without erasing the HMD. This means that the cache can never be rebuilt
* Use correct size in test results
erts_debug:flat_size/1 returns size in words (i.e. 8 bytes on 64-bit CPU) not bytes
* Don't change summary record
As it is persisted as part of the file write, any change to the summary record cannot be rolled back
* Clerk to prompt L0 write
Simplifies the logic if the clerk request work for the penciller prompts L0 writes as well as Manifest changes.
The advantage now is that if the penciller memory is full, and PUT load stops, the clerk should still be able to prompt persistence. the penciller can therefore make use of dead time this way
* Add push on journal compact
If there has been a backlog, followed by a quiet period - there may be a large ledger cache left unpushed. Journal compaction events are about once per hour, so the performance overhead of a false push should be minimal, with the advantage of clearing any backlog before load starts again.
This is only relevant to riak users with very off/full batch type workloads.
* Extend tests
To more consistently trigger all overload scenarios
* Fix range keys smaller than prefix
Can't make end key an empty binary in this case, as it may be bigger than any keys within the range, but will appear to be smaller.
Unit tests and ct tests added to expose the potential issue
* Tidy-up
- Remove penciller logs which are no longer called
- Get pclerk to only wait MIN_TIMEOUT after doing work, in case there is a backlog
- Remove update_levelzero_cache function as it is unique to handle_call of push_mem, and simple enough to be inline
- Alight testutil slow offer with standard slow offer used
* Tidy-up
Remove pre-otp20 references.
Reinstate the check that the starting pid is still active, this was added to tidy up shutdown.
Resolve failure to run on otp20 due to `-if` sttaement
* Tidy up
Using null rather then {null, Key} is potentially clearer as it is not a concern what they Key is in this case, and removes a comparison step from the leveled_codec:endkey_passed/2 function.
There were issues with coverage in eunit tests as the leveled_pclerk shut down. This prompted a general tidy of leveled_pclerk (remove passing of LoopState into internal functions, and add dialyzer specs.
* Remove R16 relic
* Further testing another issue
The StartKey must always be less than or equal to the prefix when the first N characters are stripped, but this is not true of the EndKey (for the query) which does not have to be between the FirstKey and the LastKey.
If the EndKey query does not match it must be greater than the Prefix (as otherwise it would not have been greater than the FirstKey - so set to null.
* Fix unit test
Unit test had a typo - and result interpretation had a misunderstanding.
* Code and spec tidy
Also look to the cover the situation when the FirstKey is the same as the Prefix with tests.
This is, in theory, not an issue as it is the EndKey for each sublist which is indexed in leveled_tree. However, guard against it mapping to null here, just in case there are dangers lurking (note that tests will still pass without `M > N` guard in place.
* Hibernate on BIC complete
There are three situations when the BIC becomes complete:
- In a file created as part of a merge the BIS is learned in the merge
- After startup, files below L1 learn the block cache through reads that happen to read the block, eventually the while cache will be read, unless...
- Either before/after the cache is complete, it can get whiped by a timeout after a get_sqn request (e.g. as prompted by a journal compaction) ... it will then be re-filled of the back of get/get-range requests.
In all these situations we want to hibernate after the BIC is fill - to reflect the fact that the LoopState should now be relatively stable, so it is a good point to GC and rationalise location of data.
Previously on the the first base was covered. Now all three are covered through the bic_complete message.
* Test all index keys have same term
This works functionally, but is not optimised (the term is replicated in the index)
* Summaries with same index term
If the summary index all have the same index term - only the object keys need to be indexes
* Simplify case statements
We either match the pattern of <<Prefix:N, Suffix>> or the answer should be null
* OK for M == N
If M = N for the first key, it will have a suffix of <<>>. This will match (as expected) a query Start Key of the sam size, and be smaller than any query Start Key that has the same prefix.
If the query Start Key does not match the prefix - it will be null - as it must be smaller than the Prefix (as other wise the query Start Key would be bigger than the Last Key).
The constraint of M > N was introduced before the *_prefix_filter functions were checking the prefix, to avoid issues. Now the prefix is being checked, then M == N is ok.
* Simplify
Correct the test to use a binary field in the range.
To avoid further issue, only apply filter when everything is a binary() type.
* Add test for head_only mode
When leveled is used as a tictacaae key store (in parallel mode), the keys will be head_only entries. Double check they are handled as expected like object keys
* Revert previous change - must support typed buckets
Add assertion to confirm worthwhile optimisation
* Add support for configurable cache multiple (#375)
* Mas i370 patch e (#385)
Improvement to monitoring for efficiency and improved readability of logs and stats.
As part of this, where possible, tried to avoid updating loop state on READ messages in leveled processes (as was the case when tracking stats within each process).
No performance benefits found with change, but improved stats has helped discover other potential gains.
2022-12-18 20:18:03 +00:00
|
|
|
leveled_log:log_timer(ic004, [Score, AvgJump, FN], SW).
|
2020-03-09 17:45:06 +00:00
|
|
|
|
2020-03-15 22:14:42 +00:00
|
|
|
-spec size_comparison_score(list(key_size() | corrupted_test_key_size()),
|
2020-11-29 15:43:29 +00:00
|
|
|
leveled_inker:filterfun(),
|
|
|
|
leveled_inker:filterserver(),
|
|
|
|
leveled_codec:sqn(),
|
2020-03-15 22:14:42 +00:00
|
|
|
leveled_codec:compaction_strategy()) ->
|
|
|
|
float().
|
|
|
|
size_comparison_score(KeySizeList,
|
|
|
|
FilterFun, FilterServer, MaxSQN,
|
2020-11-29 15:43:29 +00:00
|
|
|
ReloadStrategy) ->
|
2016-12-11 06:53:25 +00:00
|
|
|
FoldFunForSizeCompare =
|
|
|
|
fun(KS, {ActSize, RplSize}) ->
|
|
|
|
case KS of
|
2019-07-24 18:03:22 +01:00
|
|
|
{{SQN, Type, PK}, Size} ->
|
2020-11-29 15:43:29 +00:00
|
|
|
ToRetain =
|
|
|
|
to_retain({SQN, Type, PK},
|
|
|
|
FilterFun,
|
|
|
|
FilterServer,
|
|
|
|
MaxSQN,
|
|
|
|
ReloadStrategy),
|
|
|
|
case ToRetain of
|
2019-07-24 18:03:22 +01:00
|
|
|
true ->
|
2020-11-29 15:43:29 +00:00
|
|
|
{ActSize + Size - ?CRC_SIZE, RplSize};
|
|
|
|
convert ->
|
2020-12-04 14:31:47 +00:00
|
|
|
{ActSize, RplSize + Size - ?CRC_SIZE};
|
2020-11-29 15:43:29 +00:00
|
|
|
false ->
|
|
|
|
{ActSize, RplSize + Size - ?CRC_SIZE}
|
2016-12-11 06:53:25 +00:00
|
|
|
end;
|
|
|
|
_ ->
|
2017-11-09 12:42:49 +00:00
|
|
|
% There is a key which is not in expected format
|
|
|
|
% Not that the key-size list has been filtered for
|
|
|
|
% errors by leveled_cdb - but this doesn't know the
|
|
|
|
% expected format of the key
|
2016-12-11 06:53:25 +00:00
|
|
|
{ActSize, RplSize}
|
|
|
|
end
|
2020-03-09 15:12:48 +00:00
|
|
|
end,
|
2016-12-11 06:53:25 +00:00
|
|
|
|
|
|
|
R0 = lists:foldl(FoldFunForSizeCompare, {0, 0}, KeySizeList),
|
2016-09-26 10:55:08 +01:00
|
|
|
{ActiveSize, ReplacedSize} = R0,
|
2017-11-09 12:42:49 +00:00
|
|
|
case ActiveSize + ReplacedSize of
|
|
|
|
0 ->
|
2020-03-09 17:45:06 +00:00
|
|
|
0.0;
|
2017-11-09 12:42:49 +00:00
|
|
|
_ ->
|
|
|
|
100 * ActiveSize / (ActiveSize + ReplacedSize)
|
|
|
|
end.
|
2016-09-26 10:55:08 +01:00
|
|
|
|
|
|
|
|
2019-07-19 13:30:53 +01:00
|
|
|
fetch_inbatches([], _BatchSize, CDB, CheckedList) ->
|
|
|
|
ok = leveled_cdb:cdb_clerkcomplete(CDB),
|
2016-09-21 18:31:42 +01:00
|
|
|
CheckedList;
|
|
|
|
fetch_inbatches(PositionList, BatchSize, CDB, CheckedList) ->
|
2020-03-15 22:14:42 +00:00
|
|
|
{Batch, Tail} =
|
|
|
|
if
|
|
|
|
length(PositionList) >= BatchSize ->
|
|
|
|
lists:split(BatchSize, PositionList);
|
|
|
|
true ->
|
|
|
|
{PositionList, []}
|
|
|
|
end,
|
2016-09-27 14:58:26 +01:00
|
|
|
KL_List = leveled_cdb:cdb_directfetch(CDB, Batch, key_size),
|
2016-09-21 18:31:42 +01:00
|
|
|
fetch_inbatches(Tail, BatchSize, CDB, CheckedList ++ KL_List).
|
|
|
|
|
2017-06-02 08:37:57 +01:00
|
|
|
|
2018-09-26 14:07:44 +01:00
|
|
|
-spec assess_candidates(list(candidate()), score_parameters())
|
2018-09-26 12:56:28 +01:00
|
|
|
-> {list(candidate()), float()}.
|
|
|
|
%% @doc
|
2018-09-26 14:07:44 +01:00
|
|
|
%% For each run length we need to assess all the possible runs of candidates,
|
|
|
|
%% to determine which is the best score - to be put forward as the best
|
|
|
|
%% candidate run for compaction.
|
|
|
|
%%
|
2018-09-26 12:56:28 +01:00
|
|
|
%% Although this requires many loops over the list of the candidate, as the
|
|
|
|
%% file scores have already been calculated the cost per loop should not be
|
|
|
|
%% a high burden. Reducing the maximum run length, will reduce the cost of
|
2018-09-26 14:07:44 +01:00
|
|
|
%% this exercise should be a problem.
|
|
|
|
%%
|
|
|
|
%% The score parameters are used to produce the score of the compaction run,
|
|
|
|
%% with a higher score being better. The parameters are the maximum run
|
|
|
|
%% length and the compaction targets (for max run length and single file).
|
|
|
|
%% The score of an individual file is the approximate percentage of the space
|
|
|
|
%% that would be retained after compaction (e.g. 100 less the percentage of
|
|
|
|
%% space wasted by historic objects).
|
|
|
|
%%
|
|
|
|
%% So a file score of 60% indicates that 40% of the space would be
|
|
|
|
%% reclaimed following compaction. A single file target of 50% would not be
|
|
|
|
%% met for this file. However, if there are 4 consecutive files scoring 60%,
|
|
|
|
%% and the maximum run length is 4, and the maximum run length compaction
|
|
|
|
%% target is 70% - then this run of four files would be a viable candidate
|
|
|
|
%% for compaction.
|
2017-06-02 08:37:57 +01:00
|
|
|
assess_candidates(AllCandidates, Params) ->
|
2018-09-26 12:56:28 +01:00
|
|
|
MaxRunLength = min(element(1, Params), length(AllCandidates)),
|
|
|
|
NaiveBestRun = lists:sublist(AllCandidates, MaxRunLength),
|
2018-09-26 14:11:02 +01:00
|
|
|
% This will end up being scored twice, but lets take a guess at
|
|
|
|
% the best scoring run to take into the loop
|
2018-09-26 12:56:28 +01:00
|
|
|
FoldFun =
|
|
|
|
fun(RunLength, Best) ->
|
|
|
|
assess_for_runlength(RunLength, AllCandidates, Params, Best)
|
|
|
|
end,
|
|
|
|
% Check all run lengths to find the best candidate. Reverse the list of
|
|
|
|
% run lengths, so that longer runs win on equality of score
|
|
|
|
lists:foldl(FoldFun,
|
|
|
|
{NaiveBestRun, score_run(NaiveBestRun, Params)},
|
|
|
|
lists:reverse(lists:seq(1, MaxRunLength))).
|
|
|
|
|
|
|
|
|
2018-09-26 14:07:44 +01:00
|
|
|
-spec assess_for_runlength(integer(), list(candidate()), score_parameters(),
|
|
|
|
{list(candidate()), float()})
|
|
|
|
-> {list(candidate()), float()}.
|
|
|
|
%% @doc
|
|
|
|
%% For a given run length, calculate the scores for all consecutive runs of
|
|
|
|
%% files, comparing the score with the best run which has beens een so far.
|
|
|
|
%% The best is a tuple of the actual run of candidates, along with the score
|
|
|
|
%% achieved for that run
|
2018-09-26 12:56:28 +01:00
|
|
|
assess_for_runlength(RunLength, AllCandidates, Params, Best) ->
|
|
|
|
NumberOfRuns = 1 + length(AllCandidates) - RunLength,
|
|
|
|
FoldFun =
|
|
|
|
fun(Offset, {BestRun, BestScore}) ->
|
|
|
|
Run = lists:sublist(AllCandidates, Offset, RunLength),
|
|
|
|
Score = score_run(Run, Params),
|
|
|
|
case Score > BestScore of
|
|
|
|
true -> {Run, Score};
|
|
|
|
false -> {BestRun, BestScore}
|
2016-09-27 14:58:26 +01:00
|
|
|
end
|
2018-09-26 12:56:28 +01:00
|
|
|
end,
|
|
|
|
lists:foldl(FoldFun, Best, lists:seq(1, NumberOfRuns)).
|
2017-06-02 08:37:57 +01:00
|
|
|
|
2018-07-23 12:46:42 +01:00
|
|
|
|
2018-09-26 14:07:44 +01:00
|
|
|
-spec score_run(list(candidate()), score_parameters()) -> float().
|
|
|
|
%% @doc
|
|
|
|
%% Score a run. Caluclate the avergae score across all the files in the run,
|
|
|
|
%% and deduct that from a target score. Good candidate runs for comapction
|
|
|
|
%% have larger (positive) scores. Bad candidate runs for compaction have
|
|
|
|
%% negative scores.
|
2017-06-02 08:37:57 +01:00
|
|
|
score_run([], _Params) ->
|
2016-09-27 14:58:26 +01:00
|
|
|
0.0;
|
2017-06-02 08:37:57 +01:00
|
|
|
score_run(Run, {MaxRunLength, MR_CT, SF_CT}) ->
|
|
|
|
TargetIncr =
|
|
|
|
case MaxRunLength of
|
|
|
|
1 ->
|
|
|
|
0.0;
|
|
|
|
MaxRunSize ->
|
|
|
|
(MR_CT - SF_CT) / (MaxRunSize - 1)
|
|
|
|
end,
|
|
|
|
Target = SF_CT + TargetIncr * (length(Run) - 1),
|
2016-09-27 14:58:26 +01:00
|
|
|
RunTotal = lists:foldl(fun(Cand, Acc) ->
|
|
|
|
Acc + Cand#candidate.compaction_perc end,
|
|
|
|
0.0,
|
|
|
|
Run),
|
|
|
|
Target - RunTotal / length(Run).
|
|
|
|
|
2016-09-26 10:55:08 +01:00
|
|
|
|
2018-07-23 12:46:42 +01:00
|
|
|
print_compaction_run(BestRun, ScoreParams) ->
|
Develop 3.1 d30update (#386)
* Mas i370 patch d (#383)
* Refactor penciller memory
In high-volume tests on large key-count clusters, so significant variation in the P0031 time has been seen:
TimeBucket PatchA
a.0ms_to_1ms 18554
b.1ms_to_2ms 51778
c.2ms_to_3ms 696
d.3ms_to_5ms 220
e.5ms_to_8ms 59
f.8ms_to_13ms 40
g.13ms_to_21ms 364
h.21ms_to_34ms 277
i.34ms_to_55ms 34
j.55ms_to_89ms 17
k.89ms_to_144ms 21
l.144ms_to_233ms 31
m.233ms_to_377ms 45
n.377ms_to_610ms 52
o.610ms_to_987ms 59
p.987ms_to_1597ms 55
q.1597ms_to_2684ms 54
r.2684ms_to_4281ms 29
s.4281ms_to_6965ms 7
t.6295ms_to_11246ms 1
It is unclear why this varies so much. The time to add to the cache appears to be minimal (but perhaps there is an issue with timing points in the code), whereas the time to add to the index is much more significant and variable. There is also variable time when the memory is rolled (although the actual activity here appears to be minimal.
The refactoring here is two-fold:
- tidy and simplify by keeping LoopState managed within handle_call, and add more helpful dialyzer specs;
- change the update to the index to be a simple extension of a list, rather than any conversion.
This alternative version of the pmem index in unit test is orders of magnitude faster to add - and is the same order of magnitude to check. Anticipation is that it may be more efficient in terms of memory changes.
* Compress SST index
Reduces the size of the leveled_sst index with two changes:
1 - Where there is a common prefix of tuple elements (e.g. Bucket) across the whole leveled_sst file - only the non-common part is indexed, and a function is used to compare.
2 - There is less "indexing" of the index i.e. only 1 in 16 keys are passed into the gb_trees part instead of 1 in 4
* Immediate hibernate
Reasons for delay in hibernate were not clear.
Straight after creation the process will not be in receipt of messages (must wait for the manifest to be updated), so better to hibernate now. This also means the log PC023 provides more accurate information.
* Refactor BIC
This patch avoids the following:
- repeated replacement of the same element in the BIC (via get_kvrange), by checking presence via GET before sing SET
- Stops re-reading of all elements to discover high modified date
Also there appears to have been a bug where a missing HMD for the file is required to add to the cache. However, now the cache may be erased without erasing the HMD. This means that the cache can never be rebuilt
* Use correct size in test results
erts_debug:flat_size/1 returns size in words (i.e. 8 bytes on 64-bit CPU) not bytes
* Don't change summary record
As it is persisted as part of the file write, any change to the summary record cannot be rolled back
* Clerk to prompt L0 write
Simplifies the logic if the clerk request work for the penciller prompts L0 writes as well as Manifest changes.
The advantage now is that if the penciller memory is full, and PUT load stops, the clerk should still be able to prompt persistence. the penciller can therefore make use of dead time this way
* Add push on journal compact
If there has been a backlog, followed by a quiet period - there may be a large ledger cache left unpushed. Journal compaction events are about once per hour, so the performance overhead of a false push should be minimal, with the advantage of clearing any backlog before load starts again.
This is only relevant to riak users with very off/full batch type workloads.
* Extend tests
To more consistently trigger all overload scenarios
* Fix range keys smaller than prefix
Can't make end key an empty binary in this case, as it may be bigger than any keys within the range, but will appear to be smaller.
Unit tests and ct tests added to expose the potential issue
* Tidy-up
- Remove penciller logs which are no longer called
- Get pclerk to only wait MIN_TIMEOUT after doing work, in case there is a backlog
- Remove update_levelzero_cache function as it is unique to handle_call of push_mem, and simple enough to be inline
- Alight testutil slow offer with standard slow offer used
* Tidy-up
Remove pre-otp20 references.
Reinstate the check that the starting pid is still active, this was added to tidy up shutdown.
Resolve failure to run on otp20 due to `-if` sttaement
* Tidy up
Using null rather then {null, Key} is potentially clearer as it is not a concern what they Key is in this case, and removes a comparison step from the leveled_codec:endkey_passed/2 function.
There were issues with coverage in eunit tests as the leveled_pclerk shut down. This prompted a general tidy of leveled_pclerk (remove passing of LoopState into internal functions, and add dialyzer specs.
* Remove R16 relic
* Further testing another issue
The StartKey must always be less than or equal to the prefix when the first N characters are stripped, but this is not true of the EndKey (for the query) which does not have to be between the FirstKey and the LastKey.
If the EndKey query does not match it must be greater than the Prefix (as otherwise it would not have been greater than the FirstKey - so set to null.
* Fix unit test
Unit test had a typo - and result interpretation had a misunderstanding.
* Code and spec tidy
Also look to the cover the situation when the FirstKey is the same as the Prefix with tests.
This is, in theory, not an issue as it is the EndKey for each sublist which is indexed in leveled_tree. However, guard against it mapping to null here, just in case there are dangers lurking (note that tests will still pass without `M > N` guard in place.
* Hibernate on BIC complete
There are three situations when the BIC becomes complete:
- In a file created as part of a merge the BIS is learned in the merge
- After startup, files below L1 learn the block cache through reads that happen to read the block, eventually the while cache will be read, unless...
- Either before/after the cache is complete, it can get whiped by a timeout after a get_sqn request (e.g. as prompted by a journal compaction) ... it will then be re-filled of the back of get/get-range requests.
In all these situations we want to hibernate after the BIC is fill - to reflect the fact that the LoopState should now be relatively stable, so it is a good point to GC and rationalise location of data.
Previously on the the first base was covered. Now all three are covered through the bic_complete message.
* Test all index keys have same term
This works functionally, but is not optimised (the term is replicated in the index)
* Summaries with same index term
If the summary index all have the same index term - only the object keys need to be indexes
* Simplify case statements
We either match the pattern of <<Prefix:N, Suffix>> or the answer should be null
* OK for M == N
If M = N for the first key, it will have a suffix of <<>>. This will match (as expected) a query Start Key of the sam size, and be smaller than any query Start Key that has the same prefix.
If the query Start Key does not match the prefix - it will be null - as it must be smaller than the Prefix (as other wise the query Start Key would be bigger than the Last Key).
The constraint of M > N was introduced before the *_prefix_filter functions were checking the prefix, to avoid issues. Now the prefix is being checked, then M == N is ok.
* Simplify
Correct the test to use a binary field in the range.
To avoid further issue, only apply filter when everything is a binary() type.
* Add test for head_only mode
When leveled is used as a tictacaae key store (in parallel mode), the keys will be head_only entries. Double check they are handled as expected like object keys
* Revert previous change - must support typed buckets
Add assertion to confirm worthwhile optimisation
* Add support for configurable cache multiple (#375)
* Mas i370 patch e (#385)
Improvement to monitoring for efficiency and improved readability of logs and stats.
As part of this, where possible, tried to avoid updating loop state on READ messages in leveled processes (as was the case when tracking stats within each process).
No performance benefits found with change, but improved stats has helped discover other potential gains.
2022-12-18 20:18:03 +00:00
|
|
|
leveled_log:log(
|
|
|
|
ic005, [length(BestRun), score_run(BestRun, ScoreParams)]),
|
|
|
|
lists:foreach(
|
|
|
|
fun(File) ->
|
|
|
|
leveled_log:log(ic006, [File#candidate.filename])
|
|
|
|
end,
|
|
|
|
BestRun).
|
2016-09-26 10:55:08 +01:00
|
|
|
|
2016-10-27 00:57:19 +01:00
|
|
|
sort_run(RunOfFiles) ->
|
|
|
|
CompareFun = fun(Cand1, Cand2) ->
|
|
|
|
Cand1#candidate.low_sqn =< Cand2#candidate.low_sqn end,
|
|
|
|
lists:sort(CompareFun, RunOfFiles).
|
|
|
|
|
2017-11-06 21:16:46 +00:00
|
|
|
compact_files(BestRun, CDBopts, FilterFun, FilterServer,
|
|
|
|
MaxSQN, RStrategy, PressMethod) ->
|
2016-09-27 14:58:26 +01:00
|
|
|
BatchesOfPositions = get_all_positions(BestRun, []),
|
|
|
|
compact_files(BatchesOfPositions,
|
|
|
|
CDBopts,
|
|
|
|
null,
|
|
|
|
FilterFun,
|
|
|
|
FilterServer,
|
2016-10-05 18:28:31 +01:00
|
|
|
MaxSQN,
|
2016-10-25 23:13:14 +01:00
|
|
|
RStrategy,
|
2017-11-06 21:16:46 +00:00
|
|
|
PressMethod,
|
2016-11-14 11:40:02 +00:00
|
|
|
[]).
|
2016-09-20 16:13:36 +01:00
|
|
|
|
2016-09-28 18:26:52 +01:00
|
|
|
|
2016-10-05 18:28:31 +01:00
|
|
|
compact_files([], _CDBopts, null, _FilterFun, _FilterServer, _MaxSQN,
|
2017-11-06 21:16:46 +00:00
|
|
|
_RStrategy, _PressMethod, ManSlice0) ->
|
2016-11-14 11:40:02 +00:00
|
|
|
ManSlice0;
|
2016-10-05 18:28:31 +01:00
|
|
|
compact_files([], _CDBopts, ActiveJournal0, _FilterFun, _FilterServer, _MaxSQN,
|
2017-11-06 21:16:46 +00:00
|
|
|
_RStrategy, _PressMethod, ManSlice0) ->
|
2017-01-17 16:30:04 +00:00
|
|
|
ManSlice1 = ManSlice0 ++ leveled_imanifest:generate_entry(ActiveJournal0),
|
2016-11-14 11:40:02 +00:00
|
|
|
ManSlice1;
|
2016-10-05 18:28:31 +01:00
|
|
|
compact_files([Batch|T], CDBopts, ActiveJournal0,
|
|
|
|
FilterFun, FilterServer, MaxSQN,
|
2017-11-06 21:16:46 +00:00
|
|
|
RStrategy, PressMethod, ManSlice0) ->
|
2016-09-27 14:58:26 +01:00
|
|
|
{SrcJournal, PositionList} = Batch,
|
|
|
|
KVCs0 = leveled_cdb:cdb_directfetch(SrcJournal,
|
|
|
|
PositionList,
|
|
|
|
key_value_check),
|
2016-11-14 11:40:02 +00:00
|
|
|
KVCs1 = filter_output(KVCs0,
|
|
|
|
FilterFun,
|
|
|
|
FilterServer,
|
|
|
|
MaxSQN,
|
|
|
|
RStrategy),
|
2016-09-27 14:58:26 +01:00
|
|
|
{ActiveJournal1, ManSlice1} = write_values(KVCs1,
|
|
|
|
CDBopts,
|
|
|
|
ActiveJournal0,
|
2017-11-06 21:16:46 +00:00
|
|
|
ManSlice0,
|
|
|
|
PressMethod),
|
2019-07-19 13:30:53 +01:00
|
|
|
% The inker's clerk will no longer need these (potentially large) binaries,
|
|
|
|
% so force garbage collection at this point. This will mean when we roll
|
|
|
|
% each CDB file there will be no remaining references to the binaries that
|
|
|
|
% have been transferred and the memory can immediately be cleared
|
|
|
|
garbage_collect(),
|
2016-10-05 18:28:31 +01:00
|
|
|
compact_files(T, CDBopts, ActiveJournal1, FilterFun, FilterServer, MaxSQN,
|
2017-11-06 21:16:46 +00:00
|
|
|
RStrategy, PressMethod, ManSlice1).
|
2016-09-27 14:58:26 +01:00
|
|
|
|
|
|
|
get_all_positions([], PositionBatches) ->
|
|
|
|
PositionBatches;
|
|
|
|
get_all_positions([HeadRef|RestOfBest], PositionBatches) ->
|
|
|
|
SrcJournal = HeadRef#candidate.journal,
|
|
|
|
Positions = leveled_cdb:cdb_getpositions(SrcJournal, all),
|
Develop 3.1 d30update (#386)
* Mas i370 patch d (#383)
* Refactor penciller memory
In high-volume tests on large key-count clusters, so significant variation in the P0031 time has been seen:
TimeBucket PatchA
a.0ms_to_1ms 18554
b.1ms_to_2ms 51778
c.2ms_to_3ms 696
d.3ms_to_5ms 220
e.5ms_to_8ms 59
f.8ms_to_13ms 40
g.13ms_to_21ms 364
h.21ms_to_34ms 277
i.34ms_to_55ms 34
j.55ms_to_89ms 17
k.89ms_to_144ms 21
l.144ms_to_233ms 31
m.233ms_to_377ms 45
n.377ms_to_610ms 52
o.610ms_to_987ms 59
p.987ms_to_1597ms 55
q.1597ms_to_2684ms 54
r.2684ms_to_4281ms 29
s.4281ms_to_6965ms 7
t.6295ms_to_11246ms 1
It is unclear why this varies so much. The time to add to the cache appears to be minimal (but perhaps there is an issue with timing points in the code), whereas the time to add to the index is much more significant and variable. There is also variable time when the memory is rolled (although the actual activity here appears to be minimal.
The refactoring here is two-fold:
- tidy and simplify by keeping LoopState managed within handle_call, and add more helpful dialyzer specs;
- change the update to the index to be a simple extension of a list, rather than any conversion.
This alternative version of the pmem index in unit test is orders of magnitude faster to add - and is the same order of magnitude to check. Anticipation is that it may be more efficient in terms of memory changes.
* Compress SST index
Reduces the size of the leveled_sst index with two changes:
1 - Where there is a common prefix of tuple elements (e.g. Bucket) across the whole leveled_sst file - only the non-common part is indexed, and a function is used to compare.
2 - There is less "indexing" of the index i.e. only 1 in 16 keys are passed into the gb_trees part instead of 1 in 4
* Immediate hibernate
Reasons for delay in hibernate were not clear.
Straight after creation the process will not be in receipt of messages (must wait for the manifest to be updated), so better to hibernate now. This also means the log PC023 provides more accurate information.
* Refactor BIC
This patch avoids the following:
- repeated replacement of the same element in the BIC (via get_kvrange), by checking presence via GET before sing SET
- Stops re-reading of all elements to discover high modified date
Also there appears to have been a bug where a missing HMD for the file is required to add to the cache. However, now the cache may be erased without erasing the HMD. This means that the cache can never be rebuilt
* Use correct size in test results
erts_debug:flat_size/1 returns size in words (i.e. 8 bytes on 64-bit CPU) not bytes
* Don't change summary record
As it is persisted as part of the file write, any change to the summary record cannot be rolled back
* Clerk to prompt L0 write
Simplifies the logic if the clerk request work for the penciller prompts L0 writes as well as Manifest changes.
The advantage now is that if the penciller memory is full, and PUT load stops, the clerk should still be able to prompt persistence. the penciller can therefore make use of dead time this way
* Add push on journal compact
If there has been a backlog, followed by a quiet period - there may be a large ledger cache left unpushed. Journal compaction events are about once per hour, so the performance overhead of a false push should be minimal, with the advantage of clearing any backlog before load starts again.
This is only relevant to riak users with very off/full batch type workloads.
* Extend tests
To more consistently trigger all overload scenarios
* Fix range keys smaller than prefix
Can't make end key an empty binary in this case, as it may be bigger than any keys within the range, but will appear to be smaller.
Unit tests and ct tests added to expose the potential issue
* Tidy-up
- Remove penciller logs which are no longer called
- Get pclerk to only wait MIN_TIMEOUT after doing work, in case there is a backlog
- Remove update_levelzero_cache function as it is unique to handle_call of push_mem, and simple enough to be inline
- Alight testutil slow offer with standard slow offer used
* Tidy-up
Remove pre-otp20 references.
Reinstate the check that the starting pid is still active, this was added to tidy up shutdown.
Resolve failure to run on otp20 due to `-if` sttaement
* Tidy up
Using null rather then {null, Key} is potentially clearer as it is not a concern what they Key is in this case, and removes a comparison step from the leveled_codec:endkey_passed/2 function.
There were issues with coverage in eunit tests as the leveled_pclerk shut down. This prompted a general tidy of leveled_pclerk (remove passing of LoopState into internal functions, and add dialyzer specs.
* Remove R16 relic
* Further testing another issue
The StartKey must always be less than or equal to the prefix when the first N characters are stripped, but this is not true of the EndKey (for the query) which does not have to be between the FirstKey and the LastKey.
If the EndKey query does not match it must be greater than the Prefix (as otherwise it would not have been greater than the FirstKey - so set to null.
* Fix unit test
Unit test had a typo - and result interpretation had a misunderstanding.
* Code and spec tidy
Also look to the cover the situation when the FirstKey is the same as the Prefix with tests.
This is, in theory, not an issue as it is the EndKey for each sublist which is indexed in leveled_tree. However, guard against it mapping to null here, just in case there are dangers lurking (note that tests will still pass without `M > N` guard in place.
* Hibernate on BIC complete
There are three situations when the BIC becomes complete:
- In a file created as part of a merge the BIS is learned in the merge
- After startup, files below L1 learn the block cache through reads that happen to read the block, eventually the while cache will be read, unless...
- Either before/after the cache is complete, it can get whiped by a timeout after a get_sqn request (e.g. as prompted by a journal compaction) ... it will then be re-filled of the back of get/get-range requests.
In all these situations we want to hibernate after the BIC is fill - to reflect the fact that the LoopState should now be relatively stable, so it is a good point to GC and rationalise location of data.
Previously on the the first base was covered. Now all three are covered through the bic_complete message.
* Test all index keys have same term
This works functionally, but is not optimised (the term is replicated in the index)
* Summaries with same index term
If the summary index all have the same index term - only the object keys need to be indexes
* Simplify case statements
We either match the pattern of <<Prefix:N, Suffix>> or the answer should be null
* OK for M == N
If M = N for the first key, it will have a suffix of <<>>. This will match (as expected) a query Start Key of the sam size, and be smaller than any query Start Key that has the same prefix.
If the query Start Key does not match the prefix - it will be null - as it must be smaller than the Prefix (as other wise the query Start Key would be bigger than the Last Key).
The constraint of M > N was introduced before the *_prefix_filter functions were checking the prefix, to avoid issues. Now the prefix is being checked, then M == N is ok.
* Simplify
Correct the test to use a binary field in the range.
To avoid further issue, only apply filter when everything is a binary() type.
* Add test for head_only mode
When leveled is used as a tictacaae key store (in parallel mode), the keys will be head_only entries. Double check they are handled as expected like object keys
* Revert previous change - must support typed buckets
Add assertion to confirm worthwhile optimisation
* Add support for configurable cache multiple (#375)
* Mas i370 patch e (#385)
Improvement to monitoring for efficiency and improved readability of logs and stats.
As part of this, where possible, tried to avoid updating loop state on READ messages in leveled processes (as was the case when tracking stats within each process).
No performance benefits found with change, but improved stats has helped discover other potential gains.
2022-12-18 20:18:03 +00:00
|
|
|
leveled_log:log(ic008, [HeadRef#candidate.filename, length(Positions)]),
|
2016-09-28 11:41:56 +01:00
|
|
|
Batches = split_positions_into_batches(lists:sort(Positions),
|
|
|
|
SrcJournal,
|
|
|
|
[]),
|
2016-09-27 14:58:26 +01:00
|
|
|
get_all_positions(RestOfBest, PositionBatches ++ Batches).
|
|
|
|
|
|
|
|
split_positions_into_batches([], _Journal, Batches) ->
|
|
|
|
Batches;
|
|
|
|
split_positions_into_batches(Positions, Journal, Batches) ->
|
2016-09-28 11:41:56 +01:00
|
|
|
{ThisBatch, Tail} = if
|
|
|
|
length(Positions) > ?BATCH_SIZE ->
|
|
|
|
lists:split(?BATCH_SIZE, Positions);
|
|
|
|
true ->
|
|
|
|
{Positions, []}
|
|
|
|
end,
|
2016-09-27 14:58:26 +01:00
|
|
|
split_positions_into_batches(Tail,
|
|
|
|
Journal,
|
|
|
|
Batches ++ [{Journal, ThisBatch}]).
|
|
|
|
|
|
|
|
|
2018-12-06 22:45:05 +00:00
|
|
|
%% @doc
|
|
|
|
%% For the Keys and values taken from the Journal file, which are required
|
|
|
|
%% in the compacted journal file. To be required, they must still be active
|
|
|
|
%% (i.e. be the current SQN for that LedgerKey in the Ledger). However, if
|
|
|
|
%% it is not active, we still need to retain some information if for this
|
|
|
|
%% object tag we want to be able to rebuild the KeyStore by relaoding the
|
|
|
|
%% KeyDeltas (the retain reload strategy)
|
|
|
|
%%
|
|
|
|
%% If the reload strategy is recalc, we assume that we can reload by
|
|
|
|
%% recalculating the KeyChanges by looking at the object when we reload. So
|
|
|
|
%% old objects can be discarded.
|
|
|
|
%%
|
2020-03-26 14:25:09 +00:00
|
|
|
%% If the strategy is recovr, we don't care about KeyDeltas. Note though, that
|
2018-12-06 22:45:05 +00:00
|
|
|
%% if the ledger is deleted it may not be possible to safely rebuild a KeyStore
|
|
|
|
%% if it contains index entries. The hot_backup approach is also not safe with
|
2020-03-26 14:25:09 +00:00
|
|
|
%% a `recovr` strategy. The recovr strategy assumes faults in the ledger will
|
|
|
|
%% be resolved via application-level anti-entropy
|
2020-11-29 15:43:29 +00:00
|
|
|
filter_output(KVCs, FilterFun, FilterServer, MaxSQN, Strategy) ->
|
2018-12-06 22:45:05 +00:00
|
|
|
FoldFun =
|
2020-11-29 15:43:29 +00:00
|
|
|
filter_output_fun(FilterFun, FilterServer, MaxSQN, Strategy),
|
2018-12-06 22:45:05 +00:00
|
|
|
lists:reverse(lists:foldl(FoldFun, [], KVCs)).
|
|
|
|
|
2016-09-27 14:58:26 +01:00
|
|
|
|
2020-11-29 15:43:29 +00:00
|
|
|
filter_output_fun(FilterFun, FilterServer, MaxSQN, Strategy) ->
|
2020-03-09 15:12:48 +00:00
|
|
|
fun(KVC0, Acc) ->
|
|
|
|
case KVC0 of
|
|
|
|
{_InkKey, crc_wonky, false} ->
|
|
|
|
% Bad entry, disregard, don't check
|
|
|
|
Acc;
|
|
|
|
{JK, JV, _Check} ->
|
2020-11-29 15:43:29 +00:00
|
|
|
ToRetain =
|
|
|
|
to_retain(JK, FilterFun, FilterServer, MaxSQN, Strategy),
|
|
|
|
case ToRetain of
|
|
|
|
true ->
|
2020-03-09 15:12:48 +00:00
|
|
|
[KVC0|Acc];
|
2020-11-29 15:43:29 +00:00
|
|
|
convert ->
|
|
|
|
{JK0, JV0} =
|
|
|
|
leveled_codec:revert_to_keydeltas(JK, JV),
|
|
|
|
[{JK0, JV0, null}|Acc];
|
|
|
|
false ->
|
|
|
|
Acc
|
2020-03-09 15:12:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
2020-11-29 15:43:29 +00:00
|
|
|
-spec to_retain(leveled_codec:journal_key(),
|
|
|
|
leveled_inker:filterfun(),
|
2023-03-14 16:27:08 +00:00
|
|
|
leveled_inker:filterserver(),
|
2020-11-29 15:43:29 +00:00
|
|
|
leveled_codec:sqn(),
|
|
|
|
leveled_codec:compaction_strategy()) -> boolean()|convert.
|
|
|
|
to_retain(JournalKey, FilterFun, FilterServer, MaxSQN, ReloadStrategy) ->
|
|
|
|
{SQN, LK} =
|
|
|
|
leveled_codec:from_journalkey(JournalKey),
|
|
|
|
CompactStrategy =
|
|
|
|
leveled_codec:get_tagstrategy(LK, ReloadStrategy),
|
|
|
|
IsJournalEntry =
|
|
|
|
leveled_codec:is_full_journalentry(JournalKey),
|
|
|
|
case {CompactStrategy, IsJournalEntry} of
|
|
|
|
{retain, false} ->
|
|
|
|
true;
|
|
|
|
_ ->
|
|
|
|
KeyCurrent = FilterFun(FilterServer, LK, SQN),
|
|
|
|
IsInMemory = SQN > MaxSQN,
|
|
|
|
case {KeyCurrent, IsInMemory, CompactStrategy} of
|
|
|
|
{KC, InMem, _} when KC == current; InMem ->
|
|
|
|
% This entry may still be required
|
|
|
|
% regardless of strategy
|
|
|
|
true;
|
|
|
|
{_, _, retain} ->
|
|
|
|
% If we have a retain strategy, it can't be
|
|
|
|
% discarded - but the value part is no
|
|
|
|
% longer required as this version has been
|
|
|
|
% replaced
|
|
|
|
convert;
|
|
|
|
{_, _, _} ->
|
|
|
|
% This is out of date and not retained so
|
|
|
|
% discard
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
|
2017-11-06 21:16:46 +00:00
|
|
|
write_values([], _CDBopts, Journal0, ManSlice0, _PressMethod) ->
|
2016-09-28 11:41:56 +01:00
|
|
|
{Journal0, ManSlice0};
|
2017-11-06 21:16:46 +00:00
|
|
|
write_values(KVCList, CDBopts, Journal0, ManSlice0, PressMethod) ->
|
2019-07-26 21:43:00 +01:00
|
|
|
KVList =
|
|
|
|
lists:map(fun({K, V, _C}) ->
|
2017-03-20 15:43:54 +00:00
|
|
|
% Compress the value as part of compaction
|
2019-07-26 21:43:00 +01:00
|
|
|
{K, leveled_codec:maybe_compress(V, PressMethod)}
|
|
|
|
end,
|
|
|
|
KVCList),
|
|
|
|
{ok, Journal1} =
|
|
|
|
case Journal0 of
|
|
|
|
null ->
|
|
|
|
{TK, _TV} = lists:nth(1, KVList),
|
|
|
|
{SQN, _LK} = leveled_codec:from_journalkey(TK),
|
|
|
|
FP = CDBopts#cdb_options.file_path,
|
|
|
|
FN = leveled_inker:filepath(FP, SQN, compact_journal),
|
Develop 3.1 d30update (#386)
* Mas i370 patch d (#383)
* Refactor penciller memory
In high-volume tests on large key-count clusters, so significant variation in the P0031 time has been seen:
TimeBucket PatchA
a.0ms_to_1ms 18554
b.1ms_to_2ms 51778
c.2ms_to_3ms 696
d.3ms_to_5ms 220
e.5ms_to_8ms 59
f.8ms_to_13ms 40
g.13ms_to_21ms 364
h.21ms_to_34ms 277
i.34ms_to_55ms 34
j.55ms_to_89ms 17
k.89ms_to_144ms 21
l.144ms_to_233ms 31
m.233ms_to_377ms 45
n.377ms_to_610ms 52
o.610ms_to_987ms 59
p.987ms_to_1597ms 55
q.1597ms_to_2684ms 54
r.2684ms_to_4281ms 29
s.4281ms_to_6965ms 7
t.6295ms_to_11246ms 1
It is unclear why this varies so much. The time to add to the cache appears to be minimal (but perhaps there is an issue with timing points in the code), whereas the time to add to the index is much more significant and variable. There is also variable time when the memory is rolled (although the actual activity here appears to be minimal.
The refactoring here is two-fold:
- tidy and simplify by keeping LoopState managed within handle_call, and add more helpful dialyzer specs;
- change the update to the index to be a simple extension of a list, rather than any conversion.
This alternative version of the pmem index in unit test is orders of magnitude faster to add - and is the same order of magnitude to check. Anticipation is that it may be more efficient in terms of memory changes.
* Compress SST index
Reduces the size of the leveled_sst index with two changes:
1 - Where there is a common prefix of tuple elements (e.g. Bucket) across the whole leveled_sst file - only the non-common part is indexed, and a function is used to compare.
2 - There is less "indexing" of the index i.e. only 1 in 16 keys are passed into the gb_trees part instead of 1 in 4
* Immediate hibernate
Reasons for delay in hibernate were not clear.
Straight after creation the process will not be in receipt of messages (must wait for the manifest to be updated), so better to hibernate now. This also means the log PC023 provides more accurate information.
* Refactor BIC
This patch avoids the following:
- repeated replacement of the same element in the BIC (via get_kvrange), by checking presence via GET before sing SET
- Stops re-reading of all elements to discover high modified date
Also there appears to have been a bug where a missing HMD for the file is required to add to the cache. However, now the cache may be erased without erasing the HMD. This means that the cache can never be rebuilt
* Use correct size in test results
erts_debug:flat_size/1 returns size in words (i.e. 8 bytes on 64-bit CPU) not bytes
* Don't change summary record
As it is persisted as part of the file write, any change to the summary record cannot be rolled back
* Clerk to prompt L0 write
Simplifies the logic if the clerk request work for the penciller prompts L0 writes as well as Manifest changes.
The advantage now is that if the penciller memory is full, and PUT load stops, the clerk should still be able to prompt persistence. the penciller can therefore make use of dead time this way
* Add push on journal compact
If there has been a backlog, followed by a quiet period - there may be a large ledger cache left unpushed. Journal compaction events are about once per hour, so the performance overhead of a false push should be minimal, with the advantage of clearing any backlog before load starts again.
This is only relevant to riak users with very off/full batch type workloads.
* Extend tests
To more consistently trigger all overload scenarios
* Fix range keys smaller than prefix
Can't make end key an empty binary in this case, as it may be bigger than any keys within the range, but will appear to be smaller.
Unit tests and ct tests added to expose the potential issue
* Tidy-up
- Remove penciller logs which are no longer called
- Get pclerk to only wait MIN_TIMEOUT after doing work, in case there is a backlog
- Remove update_levelzero_cache function as it is unique to handle_call of push_mem, and simple enough to be inline
- Alight testutil slow offer with standard slow offer used
* Tidy-up
Remove pre-otp20 references.
Reinstate the check that the starting pid is still active, this was added to tidy up shutdown.
Resolve failure to run on otp20 due to `-if` sttaement
* Tidy up
Using null rather then {null, Key} is potentially clearer as it is not a concern what they Key is in this case, and removes a comparison step from the leveled_codec:endkey_passed/2 function.
There were issues with coverage in eunit tests as the leveled_pclerk shut down. This prompted a general tidy of leveled_pclerk (remove passing of LoopState into internal functions, and add dialyzer specs.
* Remove R16 relic
* Further testing another issue
The StartKey must always be less than or equal to the prefix when the first N characters are stripped, but this is not true of the EndKey (for the query) which does not have to be between the FirstKey and the LastKey.
If the EndKey query does not match it must be greater than the Prefix (as otherwise it would not have been greater than the FirstKey - so set to null.
* Fix unit test
Unit test had a typo - and result interpretation had a misunderstanding.
* Code and spec tidy
Also look to the cover the situation when the FirstKey is the same as the Prefix with tests.
This is, in theory, not an issue as it is the EndKey for each sublist which is indexed in leveled_tree. However, guard against it mapping to null here, just in case there are dangers lurking (note that tests will still pass without `M > N` guard in place.
* Hibernate on BIC complete
There are three situations when the BIC becomes complete:
- In a file created as part of a merge the BIS is learned in the merge
- After startup, files below L1 learn the block cache through reads that happen to read the block, eventually the while cache will be read, unless...
- Either before/after the cache is complete, it can get whiped by a timeout after a get_sqn request (e.g. as prompted by a journal compaction) ... it will then be re-filled of the back of get/get-range requests.
In all these situations we want to hibernate after the BIC is fill - to reflect the fact that the LoopState should now be relatively stable, so it is a good point to GC and rationalise location of data.
Previously on the the first base was covered. Now all three are covered through the bic_complete message.
* Test all index keys have same term
This works functionally, but is not optimised (the term is replicated in the index)
* Summaries with same index term
If the summary index all have the same index term - only the object keys need to be indexes
* Simplify case statements
We either match the pattern of <<Prefix:N, Suffix>> or the answer should be null
* OK for M == N
If M = N for the first key, it will have a suffix of <<>>. This will match (as expected) a query Start Key of the sam size, and be smaller than any query Start Key that has the same prefix.
If the query Start Key does not match the prefix - it will be null - as it must be smaller than the Prefix (as other wise the query Start Key would be bigger than the Last Key).
The constraint of M > N was introduced before the *_prefix_filter functions were checking the prefix, to avoid issues. Now the prefix is being checked, then M == N is ok.
* Simplify
Correct the test to use a binary field in the range.
To avoid further issue, only apply filter when everything is a binary() type.
* Add test for head_only mode
When leveled is used as a tictacaae key store (in parallel mode), the keys will be head_only entries. Double check they are handled as expected like object keys
* Revert previous change - must support typed buckets
Add assertion to confirm worthwhile optimisation
* Add support for configurable cache multiple (#375)
* Mas i370 patch e (#385)
Improvement to monitoring for efficiency and improved readability of logs and stats.
As part of this, where possible, tried to avoid updating loop state on READ messages in leveled processes (as was the case when tracking stats within each process).
No performance benefits found with change, but improved stats has helped discover other potential gains.
2022-12-18 20:18:03 +00:00
|
|
|
leveled_log:log(ic009, [FN]),
|
2019-07-26 21:43:00 +01:00
|
|
|
leveled_cdb:cdb_open_writer(FN, CDBopts);
|
|
|
|
_ ->
|
|
|
|
{ok, Journal0}
|
|
|
|
end,
|
2016-10-26 11:39:27 +01:00
|
|
|
R = leveled_cdb:cdb_mput(Journal1, KVList),
|
2016-09-27 14:58:26 +01:00
|
|
|
case R of
|
|
|
|
ok ->
|
2016-10-26 11:39:27 +01:00
|
|
|
{Journal1, ManSlice0};
|
2016-09-27 14:58:26 +01:00
|
|
|
roll ->
|
2017-01-17 16:30:04 +00:00
|
|
|
ManSlice1 = ManSlice0 ++ leveled_imanifest:generate_entry(Journal1),
|
2017-11-06 21:16:46 +00:00
|
|
|
write_values(KVCList, CDBopts, null, ManSlice1, PressMethod)
|
2016-09-27 14:58:26 +01:00
|
|
|
end.
|
|
|
|
|
2016-11-14 11:17:14 +00:00
|
|
|
clear_waste(State) ->
|
2017-11-08 12:58:09 +00:00
|
|
|
case State#state.waste_path of
|
|
|
|
undefined ->
|
|
|
|
ok;
|
|
|
|
WP ->
|
|
|
|
WRP = State#state.waste_retention_period,
|
|
|
|
{ok, ClearedJournals} = file:list_dir(WP),
|
|
|
|
N = calendar:datetime_to_gregorian_seconds(calendar:local_time()),
|
|
|
|
DeleteJournalFun =
|
|
|
|
fun(DelJ) ->
|
|
|
|
LMD = filelib:last_modified(WP ++ DelJ),
|
|
|
|
case N - calendar:datetime_to_gregorian_seconds(LMD) of
|
|
|
|
LMD_Delta when LMD_Delta >= WRP ->
|
|
|
|
ok = file:delete(WP ++ DelJ),
|
Develop 3.1 d30update (#386)
* Mas i370 patch d (#383)
* Refactor penciller memory
In high-volume tests on large key-count clusters, so significant variation in the P0031 time has been seen:
TimeBucket PatchA
a.0ms_to_1ms 18554
b.1ms_to_2ms 51778
c.2ms_to_3ms 696
d.3ms_to_5ms 220
e.5ms_to_8ms 59
f.8ms_to_13ms 40
g.13ms_to_21ms 364
h.21ms_to_34ms 277
i.34ms_to_55ms 34
j.55ms_to_89ms 17
k.89ms_to_144ms 21
l.144ms_to_233ms 31
m.233ms_to_377ms 45
n.377ms_to_610ms 52
o.610ms_to_987ms 59
p.987ms_to_1597ms 55
q.1597ms_to_2684ms 54
r.2684ms_to_4281ms 29
s.4281ms_to_6965ms 7
t.6295ms_to_11246ms 1
It is unclear why this varies so much. The time to add to the cache appears to be minimal (but perhaps there is an issue with timing points in the code), whereas the time to add to the index is much more significant and variable. There is also variable time when the memory is rolled (although the actual activity here appears to be minimal.
The refactoring here is two-fold:
- tidy and simplify by keeping LoopState managed within handle_call, and add more helpful dialyzer specs;
- change the update to the index to be a simple extension of a list, rather than any conversion.
This alternative version of the pmem index in unit test is orders of magnitude faster to add - and is the same order of magnitude to check. Anticipation is that it may be more efficient in terms of memory changes.
* Compress SST index
Reduces the size of the leveled_sst index with two changes:
1 - Where there is a common prefix of tuple elements (e.g. Bucket) across the whole leveled_sst file - only the non-common part is indexed, and a function is used to compare.
2 - There is less "indexing" of the index i.e. only 1 in 16 keys are passed into the gb_trees part instead of 1 in 4
* Immediate hibernate
Reasons for delay in hibernate were not clear.
Straight after creation the process will not be in receipt of messages (must wait for the manifest to be updated), so better to hibernate now. This also means the log PC023 provides more accurate information.
* Refactor BIC
This patch avoids the following:
- repeated replacement of the same element in the BIC (via get_kvrange), by checking presence via GET before sing SET
- Stops re-reading of all elements to discover high modified date
Also there appears to have been a bug where a missing HMD for the file is required to add to the cache. However, now the cache may be erased without erasing the HMD. This means that the cache can never be rebuilt
* Use correct size in test results
erts_debug:flat_size/1 returns size in words (i.e. 8 bytes on 64-bit CPU) not bytes
* Don't change summary record
As it is persisted as part of the file write, any change to the summary record cannot be rolled back
* Clerk to prompt L0 write
Simplifies the logic if the clerk request work for the penciller prompts L0 writes as well as Manifest changes.
The advantage now is that if the penciller memory is full, and PUT load stops, the clerk should still be able to prompt persistence. the penciller can therefore make use of dead time this way
* Add push on journal compact
If there has been a backlog, followed by a quiet period - there may be a large ledger cache left unpushed. Journal compaction events are about once per hour, so the performance overhead of a false push should be minimal, with the advantage of clearing any backlog before load starts again.
This is only relevant to riak users with very off/full batch type workloads.
* Extend tests
To more consistently trigger all overload scenarios
* Fix range keys smaller than prefix
Can't make end key an empty binary in this case, as it may be bigger than any keys within the range, but will appear to be smaller.
Unit tests and ct tests added to expose the potential issue
* Tidy-up
- Remove penciller logs which are no longer called
- Get pclerk to only wait MIN_TIMEOUT after doing work, in case there is a backlog
- Remove update_levelzero_cache function as it is unique to handle_call of push_mem, and simple enough to be inline
- Alight testutil slow offer with standard slow offer used
* Tidy-up
Remove pre-otp20 references.
Reinstate the check that the starting pid is still active, this was added to tidy up shutdown.
Resolve failure to run on otp20 due to `-if` sttaement
* Tidy up
Using null rather then {null, Key} is potentially clearer as it is not a concern what they Key is in this case, and removes a comparison step from the leveled_codec:endkey_passed/2 function.
There were issues with coverage in eunit tests as the leveled_pclerk shut down. This prompted a general tidy of leveled_pclerk (remove passing of LoopState into internal functions, and add dialyzer specs.
* Remove R16 relic
* Further testing another issue
The StartKey must always be less than or equal to the prefix when the first N characters are stripped, but this is not true of the EndKey (for the query) which does not have to be between the FirstKey and the LastKey.
If the EndKey query does not match it must be greater than the Prefix (as otherwise it would not have been greater than the FirstKey - so set to null.
* Fix unit test
Unit test had a typo - and result interpretation had a misunderstanding.
* Code and spec tidy
Also look to the cover the situation when the FirstKey is the same as the Prefix with tests.
This is, in theory, not an issue as it is the EndKey for each sublist which is indexed in leveled_tree. However, guard against it mapping to null here, just in case there are dangers lurking (note that tests will still pass without `M > N` guard in place.
* Hibernate on BIC complete
There are three situations when the BIC becomes complete:
- In a file created as part of a merge the BIS is learned in the merge
- After startup, files below L1 learn the block cache through reads that happen to read the block, eventually the while cache will be read, unless...
- Either before/after the cache is complete, it can get whiped by a timeout after a get_sqn request (e.g. as prompted by a journal compaction) ... it will then be re-filled of the back of get/get-range requests.
In all these situations we want to hibernate after the BIC is fill - to reflect the fact that the LoopState should now be relatively stable, so it is a good point to GC and rationalise location of data.
Previously on the the first base was covered. Now all three are covered through the bic_complete message.
* Test all index keys have same term
This works functionally, but is not optimised (the term is replicated in the index)
* Summaries with same index term
If the summary index all have the same index term - only the object keys need to be indexes
* Simplify case statements
We either match the pattern of <<Prefix:N, Suffix>> or the answer should be null
* OK for M == N
If M = N for the first key, it will have a suffix of <<>>. This will match (as expected) a query Start Key of the sam size, and be smaller than any query Start Key that has the same prefix.
If the query Start Key does not match the prefix - it will be null - as it must be smaller than the Prefix (as other wise the query Start Key would be bigger than the Last Key).
The constraint of M > N was introduced before the *_prefix_filter functions were checking the prefix, to avoid issues. Now the prefix is being checked, then M == N is ok.
* Simplify
Correct the test to use a binary field in the range.
To avoid further issue, only apply filter when everything is a binary() type.
* Add test for head_only mode
When leveled is used as a tictacaae key store (in parallel mode), the keys will be head_only entries. Double check they are handled as expected like object keys
* Revert previous change - must support typed buckets
Add assertion to confirm worthwhile optimisation
* Add support for configurable cache multiple (#375)
* Mas i370 patch e (#385)
Improvement to monitoring for efficiency and improved readability of logs and stats.
As part of this, where possible, tried to avoid updating loop state on READ messages in leveled processes (as was the case when tracking stats within each process).
No performance benefits found with change, but improved stats has helped discover other potential gains.
2022-12-18 20:18:03 +00:00
|
|
|
leveled_log:log(ic010, [WP ++ DelJ]);
|
2017-11-08 12:58:09 +00:00
|
|
|
LMD_Delta ->
|
Develop 3.1 d30update (#386)
* Mas i370 patch d (#383)
* Refactor penciller memory
In high-volume tests on large key-count clusters, so significant variation in the P0031 time has been seen:
TimeBucket PatchA
a.0ms_to_1ms 18554
b.1ms_to_2ms 51778
c.2ms_to_3ms 696
d.3ms_to_5ms 220
e.5ms_to_8ms 59
f.8ms_to_13ms 40
g.13ms_to_21ms 364
h.21ms_to_34ms 277
i.34ms_to_55ms 34
j.55ms_to_89ms 17
k.89ms_to_144ms 21
l.144ms_to_233ms 31
m.233ms_to_377ms 45
n.377ms_to_610ms 52
o.610ms_to_987ms 59
p.987ms_to_1597ms 55
q.1597ms_to_2684ms 54
r.2684ms_to_4281ms 29
s.4281ms_to_6965ms 7
t.6295ms_to_11246ms 1
It is unclear why this varies so much. The time to add to the cache appears to be minimal (but perhaps there is an issue with timing points in the code), whereas the time to add to the index is much more significant and variable. There is also variable time when the memory is rolled (although the actual activity here appears to be minimal.
The refactoring here is two-fold:
- tidy and simplify by keeping LoopState managed within handle_call, and add more helpful dialyzer specs;
- change the update to the index to be a simple extension of a list, rather than any conversion.
This alternative version of the pmem index in unit test is orders of magnitude faster to add - and is the same order of magnitude to check. Anticipation is that it may be more efficient in terms of memory changes.
* Compress SST index
Reduces the size of the leveled_sst index with two changes:
1 - Where there is a common prefix of tuple elements (e.g. Bucket) across the whole leveled_sst file - only the non-common part is indexed, and a function is used to compare.
2 - There is less "indexing" of the index i.e. only 1 in 16 keys are passed into the gb_trees part instead of 1 in 4
* Immediate hibernate
Reasons for delay in hibernate were not clear.
Straight after creation the process will not be in receipt of messages (must wait for the manifest to be updated), so better to hibernate now. This also means the log PC023 provides more accurate information.
* Refactor BIC
This patch avoids the following:
- repeated replacement of the same element in the BIC (via get_kvrange), by checking presence via GET before sing SET
- Stops re-reading of all elements to discover high modified date
Also there appears to have been a bug where a missing HMD for the file is required to add to the cache. However, now the cache may be erased without erasing the HMD. This means that the cache can never be rebuilt
* Use correct size in test results
erts_debug:flat_size/1 returns size in words (i.e. 8 bytes on 64-bit CPU) not bytes
* Don't change summary record
As it is persisted as part of the file write, any change to the summary record cannot be rolled back
* Clerk to prompt L0 write
Simplifies the logic if the clerk request work for the penciller prompts L0 writes as well as Manifest changes.
The advantage now is that if the penciller memory is full, and PUT load stops, the clerk should still be able to prompt persistence. the penciller can therefore make use of dead time this way
* Add push on journal compact
If there has been a backlog, followed by a quiet period - there may be a large ledger cache left unpushed. Journal compaction events are about once per hour, so the performance overhead of a false push should be minimal, with the advantage of clearing any backlog before load starts again.
This is only relevant to riak users with very off/full batch type workloads.
* Extend tests
To more consistently trigger all overload scenarios
* Fix range keys smaller than prefix
Can't make end key an empty binary in this case, as it may be bigger than any keys within the range, but will appear to be smaller.
Unit tests and ct tests added to expose the potential issue
* Tidy-up
- Remove penciller logs which are no longer called
- Get pclerk to only wait MIN_TIMEOUT after doing work, in case there is a backlog
- Remove update_levelzero_cache function as it is unique to handle_call of push_mem, and simple enough to be inline
- Alight testutil slow offer with standard slow offer used
* Tidy-up
Remove pre-otp20 references.
Reinstate the check that the starting pid is still active, this was added to tidy up shutdown.
Resolve failure to run on otp20 due to `-if` sttaement
* Tidy up
Using null rather then {null, Key} is potentially clearer as it is not a concern what they Key is in this case, and removes a comparison step from the leveled_codec:endkey_passed/2 function.
There were issues with coverage in eunit tests as the leveled_pclerk shut down. This prompted a general tidy of leveled_pclerk (remove passing of LoopState into internal functions, and add dialyzer specs.
* Remove R16 relic
* Further testing another issue
The StartKey must always be less than or equal to the prefix when the first N characters are stripped, but this is not true of the EndKey (for the query) which does not have to be between the FirstKey and the LastKey.
If the EndKey query does not match it must be greater than the Prefix (as otherwise it would not have been greater than the FirstKey - so set to null.
* Fix unit test
Unit test had a typo - and result interpretation had a misunderstanding.
* Code and spec tidy
Also look to the cover the situation when the FirstKey is the same as the Prefix with tests.
This is, in theory, not an issue as it is the EndKey for each sublist which is indexed in leveled_tree. However, guard against it mapping to null here, just in case there are dangers lurking (note that tests will still pass without `M > N` guard in place.
* Hibernate on BIC complete
There are three situations when the BIC becomes complete:
- In a file created as part of a merge the BIS is learned in the merge
- After startup, files below L1 learn the block cache through reads that happen to read the block, eventually the while cache will be read, unless...
- Either before/after the cache is complete, it can get whiped by a timeout after a get_sqn request (e.g. as prompted by a journal compaction) ... it will then be re-filled of the back of get/get-range requests.
In all these situations we want to hibernate after the BIC is fill - to reflect the fact that the LoopState should now be relatively stable, so it is a good point to GC and rationalise location of data.
Previously on the the first base was covered. Now all three are covered through the bic_complete message.
* Test all index keys have same term
This works functionally, but is not optimised (the term is replicated in the index)
* Summaries with same index term
If the summary index all have the same index term - only the object keys need to be indexes
* Simplify case statements
We either match the pattern of <<Prefix:N, Suffix>> or the answer should be null
* OK for M == N
If M = N for the first key, it will have a suffix of <<>>. This will match (as expected) a query Start Key of the sam size, and be smaller than any query Start Key that has the same prefix.
If the query Start Key does not match the prefix - it will be null - as it must be smaller than the Prefix (as other wise the query Start Key would be bigger than the Last Key).
The constraint of M > N was introduced before the *_prefix_filter functions were checking the prefix, to avoid issues. Now the prefix is being checked, then M == N is ok.
* Simplify
Correct the test to use a binary field in the range.
To avoid further issue, only apply filter when everything is a binary() type.
* Add test for head_only mode
When leveled is used as a tictacaae key store (in parallel mode), the keys will be head_only entries. Double check they are handled as expected like object keys
* Revert previous change - must support typed buckets
Add assertion to confirm worthwhile optimisation
* Add support for configurable cache multiple (#375)
* Mas i370 patch e (#385)
Improvement to monitoring for efficiency and improved readability of logs and stats.
As part of this, where possible, tried to avoid updating loop state on READ messages in leveled processes (as was the case when tracking stats within each process).
No performance benefits found with change, but improved stats has helped discover other potential gains.
2022-12-18 20:18:03 +00:00
|
|
|
leveled_log:log(ic011, [WP ++ DelJ, LMD_Delta]),
|
2017-11-08 12:58:09 +00:00
|
|
|
ok
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
lists:foreach(DeleteJournalFun, ClearedJournals)
|
|
|
|
end.
|
2016-09-27 14:58:26 +01:00
|
|
|
|
2016-09-20 16:13:36 +01:00
|
|
|
|
|
|
|
%%%============================================================================
|
|
|
|
%%% Test
|
|
|
|
%%%============================================================================
|
2016-09-27 14:58:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
-ifdef(TEST).
|
|
|
|
|
2023-03-14 16:27:08 +00:00
|
|
|
-include_lib("eunit/include/eunit.hrl").
|
|
|
|
|
2017-03-30 15:46:37 +01:00
|
|
|
schedule_test() ->
|
|
|
|
schedule_test_bycount(1),
|
|
|
|
schedule_test_bycount(2),
|
|
|
|
schedule_test_bycount(4).
|
|
|
|
|
|
|
|
schedule_test_bycount(N) ->
|
2018-08-07 12:23:43 +01:00
|
|
|
LocalTimeAsDateTime = {{2017,3,30},{15,27,0}},
|
|
|
|
CurrentTS= local_time_to_now(LocalTimeAsDateTime),
|
2017-03-30 15:46:37 +01:00
|
|
|
SecondsToCompaction0 = schedule_compaction([16], N, CurrentTS),
|
|
|
|
io:format("Seconds to compaction ~w~n", [SecondsToCompaction0]),
|
|
|
|
?assertMatch(true, SecondsToCompaction0 > 1800),
|
|
|
|
?assertMatch(true, SecondsToCompaction0 < 5700),
|
2017-05-18 14:09:45 +01:00
|
|
|
SecondsToCompaction1 = schedule_compaction([14], N, CurrentTS), % tomorrow!
|
2018-07-24 12:09:59 +01:00
|
|
|
io:format("Seconds to compaction ~w for count ~w~n",
|
|
|
|
[SecondsToCompaction1, N]),
|
2017-10-24 14:32:04 +01:00
|
|
|
?assertMatch(true, SecondsToCompaction1 >= 81180),
|
|
|
|
?assertMatch(true, SecondsToCompaction1 =< 84780).
|
2017-03-30 15:46:37 +01:00
|
|
|
|
2018-08-07 12:23:43 +01:00
|
|
|
local_time_to_now(DateTime) ->
|
|
|
|
[UTC] = calendar:local_time_to_universal_time_dst(DateTime),
|
|
|
|
Epoch = calendar:datetime_to_gregorian_seconds({{1970, 1, 1}, {0, 0, 0}}),
|
|
|
|
Seconds = calendar:datetime_to_gregorian_seconds(UTC) - Epoch,
|
|
|
|
{Seconds div 1000000, Seconds rem 1000000, 0}.
|
2017-03-30 15:46:37 +01:00
|
|
|
|
2016-09-27 14:58:26 +01:00
|
|
|
simple_score_test() ->
|
|
|
|
Run1 = [#candidate{compaction_perc = 75.0},
|
|
|
|
#candidate{compaction_perc = 75.0},
|
|
|
|
#candidate{compaction_perc = 76.0},
|
|
|
|
#candidate{compaction_perc = 70.0}],
|
2018-07-23 12:46:42 +01:00
|
|
|
?assertMatch(-4.0, score_run(Run1, {4, 70.0, 40.0})),
|
2016-09-27 14:58:26 +01:00
|
|
|
Run2 = [#candidate{compaction_perc = 75.0}],
|
2018-07-23 12:46:42 +01:00
|
|
|
?assertMatch(-35.0, score_run(Run2, {4, 70.0, 40.0})),
|
2023-10-03 13:29:54 -04:00
|
|
|
?assertEqual(0.0, score_run([], {4, 40.0, 70.0})),
|
2016-10-05 18:28:31 +01:00
|
|
|
Run3 = [#candidate{compaction_perc = 100.0}],
|
2018-07-23 12:46:42 +01:00
|
|
|
?assertMatch(-60.0, score_run(Run3, {4, 70.0, 40.0})).
|
2016-09-27 14:58:26 +01:00
|
|
|
|
2016-11-14 11:17:14 +00:00
|
|
|
file_gc_test() ->
|
2019-01-17 21:02:29 +00:00
|
|
|
State = #state{waste_path="test/test_area/waste/",
|
2016-11-14 11:17:14 +00:00
|
|
|
waste_retention_period=1},
|
|
|
|
ok = filelib:ensure_dir(State#state.waste_path),
|
|
|
|
file:write_file(State#state.waste_path ++ "1.cdb", term_to_binary("Hello")),
|
|
|
|
timer:sleep(1100),
|
|
|
|
file:write_file(State#state.waste_path ++ "2.cdb", term_to_binary("Hello")),
|
|
|
|
clear_waste(State),
|
|
|
|
{ok, ClearedJournals} = file:list_dir(State#state.waste_path),
|
|
|
|
?assertMatch(["2.cdb"], ClearedJournals),
|
|
|
|
timer:sleep(1100),
|
|
|
|
clear_waste(State),
|
|
|
|
{ok, ClearedJournals2} = file:list_dir(State#state.waste_path),
|
|
|
|
?assertMatch([], ClearedJournals2).
|
|
|
|
|
2018-09-26 12:56:28 +01:00
|
|
|
|
|
|
|
check_bestrun(CandidateList, Params) ->
|
|
|
|
{BestRun, _Score} = assess_candidates(CandidateList, Params),
|
|
|
|
lists:map(fun(C) -> C#candidate.filename end, BestRun).
|
|
|
|
|
2016-09-27 14:58:26 +01:00
|
|
|
find_bestrun_test() ->
|
|
|
|
%% Tests dependent on these defaults
|
|
|
|
%% -define(MAX_COMPACTION_RUN, 4).
|
2017-03-30 12:15:36 +01:00
|
|
|
%% -define(SINGLEFILE_COMPACTION_TARGET, 40.0).
|
2018-07-23 12:46:42 +01:00
|
|
|
%% -define(MAXRUNLENGTH_COMPACTION_TARGET, 60.0).
|
2016-09-27 14:58:26 +01:00
|
|
|
%% Tested first with blocks significant as no back-tracking
|
2017-06-02 08:37:57 +01:00
|
|
|
Params = {4, 60.0, 40.0},
|
2018-09-26 12:56:28 +01:00
|
|
|
Block1 = [#candidate{compaction_perc = 55.0, filename = "a"},
|
|
|
|
#candidate{compaction_perc = 65.0, filename = "b"},
|
|
|
|
#candidate{compaction_perc = 42.0, filename = "c"},
|
|
|
|
#candidate{compaction_perc = 50.0, filename = "d"}],
|
|
|
|
Block2 = [#candidate{compaction_perc = 38.0, filename = "e"},
|
|
|
|
#candidate{compaction_perc = 75.0, filename = "f"},
|
|
|
|
#candidate{compaction_perc = 75.0, filename = "g"},
|
|
|
|
#candidate{compaction_perc = 45.0, filename = "h"}],
|
|
|
|
Block3 = [#candidate{compaction_perc = 70.0, filename = "i"},
|
|
|
|
#candidate{compaction_perc = 100.0, filename = "j"},
|
|
|
|
#candidate{compaction_perc = 100.0, filename = "k"},
|
|
|
|
#candidate{compaction_perc = 100.0, filename = "l"}],
|
|
|
|
Block4 = [#candidate{compaction_perc = 55.0, filename = "m"},
|
|
|
|
#candidate{compaction_perc = 56.0, filename = "n"},
|
|
|
|
#candidate{compaction_perc = 57.0, filename = "o"},
|
|
|
|
#candidate{compaction_perc = 40.0, filename = "p"}],
|
|
|
|
Block5 = [#candidate{compaction_perc = 60.0, filename = "q"},
|
|
|
|
#candidate{compaction_perc = 60.0, filename = "r"}],
|
2016-09-27 14:58:26 +01:00
|
|
|
CList0 = Block1 ++ Block2 ++ Block3 ++ Block4 ++ Block5,
|
2018-09-26 12:56:28 +01:00
|
|
|
?assertMatch(["b", "c", "d", "e"], check_bestrun(CList0, Params)),
|
|
|
|
CList1 = CList0 ++ [#candidate{compaction_perc = 20.0, filename="s"}],
|
|
|
|
?assertMatch(["s"], check_bestrun(CList1, Params)),
|
2016-09-27 14:58:26 +01:00
|
|
|
CList2 = Block4 ++ Block3 ++ Block2 ++ Block1 ++ Block5,
|
2018-09-26 12:56:28 +01:00
|
|
|
?assertMatch(["h", "a", "b", "c"], check_bestrun(CList2, Params)),
|
2016-09-27 14:58:26 +01:00
|
|
|
CList3 = Block5 ++ Block1 ++ Block2 ++ Block3 ++ Block4,
|
2018-09-26 12:56:28 +01:00
|
|
|
?assertMatch(["b", "c", "d", "e"],check_bestrun(CList3, Params)).
|
|
|
|
|
|
|
|
handle_emptycandidatelist_test() ->
|
2023-10-03 13:29:54 -04:00
|
|
|
{A, B} = assess_candidates([], {4, 60.0, 40.0}),
|
|
|
|
?assertEqual([], A),
|
|
|
|
?assert(B =:= +0.0).
|
2016-09-27 14:58:26 +01:00
|
|
|
|
2016-10-25 23:13:14 +01:00
|
|
|
test_ledgerkey(Key) ->
|
|
|
|
{o, "Bucket", Key, null}.
|
|
|
|
|
|
|
|
test_inkerkv(SQN, Key, V, IdxSpecs) ->
|
2017-11-06 18:44:08 +00:00
|
|
|
leveled_codec:to_inkerkv(test_ledgerkey(Key), SQN, V, IdxSpecs,
|
|
|
|
native, false).
|
2016-10-25 23:13:14 +01:00
|
|
|
|
2016-09-28 11:41:56 +01:00
|
|
|
fetch_testcdb(RP) ->
|
2016-09-27 14:58:26 +01:00
|
|
|
FN1 = leveled_inker:filepath(RP, 1, new_journal),
|
2017-03-20 15:43:54 +00:00
|
|
|
{ok,
|
|
|
|
CDB1} = leveled_cdb:cdb_open_writer(FN1,
|
|
|
|
#cdb_options{binary_mode=true}),
|
2018-05-04 11:19:37 +01:00
|
|
|
{K1, V1} = test_inkerkv(1, "Key1", "Value1", {[], infinity}),
|
|
|
|
{K2, V2} = test_inkerkv(2, "Key2", "Value2", {[], infinity}),
|
|
|
|
{K3, V3} = test_inkerkv(3, "Key3", "Value3", {[], infinity}),
|
|
|
|
{K4, V4} = test_inkerkv(4, "Key1", "Value4", {[], infinity}),
|
|
|
|
{K5, V5} = test_inkerkv(5, "Key1", "Value5", {[], infinity}),
|
|
|
|
{K6, V6} = test_inkerkv(6, "Key1", "Value6", {[], infinity}),
|
|
|
|
{K7, V7} = test_inkerkv(7, "Key1", "Value7", {[], infinity}),
|
|
|
|
{K8, V8} = test_inkerkv(8, "Key1", "Value8", {[], infinity}),
|
2016-09-27 14:58:26 +01:00
|
|
|
ok = leveled_cdb:cdb_put(CDB1, K1, V1),
|
|
|
|
ok = leveled_cdb:cdb_put(CDB1, K2, V2),
|
|
|
|
ok = leveled_cdb:cdb_put(CDB1, K3, V3),
|
|
|
|
ok = leveled_cdb:cdb_put(CDB1, K4, V4),
|
|
|
|
ok = leveled_cdb:cdb_put(CDB1, K5, V5),
|
|
|
|
ok = leveled_cdb:cdb_put(CDB1, K6, V6),
|
|
|
|
ok = leveled_cdb:cdb_put(CDB1, K7, V7),
|
|
|
|
ok = leveled_cdb:cdb_put(CDB1, K8, V8),
|
|
|
|
{ok, FN2} = leveled_cdb:cdb_complete(CDB1),
|
2017-03-20 15:43:54 +00:00
|
|
|
leveled_cdb:cdb_open_reader(FN2, #cdb_options{binary_mode=true}).
|
2016-09-28 11:41:56 +01:00
|
|
|
|
|
|
|
check_single_file_test() ->
|
2019-01-17 21:02:29 +00:00
|
|
|
RP = "test/test_area/",
|
2020-03-15 22:14:42 +00:00
|
|
|
RS = leveled_codec:inker_reload_strategy([]),
|
2019-01-17 21:02:29 +00:00
|
|
|
ok = filelib:ensure_dir(leveled_inker:filepath(RP, journal_dir)),
|
2016-09-28 11:41:56 +01:00
|
|
|
{ok, CDB} = fetch_testcdb(RP),
|
2016-10-25 23:13:14 +01:00
|
|
|
LedgerSrv1 = [{8, {o, "Bucket", "Key1", null}},
|
|
|
|
{2, {o, "Bucket", "Key2", null}},
|
|
|
|
{3, {o, "Bucket", "Key3", null}}],
|
2016-09-27 14:58:26 +01:00
|
|
|
LedgerFun1 = fun(Srv, Key, ObjSQN) ->
|
|
|
|
case lists:keyfind(ObjSQN, 1, Srv) of
|
|
|
|
{ObjSQN, Key} ->
|
2020-03-09 15:12:48 +00:00
|
|
|
current;
|
2016-09-27 14:58:26 +01:00
|
|
|
_ ->
|
2020-03-09 15:12:48 +00:00
|
|
|
replaced
|
2016-09-27 14:58:26 +01:00
|
|
|
end end,
|
2020-03-15 22:14:42 +00:00
|
|
|
Score1 = check_single_file(CDB, LedgerFun1, LedgerSrv1, 9, 8, 4, RS),
|
2016-09-27 14:58:26 +01:00
|
|
|
?assertMatch(37.5, Score1),
|
2020-03-09 15:12:48 +00:00
|
|
|
LedgerFun2 = fun(_Srv, _Key, _ObjSQN) -> current end,
|
2020-03-15 22:14:42 +00:00
|
|
|
Score2 = check_single_file(CDB, LedgerFun2, LedgerSrv1, 9, 8, 4, RS),
|
2016-09-27 14:58:26 +01:00
|
|
|
?assertMatch(100.0, Score2),
|
2020-03-15 22:14:42 +00:00
|
|
|
Score3 = check_single_file(CDB, LedgerFun1, LedgerSrv1, 9, 8, 3, RS),
|
2016-09-27 14:58:26 +01:00
|
|
|
?assertMatch(37.5, Score3),
|
2020-03-15 22:14:42 +00:00
|
|
|
Score4 = check_single_file(CDB, LedgerFun1, LedgerSrv1, 4, 8, 4, RS),
|
2016-10-05 18:28:31 +01:00
|
|
|
?assertMatch(75.0, Score4),
|
2016-10-26 20:39:16 +01:00
|
|
|
ok = leveled_cdb:cdb_deletepending(CDB),
|
2016-09-28 11:41:56 +01:00
|
|
|
ok = leveled_cdb:cdb_destroy(CDB).
|
2016-10-05 18:28:31 +01:00
|
|
|
|
|
|
|
|
2016-10-25 23:13:14 +01:00
|
|
|
compact_single_file_setup() ->
|
2019-01-17 21:02:29 +00:00
|
|
|
RP = "test/test_area/",
|
|
|
|
ok = filelib:ensure_dir(leveled_inker:filepath(RP, journal_dir)),
|
2016-09-28 11:41:56 +01:00
|
|
|
{ok, CDB} = fetch_testcdb(RP),
|
|
|
|
Candidate = #candidate{journal = CDB,
|
|
|
|
low_sqn = 1,
|
|
|
|
filename = "test",
|
|
|
|
compaction_perc = 37.5},
|
2016-10-25 23:13:14 +01:00
|
|
|
LedgerSrv1 = [{8, {o, "Bucket", "Key1", null}},
|
|
|
|
{2, {o, "Bucket", "Key2", null}},
|
|
|
|
{3, {o, "Bucket", "Key3", null}}],
|
2016-09-28 11:41:56 +01:00
|
|
|
LedgerFun1 = fun(Srv, Key, ObjSQN) ->
|
|
|
|
case lists:keyfind(ObjSQN, 1, Srv) of
|
|
|
|
{ObjSQN, Key} ->
|
2020-03-09 15:12:48 +00:00
|
|
|
current;
|
2016-09-28 11:41:56 +01:00
|
|
|
_ ->
|
2020-03-09 15:12:48 +00:00
|
|
|
replaced
|
2016-09-28 11:41:56 +01:00
|
|
|
end end,
|
|
|
|
CompactFP = leveled_inker:filepath(RP, journal_compact_dir),
|
|
|
|
ok = filelib:ensure_dir(CompactFP),
|
2016-10-25 23:13:14 +01:00
|
|
|
{Candidate, LedgerSrv1, LedgerFun1, CompactFP, CDB}.
|
|
|
|
|
|
|
|
compact_single_file_recovr_test() ->
|
|
|
|
{Candidate,
|
|
|
|
LedgerSrv1,
|
|
|
|
LedgerFun1,
|
|
|
|
CompactFP,
|
|
|
|
CDB} = compact_single_file_setup(),
|
2019-01-25 14:32:41 +00:00
|
|
|
CDBOpts = #cdb_options{binary_mode=true},
|
|
|
|
[{LowSQN, FN, _PidOldR, LastKey}] =
|
2017-01-17 16:30:04 +00:00
|
|
|
compact_files([Candidate],
|
2019-01-25 14:32:41 +00:00
|
|
|
CDBOpts#cdb_options{file_path=CompactFP},
|
2017-01-17 16:30:04 +00:00
|
|
|
LedgerFun1,
|
|
|
|
LedgerSrv1,
|
|
|
|
9,
|
2017-11-06 21:16:46 +00:00
|
|
|
[{?STD_TAG, recovr}],
|
|
|
|
native),
|
2016-09-28 11:41:56 +01:00
|
|
|
io:format("FN of ~s~n", [FN]),
|
|
|
|
?assertMatch(2, LowSQN),
|
2019-01-25 14:32:41 +00:00
|
|
|
{ok, PidR} = leveled_cdb:cdb_reopen_reader(FN, LastKey, CDBOpts),
|
2016-10-25 23:13:14 +01:00
|
|
|
?assertMatch(probably,
|
|
|
|
leveled_cdb:cdb_keycheck(PidR,
|
|
|
|
{8,
|
|
|
|
stnd,
|
|
|
|
test_ledgerkey("Key1")})),
|
|
|
|
?assertMatch(missing, leveled_cdb:cdb_get(PidR,
|
|
|
|
{7,
|
|
|
|
stnd,
|
|
|
|
test_ledgerkey("Key1")})),
|
|
|
|
?assertMatch(missing, leveled_cdb:cdb_get(PidR,
|
|
|
|
{1,
|
|
|
|
stnd,
|
|
|
|
test_ledgerkey("Key1")})),
|
2017-03-20 15:43:54 +00:00
|
|
|
RKV1 = leveled_cdb:cdb_get(PidR,
|
|
|
|
{2,
|
|
|
|
stnd,
|
|
|
|
test_ledgerkey("Key2")}),
|
2018-05-04 11:19:37 +01:00
|
|
|
?assertMatch({{_, _}, {"Value2", {[], infinity}}},
|
|
|
|
leveled_codec:from_inkerkv(RKV1)),
|
2019-01-25 14:32:41 +00:00
|
|
|
ok = leveled_cdb:cdb_close(PidR),
|
2016-10-26 20:39:16 +01:00
|
|
|
ok = leveled_cdb:cdb_deletepending(CDB),
|
2016-09-28 18:26:52 +01:00
|
|
|
ok = leveled_cdb:cdb_destroy(CDB).
|
2016-09-28 11:41:56 +01:00
|
|
|
|
2016-09-27 14:58:26 +01:00
|
|
|
|
2016-10-25 23:13:14 +01:00
|
|
|
compact_single_file_retain_test() ->
|
|
|
|
{Candidate,
|
|
|
|
LedgerSrv1,
|
|
|
|
LedgerFun1,
|
|
|
|
CompactFP,
|
|
|
|
CDB} = compact_single_file_setup(),
|
2019-01-25 14:32:41 +00:00
|
|
|
CDBOpts = #cdb_options{binary_mode=true},
|
|
|
|
[{LowSQN, FN, _PidOldR, LastKey}] =
|
2017-01-17 16:30:04 +00:00
|
|
|
compact_files([Candidate],
|
2019-01-25 14:32:41 +00:00
|
|
|
CDBOpts#cdb_options{file_path=CompactFP},
|
2017-01-17 16:30:04 +00:00
|
|
|
LedgerFun1,
|
|
|
|
LedgerSrv1,
|
|
|
|
9,
|
2017-11-06 21:16:46 +00:00
|
|
|
[{?STD_TAG, retain}],
|
|
|
|
native),
|
2016-10-25 23:13:14 +01:00
|
|
|
io:format("FN of ~s~n", [FN]),
|
|
|
|
?assertMatch(1, LowSQN),
|
2019-01-25 14:32:41 +00:00
|
|
|
{ok, PidR} = leveled_cdb:cdb_reopen_reader(FN, LastKey, CDBOpts),
|
2016-10-25 23:13:14 +01:00
|
|
|
?assertMatch(probably,
|
|
|
|
leveled_cdb:cdb_keycheck(PidR,
|
|
|
|
{8,
|
|
|
|
stnd,
|
|
|
|
test_ledgerkey("Key1")})),
|
|
|
|
?assertMatch(missing, leveled_cdb:cdb_get(PidR,
|
|
|
|
{7,
|
|
|
|
stnd,
|
|
|
|
test_ledgerkey("Key1")})),
|
|
|
|
?assertMatch(missing, leveled_cdb:cdb_get(PidR,
|
|
|
|
{1,
|
|
|
|
stnd,
|
|
|
|
test_ledgerkey("Key1")})),
|
2017-03-20 15:43:54 +00:00
|
|
|
RKV1 = leveled_cdb:cdb_get(PidR,
|
2019-01-25 14:32:41 +00:00
|
|
|
{2,
|
|
|
|
stnd,
|
|
|
|
test_ledgerkey("Key2")}),
|
2018-05-04 11:19:37 +01:00
|
|
|
?assertMatch({{_, _}, {"Value2", {[], infinity}}},
|
|
|
|
leveled_codec:from_inkerkv(RKV1)),
|
2019-01-25 14:32:41 +00:00
|
|
|
ok = leveled_cdb:cdb_close(PidR),
|
2016-10-26 20:39:16 +01:00
|
|
|
ok = leveled_cdb:cdb_deletepending(CDB),
|
2016-10-25 23:13:14 +01:00
|
|
|
ok = leveled_cdb:cdb_destroy(CDB).
|
|
|
|
|
2016-10-08 22:15:48 +01:00
|
|
|
compact_empty_file_test() ->
|
2019-01-17 21:02:29 +00:00
|
|
|
RP = "test/test_area/",
|
|
|
|
ok = filelib:ensure_dir(leveled_inker:filepath(RP, journal_dir)),
|
2016-10-08 22:15:48 +01:00
|
|
|
FN1 = leveled_inker:filepath(RP, 1, new_journal),
|
2020-03-15 22:14:42 +00:00
|
|
|
RS = leveled_codec:inker_reload_strategy([]),
|
2016-10-08 22:15:48 +01:00
|
|
|
CDBopts = #cdb_options{binary_mode=true},
|
|
|
|
{ok, CDB1} = leveled_cdb:cdb_open_writer(FN1, CDBopts),
|
|
|
|
{ok, FN2} = leveled_cdb:cdb_complete(CDB1),
|
|
|
|
{ok, CDB2} = leveled_cdb:cdb_open_reader(FN2),
|
2016-10-25 23:13:14 +01:00
|
|
|
LedgerSrv1 = [{8, {o, "Bucket", "Key1", null}},
|
|
|
|
{2, {o, "Bucket", "Key2", null}},
|
|
|
|
{3, {o, "Bucket", "Key3", null}}],
|
2020-03-09 15:12:48 +00:00
|
|
|
LedgerFun1 = fun(_Srv, _Key, _ObjSQN) -> replaced end,
|
2020-03-15 22:14:42 +00:00
|
|
|
Score1 = check_single_file(CDB2, LedgerFun1, LedgerSrv1, 9, 8, 4, RS),
|
2023-10-03 13:29:54 -04:00
|
|
|
?assert((+0.0 =:= Score1) orelse (-0.0 =:= Score1)),
|
2017-11-08 11:20:22 +00:00
|
|
|
ok = leveled_cdb:cdb_deletepending(CDB2),
|
|
|
|
ok = leveled_cdb:cdb_destroy(CDB2).
|
2016-10-08 22:15:48 +01:00
|
|
|
|
2016-10-27 00:57:19 +01:00
|
|
|
compare_candidate_test() ->
|
|
|
|
Candidate1 = #candidate{low_sqn=1},
|
|
|
|
Candidate2 = #candidate{low_sqn=2},
|
|
|
|
Candidate3 = #candidate{low_sqn=3},
|
|
|
|
Candidate4 = #candidate{low_sqn=4},
|
|
|
|
?assertMatch([Candidate1, Candidate2, Candidate3, Candidate4],
|
|
|
|
sort_run([Candidate3, Candidate2, Candidate4, Candidate1])).
|
|
|
|
|
2017-09-15 15:10:04 +01:00
|
|
|
compact_singlefile_totwosmallfiles_test_() ->
|
|
|
|
{timeout, 60, fun compact_singlefile_totwosmallfiles_testto/0}.
|
|
|
|
|
|
|
|
compact_singlefile_totwosmallfiles_testto() ->
|
2019-01-17 21:02:29 +00:00
|
|
|
RP = "test/test_area/",
|
|
|
|
CP = "test/test_area/journal/journal_file/post_compact/",
|
2016-11-04 12:22:15 +00:00
|
|
|
ok = filelib:ensure_dir(CP),
|
|
|
|
FN1 = leveled_inker:filepath(RP, 1, new_journal),
|
|
|
|
CDBoptsLarge = #cdb_options{binary_mode=true, max_size=30000000},
|
|
|
|
{ok, CDB1} = leveled_cdb:cdb_open_writer(FN1, CDBoptsLarge),
|
|
|
|
lists:foreach(fun(X) ->
|
|
|
|
LK = test_ledgerkey("Key" ++ integer_to_list(X)),
|
2017-07-31 20:20:39 +02:00
|
|
|
Value = leveled_rand:rand_bytes(1024),
|
2017-11-06 15:54:58 +00:00
|
|
|
{IK, IV} =
|
2018-05-04 11:19:37 +01:00
|
|
|
leveled_codec:to_inkerkv(LK, X, Value,
|
|
|
|
{[], infinity},
|
2017-11-06 18:44:08 +00:00
|
|
|
native, true),
|
2017-03-20 15:43:54 +00:00
|
|
|
ok = leveled_cdb:cdb_put(CDB1, IK, IV)
|
2016-11-04 12:22:15 +00:00
|
|
|
end,
|
|
|
|
lists:seq(1, 1000)),
|
|
|
|
{ok, NewName} = leveled_cdb:cdb_complete(CDB1),
|
|
|
|
{ok, CDBr} = leveled_cdb:cdb_open_reader(NewName),
|
2017-11-06 15:54:58 +00:00
|
|
|
CDBoptsSmall =
|
|
|
|
#cdb_options{binary_mode=true, max_size=400000, file_path=CP},
|
2016-11-04 12:22:15 +00:00
|
|
|
BestRun1 = [#candidate{low_sqn=1,
|
|
|
|
filename=leveled_cdb:cdb_filename(CDBr),
|
|
|
|
journal=CDBr,
|
|
|
|
compaction_perc=50.0}],
|
2020-03-09 15:12:48 +00:00
|
|
|
FakeFilterFun =
|
|
|
|
fun(_FS, _LK, SQN) ->
|
|
|
|
case SQN rem 2 of
|
|
|
|
0 -> current;
|
|
|
|
_ -> replaced
|
|
|
|
end
|
|
|
|
end,
|
2016-11-04 12:22:15 +00:00
|
|
|
|
2016-11-14 11:40:02 +00:00
|
|
|
ManifestSlice = compact_files(BestRun1,
|
|
|
|
CDBoptsSmall,
|
|
|
|
FakeFilterFun,
|
|
|
|
null,
|
|
|
|
900,
|
2017-11-06 21:16:46 +00:00
|
|
|
[{?STD_TAG, recovr}],
|
|
|
|
native),
|
2016-11-04 12:22:15 +00:00
|
|
|
?assertMatch(2, length(ManifestSlice)),
|
2017-01-17 16:30:04 +00:00
|
|
|
lists:foreach(fun({_SQN, _FN, CDB, _LK}) ->
|
2016-11-04 12:22:15 +00:00
|
|
|
ok = leveled_cdb:cdb_deletepending(CDB),
|
|
|
|
ok = leveled_cdb:cdb_destroy(CDB)
|
|
|
|
end,
|
|
|
|
ManifestSlice),
|
|
|
|
ok = leveled_cdb:cdb_deletepending(CDBr),
|
|
|
|
ok = leveled_cdb:cdb_destroy(CDBr).
|
2016-11-14 20:43:38 +00:00
|
|
|
|
2017-11-09 12:42:49 +00:00
|
|
|
size_score_test() ->
|
|
|
|
KeySizeList =
|
2020-03-15 22:14:42 +00:00
|
|
|
[{{1, ?INKT_STND, {?STD_TAG, <<"B">>, <<"Key1">>, null}}, 104},
|
|
|
|
{{2, ?INKT_STND, {?STD_TAG, <<"B">>, <<"Key2">>, null}}, 124},
|
|
|
|
{{3, ?INKT_STND, {?STD_TAG, <<"B">>, <<"Key3">>, null}}, 144},
|
|
|
|
{{4, ?INKT_STND, {?STD_TAG, <<"B">>, <<"Key4">>, null}}, 154},
|
|
|
|
{{5,
|
|
|
|
?INKT_STND,
|
|
|
|
{?STD_TAG, <<"B">>, <<"Key5">>, <<"Subk1">>}, null},
|
|
|
|
164},
|
|
|
|
{{6, ?INKT_STND, {?STD_TAG, <<"B">>, <<"Key6">>, null}}, 174},
|
|
|
|
{{7, ?INKT_STND, {?STD_TAG, <<"B">>, <<"Key7">>, null}}, 184}],
|
2017-11-09 12:42:49 +00:00
|
|
|
MaxSQN = 6,
|
2020-03-15 22:14:42 +00:00
|
|
|
CurrentList =
|
|
|
|
[{?STD_TAG, <<"B">>, <<"Key1">>, null},
|
|
|
|
{?STD_TAG, <<"B">>, <<"Key4">>, null},
|
|
|
|
{?STD_TAG, <<"B">>, <<"Key5">>, <<"Subk1">>},
|
|
|
|
{?STD_TAG, <<"B">>, <<"Key6">>, null}],
|
2020-03-09 15:12:48 +00:00
|
|
|
FilterFun =
|
|
|
|
fun(L, K, _SQN) ->
|
|
|
|
case lists:member(K, L) of
|
|
|
|
true -> current;
|
|
|
|
false -> replaced
|
|
|
|
end
|
|
|
|
end,
|
2020-03-15 22:14:42 +00:00
|
|
|
Score =
|
|
|
|
size_comparison_score(KeySizeList,
|
|
|
|
FilterFun,
|
|
|
|
CurrentList,
|
|
|
|
MaxSQN,
|
|
|
|
leveled_codec:inker_reload_strategy([])),
|
|
|
|
io:format("Score ~w", [Score]),
|
2017-11-09 12:42:49 +00:00
|
|
|
?assertMatch(true, Score > 69.0),
|
|
|
|
?assertMatch(true, Score < 70.0).
|
|
|
|
|
2016-11-14 20:43:38 +00:00
|
|
|
coverage_cheat_test() ->
|
|
|
|
{noreply, _State0} = handle_info(timeout, #state{}),
|
2016-11-14 20:56:59 +00:00
|
|
|
{ok, _State1} = code_change(null, #state{}, null),
|
2016-11-18 21:35:45 +00:00
|
|
|
terminate(error, #state{}).
|
2016-11-04 12:22:15 +00:00
|
|
|
|
2017-07-31 19:53:01 +02:00
|
|
|
-endif.
|