Skip to content

Commit 1c9de96

Browse files
author
Shunichi Shinohara
committed
Disable previous riak object after back-pressure sleep is triggered
When back-pressure sleep is triggered by many siblings, holding previous object can lead to more siblings. This commit change the behavior and discard it. This setting has effect only when all the following conditions are met: - Normal PUT Object, no effect for multipart upload - Overwring existing object, no effect for new object - read_before_last_manifest_write=false, this setting was introduced in CS 1.5.3 and default is true
1 parent b8b1737 commit 1c9de96

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

src/riak_cs_manifest_fsm.erl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,14 @@ get_and_update(RcPid, WrappedManifests, Bucket, Key) ->
314314
{ok, RiakObject, Manifests} ->
315315
case update(RcPid, Manifests, RiakObject, WrappedManifests, Bucket, Key) of
316316
{ok, _, _} = Res ->
317-
maybe_backpressure_sleep(riakc_obj:value_count(RiakObject)),
318-
Res;
317+
case maybe_backpressure_sleep(riakc_obj:value_count(RiakObject)) of
318+
true ->
319+
%% Backpressure sleep is triggered. Bacause holding
320+
%% previous object can lead to more siblings, discard it.
321+
{ok, undefined, undefined};
322+
false ->
323+
Res
324+
end;
319325
OtherRes ->
320326
OtherRes
321327
end;
@@ -329,14 +335,18 @@ get_and_update(RcPid, WrappedManifests, Bucket, Key) ->
329335
{PutResult, undefined, undefined}
330336
end.
331337

338+
%% If backpressure is needed, sleep some interval and return `true'.
339+
%% Otherwise, return `false'.
340+
-spec maybe_backpressure_sleep(non_neg_integer()) -> boolean().
332341
maybe_backpressure_sleep(Siblings) ->
333342
BackpressureThreshold = riak_cs_config:get_env(
334343
riak_cs, manifest_siblings_bp_threashold, 5),
335344
maybe_backpressure_sleep(Siblings, BackpressureThreshold).
336345

346+
-spec maybe_backpressure_sleep(non_neg_integer(), non_neg_integer() | infinity) -> boolean().
337347
maybe_backpressure_sleep(Siblings, BackpressureThreshold)
338348
when Siblings < BackpressureThreshold ->
339-
ok;
349+
false;
340350
maybe_backpressure_sleep(Siblings, _BackpressureThreshold) ->
341351
MaxSleep = riak_cs_config:get_env(riak_cs, manifest_siblings_bp_max_sleep, 30*1000),
342352
Coefficient = riak_cs_config:get_env(riak_cs, manifest_siblings_bp_coefficient, 200),
@@ -345,7 +355,8 @@ maybe_backpressure_sleep(Siblings, _BackpressureThreshold) ->
345355
SleepMS = crypto:rand_uniform(MeanSleepMS - Delta, MeanSleepMS + Delta),
346356
lager:debug("maybe_backpressure_sleep: Siblings=~p, SleepMS=~p~n", [Siblings, SleepMS]),
347357
ok = riak_cs_stats:update(manifest_siblings_bp_sleep, SleepMS * 1000),
348-
timer:sleep(SleepMS).
358+
ok = timer:sleep(SleepMS),
359+
true.
349360

350361
update(RcPid, OldManifests, OldRiakObject, WrappedManifests, Bucket, Key) ->
351362
NewManiAdded = riak_cs_manifest_resolution:resolve([WrappedManifests, OldManifests]),

0 commit comments

Comments
 (0)