Packages
ferricstore
0.7.4
0.11.14
0.11.12
0.11.11
0.11.10
0.11.9
0.11.8
0.11.7
0.11.6
0.11.5
0.11.4
0.11.3
0.11.2
0.11.1
0.11.0
0.10.3
0.10.2
0.10.1
0.10.0
0.9.1
0.9.0
0.8.0
0.7.5
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.0
0.5.7
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.3
0.4.2
0.4.1
0.4.0
0.3.7
0.3.6
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.2.0
0.1.0
FerricFlow durable workflows and queues with native-protocol storage, Raft durability, and Bitcask persistence.
Current section
Files
Jump to
Current section
Files
lib/ferricstore/flow/lmdb_query_window.ex
defmodule Ferricstore.Flow.LMDBQueryWindow do
@moduledoc false
@u64_decimal_zero_pad "00000000000000000000"
def time_seek_key(prefix, ms) when is_binary(prefix) and is_integer(ms),
do: prefix <> pad_u64(ms)
def time_upper_seek_key(prefix, ms) when is_binary(prefix) and is_integer(ms),
do: prefix <> pad_u64(ms) <> <<255>>
def pad_u64(value) when is_integer(value) and value >= 0 do
encoded = Integer.to_string(value)
case byte_size(encoded) do
size when size < 20 -> binary_part(@u64_decimal_zero_pad, 0, 20 - size) <> encoded
_size -> encoded
end
end
def query_scan_count(count, default_scan_limit) when is_integer(count) and count > 0 do
max_scan =
Application.get_env(
:ferricstore,
:flow_lmdb_query_scan_limit,
default_scan_limit
)
max_scan =
case max_scan do
value when is_integer(value) and value > 0 -> value
_ -> default_scan_limit
end
scan_count(count, max_scan)
end
def history_query_scan_count(count, true, _max_history_events)
when is_integer(count) and count > 0,
do: count
def history_query_scan_count(count, false, max_history_events)
when is_integer(count) and count > 0 do
max_scan =
Application.get_env(
:ferricstore,
:flow_lmdb_history_query_scan_limit,
max_history_events
)
max_scan =
case max_scan do
value when is_integer(value) and value > 0 -> min(value, max_history_events)
_ -> max_history_events
end
scan_count(count, max_scan)
end
defp scan_count(count, max_scan) do
count
|> Kernel.+(64)
|> max(count * 4)
|> min(max_scan)
|> max(count)
end
end