Problem
In PR #14897 streamMoveIdmpKeys() was implemented such that it takes in int slot as input parameter and iterates over server.db[0].stream_idmp_keys and moves the keys which belong to slot into stream_idmp_keys.
Therefore asmTriggerBackgroundTrim() was calling streamMoveIdmpKeys() for each slot in trim ranges.
Time Complexity
Lets say number of slots be S (it could be 16,384 in worst case)
and let K be number of keys in server.db[0].stream_idmp_keys
then the total time complexity would be O(S x K)
Suggested Fix
we have changed the implementation of streamMoveIdmpKeys() such that it now takes in slotRangeArray *slots as an input parameter and iterates over server.db[0].stream_idmp_keys once, catching all the keys which fall in the slots range and moving them to stream_idmp_keys
Therefore asmTriggerBackgroundTrim() would now call streamMoveIdmpKeys() just once.
Time Complexity
say R is number of ranges in slots and let K be number of keys in server.db[0].stream_idmp_keys
then the total time complexity would be O(R x K)
since O(R x K) is better than O(S x K) because number of slots would almost always be greater than number of ranges in slotRangeArray *slots
(for a single merged range like 0–16383, R = 1 but S = 16 384).
Problem
In PR #14897
streamMoveIdmpKeys()was implemented such that it takes inint slotas input parameter and iterates overserver.db[0].stream_idmp_keysand moves the keys which belong toslotintostream_idmp_keys.Therefore asmTriggerBackgroundTrim() was calling
streamMoveIdmpKeys()for each slot in trim ranges.Time Complexity
Lets say number of slots be
S(it could be 16,384 in worst case)and let
Kbe number of keys in server.db[0].stream_idmp_keysthen the total time complexity would be
O(S x K)Suggested Fix
we have changed the implementation of streamMoveIdmpKeys() such that it now takes in
slotRangeArray *slotsas an input parameter and iterates overserver.db[0].stream_idmp_keysonce, catching all the keys which fall in theslotsrange and moving them tostream_idmp_keysTherefore asmTriggerBackgroundTrim() would now call
streamMoveIdmpKeys()just once.Time Complexity
say
Ris number of ranges inslotsand letKbe number of keys in server.db[0].stream_idmp_keysthen the total time complexity would be
O(R x K)since
O(R x K)is better thanO(S x K)because number of slots would almost always be greater than number of ranges inslotRangeArray *slots(for a single merged range like
0–16383,R = 1butS = 16 384).