Browse Source

chore: cap replayq seg size under total size

Zaiming (Stone) Shi 3 years ago
parent
commit
f611cbab45
1 changed files with 5 additions and 2 deletions
  1. 5 2
      apps/emqx_resource/src/emqx_resource_worker.erl

+ 5 - 2
apps/emqx_resource/src/emqx_resource_worker.erl

@@ -117,13 +117,16 @@ init({Id, Index, Opts}) ->
     true = gproc_pool:connect_worker(Id, {Id, Index}),
     Name = name(Id, Index),
     BatchSize = maps:get(batch_size, Opts, ?DEFAULT_BATCH_SIZE),
+    SegBytes0 = maps:get(queue_seg_bytes, Opts, ?DEFAULT_QUEUE_SEG_SIZE),
+    TotalBytes = maps:get(max_queue_bytes, Opts, ?DEFAULT_QUEUE_SIZE),
+    SegBytes = min(SegBytes0, TotalBytes),
     Queue =
         case maps:get(enable_queue, Opts, false) of
             true ->
                 replayq:open(#{
                     dir => disk_queue_dir(Id, Index),
-                    seg_bytes => maps:get(queue_seg_bytes, Opts, ?DEFAULT_QUEUE_SEG_SIZE),
-                    max_total_bytes => maps:get(max_queue_bytes, Opts, ?DEFAULT_QUEUE_SIZE),
+                    seg_bytes => SegBytes,
+                    max_total_bytes => TotalBytes,
                     sizer => fun ?MODULE:estimate_size/1,
                     marshaller => fun ?MODULE:queue_item_marshaller/1
                 });