Fix segmented cache expiration timeouts.
This commit is contained in:
parent
3455c72447
commit
0c6ac7e491
|
@ -65,8 +65,7 @@ init([SegmentSize]) ->
|
||||||
handle_call({get_write_segment, Expiration}, _From,
|
handle_call({get_write_segment, Expiration}, _From,
|
||||||
State = #state{segments = Segments,
|
State = #state{segments = Segments,
|
||||||
segment_size = SegmentSize}) ->
|
segment_size = SegmentSize}) ->
|
||||||
NewBoundary = new_boundary(Expiration, SegmentSize),
|
[{_, Segment} | _] = NewSegments = maybe_add_segment(Expiration, SegmentSize, Segments),
|
||||||
[{_, Segment} | _] = NewSegments = maybe_add_segment(NewBoundary, Segments),
|
|
||||||
{reply, Segment, State#state{segments = NewSegments}};
|
{reply, Segment, State#state{segments = NewSegments}};
|
||||||
handle_call(get_segment_tables, _From, State = #state{segments = Segments}) ->
|
handle_call(get_segment_tables, _From, State = #state{segments = Segments}) ->
|
||||||
{_, Valid} = partition_expired_segments(Segments),
|
{_, Valid} = partition_expired_segments(Segments),
|
||||||
|
@ -95,18 +94,16 @@ partition_expired_segments(Segments) ->
|
||||||
fun({Boundary, _}) -> rabbit_auth_cache:expired(Boundary) end,
|
fun({Boundary, _}) -> rabbit_auth_cache:expired(Boundary) end,
|
||||||
Segments).
|
Segments).
|
||||||
|
|
||||||
maybe_add_segment(Boundary, OldSegments) ->
|
maybe_add_segment(Expiration, SegmentSize, OldSegments) ->
|
||||||
case OldSegments of
|
case OldSegments of
|
||||||
[{OldBoundary, _}|_] when OldBoundary > Boundary ->
|
[{OldBoundary, _}|_] when OldBoundary > Expiration ->
|
||||||
OldSegments;
|
OldSegments;
|
||||||
_ ->
|
_ ->
|
||||||
|
NewBoundary = Expiration + SegmentSize,
|
||||||
Segment = ets:new(segment, [set, public]),
|
Segment = ets:new(segment, [set, public]),
|
||||||
[{Boundary, Segment} | OldSegments]
|
[{NewBoundary, Segment} | OldSegments]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
new_boundary(Expiration, SegmentSize) ->
|
|
||||||
((Expiration div SegmentSize) * SegmentSize) + SegmentSize.
|
|
||||||
|
|
||||||
get_from_segments(Key) ->
|
get_from_segments(Key) ->
|
||||||
Tables = gen_server2:call(?MODULE, get_segment_tables),
|
Tables = gen_server2:call(?MODULE, get_segment_tables),
|
||||||
lists:flatmap(
|
lists:flatmap(
|
||||||
|
|
|
@ -164,8 +164,11 @@ random_timing(Config, MaxTTL, Parallel) ->
|
||||||
Value = {tuple_with, N, TTL},
|
Value = {tuple_with, N, TTL},
|
||||||
{error, not_found} = AuthCacheModule:get(Key),
|
{error, not_found} = AuthCacheModule:get(Key),
|
||||||
ok = AuthCacheModule:put(Key, Value, TTL),
|
ok = AuthCacheModule:put(Key, Value, TTL),
|
||||||
{ok, Value} = AuthCacheModule:get(Key),
|
case AuthCacheModule:get(Key) of
|
||||||
% 20ms expiry error
|
{ok, Value} -> ok;
|
||||||
|
Other -> error({Other, Value})
|
||||||
|
end,
|
||||||
|
% expiry error
|
||||||
timer:sleep(TTL + 40),
|
timer:sleep(TTL + 40),
|
||||||
{error, not_found} = AuthCacheModule:get(Key),
|
{error, not_found} = AuthCacheModule:get(Key),
|
||||||
Pid ! {ok, self(), Ref}
|
Pid ! {ok, self(), Ref}
|
||||||
|
|
Loading…
Reference in New Issue