From 29345aaa30e7e5f931b12abd55165c2d1ca6489e Mon Sep 17 00:00:00 2001 From: ieQu1 <99872536+ieQu1@users.noreply.github.com> Date: Mon, 20 May 2024 15:53:11 +0200 Subject: [PATCH] fix(ds): Fix idle event generation in bitfield_lts layout --- apps/emqx/src/emqx_ds_schema.erl | 7 +------ .../src/emqx_ds_storage_bitfield_lts.erl | 8 +++++--- .../test/emqx_ds_replication_SUITE.erl | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/apps/emqx/src/emqx_ds_schema.erl b/apps/emqx/src/emqx_ds_schema.erl index 87f87aa7f..dc395b291 100644 --- a/apps/emqx/src/emqx_ds_schema.erl +++ b/apps/emqx/src/emqx_ds_schema.erl @@ -246,7 +246,7 @@ fields(layout_builtin_reference) -> reference, #{ 'readOnly' => true, - importance => ?IMPORTANCE_HIDDEN + importance => ?IMPORTANCE_LOW } )} ]. @@ -273,17 +273,12 @@ ds_schema(Options) -> Options ). --ifndef(TEST). -builtin_layouts() -> - [ref(layout_builtin_wildcard_optimized)]. --else. builtin_layouts() -> %% Reference layout stores everything in one stream, so it's not %% suitable for production use. However, it's very simple and %% produces a very predictabale replay order, which can be useful %% for testing and debugging: [ref(layout_builtin_wildcard_optimized), ref(layout_builtin_reference)]. --endif. sc(Type, Meta) -> hoconsc:mk(Type, Meta). diff --git a/apps/emqx_durable_storage/src/emqx_ds_storage_bitfield_lts.erl b/apps/emqx_durable_storage/src/emqx_ds_storage_bitfield_lts.erl index 8acb6e529..7d058109e 100644 --- a/apps/emqx_durable_storage/src/emqx_ds_storage_bitfield_lts.erl +++ b/apps/emqx_durable_storage/src/emqx_ds_storage_bitfield_lts.erl @@ -161,7 +161,7 @@ %% GVar used for idle detection: -define(IDLE_DETECT, idle_detect). --define(EPOCH(S, TS), (TS bsl S#s.ts_bits)). +-define(EPOCH(S, TS), (TS bsr S#s.ts_offset)). -ifdef(TEST). -include_lib("eunit/include/eunit.hrl"). @@ -458,7 +458,7 @@ next( SafeCutoffTime = case HasCutoff of true -> - (Now bsr TSOffset) bsl TSOffset; + ?EPOCH(Schema, Now) bsl TSOffset; false -> 1 bsl TSBits - 1 end, @@ -561,13 +561,15 @@ handle_event(_ShardId, State = #s{gvars = Gvars}, Time, tick) -> LastWrittenTs = 0 end, case Latch of - false when ?EPOCH(State, Time) > ?EPOCH(State, LastWrittenTs) -> + false when ?EPOCH(State, Time) > ?EPOCH(State, LastWrittenTs) + 1 -> ets:insert(Gvars, {?IDLE_DETECT, true, LastWrittenTs}), [dummy_event]; _ -> [] end; handle_event(_ShardId, _Data, _Time, _Event) -> + %% `dummy_event' goes here and does nothing. But it forces update + %% of `Time' in the replication layer. []. %%================================================================================ diff --git a/apps/emqx_durable_storage/test/emqx_ds_replication_SUITE.erl b/apps/emqx_durable_storage/test/emqx_ds_replication_SUITE.erl index eacf7e301..941e20641 100644 --- a/apps/emqx_durable_storage/test/emqx_ds_replication_SUITE.erl +++ b/apps/emqx_durable_storage/test/emqx_ds_replication_SUITE.erl @@ -183,7 +183,7 @@ t_rebalance(Config) -> ], Stream1 = emqx_utils_stream:interleave( [ - {50, Stream0}, + {10, Stream0}, emqx_utils_stream:const(add_generation) ], false