Attempt to stop race - between level zero and ongoing merge

This commit is contained in:
martinsumner 2017-01-14 22:03:57 +00:00
parent dcf3afc056
commit ea171cb13b

View file

@ -235,8 +235,8 @@
source_penciller :: pid(), source_penciller :: pid(),
levelzero_astree :: list(), levelzero_astree :: list(),
ongoing_work = [] :: list(), work_ongoing = false :: boolean(), % i.e. compaction work
work_backlog = false :: boolean(), work_backlog = false :: boolean(), % i.e. compaction work
head_timing :: tuple()}). head_timing :: tuple()}).
@ -443,13 +443,13 @@ handle_call(work_for_clerk, _From, State) ->
[TL|_Tail] = WL, [TL|_Tail] = WL,
{reply, {reply,
{TL, State#state.manifest}, {TL, State#state.manifest},
State#state{work_backlog=true}}; State#state{work_backlog=true, work_ongoing=true}};
N -> N ->
leveled_log:log("P0024", [N, false]), leveled_log:log("P0024", [N, false]),
[TL|_Tail] = WL, [TL|_Tail] = WL,
{reply, {reply,
{TL, State#state.manifest}, {TL, State#state.manifest},
State#state{work_backlog=false}} State#state{work_backlog=false, work_ongoing=true}}
end end
end; end;
handle_call(get_startup_sqn, _From, State) -> handle_call(get_startup_sqn, _From, State) ->
@ -485,7 +485,7 @@ handle_call(doom, _From, State) ->
{stop, normal, {ok, [ManifestFP, FilesFP]}, State}. {stop, normal, {ok, [ManifestFP, FilesFP]}, State}.
handle_cast({manifest_change, NewManifest}, State) -> handle_cast({manifest_change, NewManifest}, State) ->
{noreply, State#state{manifest = NewManifest}}; {noreply, State#state{manifest = NewManifest, work_ongoing=false}};
handle_cast({release_snapshot, Snapshot}, State) -> handle_cast({release_snapshot, Snapshot}, State) ->
Manifest0 = leveled_manifest:release_snapshot(State#state.manifest, Manifest0 = leveled_manifest:release_snapshot(State#state.manifest,
Snapshot), Snapshot),
@ -676,9 +676,10 @@ update_levelzero(L0Size, {PushedTree, PushedIdx, MinSQN, MaxSQN},
false -> false ->
true true
end, end,
NoPendingManifestChange = not State#state.work_ongoing,
JitterCheck = RandomFactor or CacheMuchTooBig, JitterCheck = RandomFactor or CacheMuchTooBig,
case {CacheTooBig, L0Free, JitterCheck} of case {CacheTooBig, L0Free, JitterCheck, NoPendingManifestChange} of
{true, true, true} -> {true, true, true, true} ->
L0Constructor = roll_memory(UpdState, false), L0Constructor = roll_memory(UpdState, false),
leveled_log:log_timer("P0031", [], SW), leveled_log:log_timer("P0031", [], SW),
UpdState#state{levelzero_pending=true, UpdState#state{levelzero_pending=true,