raft_kv v0.2.0 RaftKV.SplitMergePolicy View Source
An Elixir struct to specify when to split/merge shards in a keyspace.
:raft_kv uses the following 3 stats to judge whether splitting/merging should be done:
- number of keys in a shard
- aggregated data size (in an arbitrary unit) in a shard
- current load (computing resource required, in an arbitrary unit) of a shard
Fields:
:max_shardsMaximum number of shards. If number of shards is the same as this value, no further split occurs.:min_shardsMinimum number of shards. If number of shards is the same as this value, no further merge occurs.:max_keys_per_shardThreshold number of keys for shard split. Shards that contains more keys than this value become candidates for split. Ifnil, shards are not split due to number of keys. Defaults tonil.:max_size_per_shardThreshold size for shard split. Shards whose aggregated size exceeds this value become candidates for split. Ifnil, shards are not split due to size. Defaults tonil.:max_load_per_shardThreshold load for shard split. Shards that have been experiencing load above this value become candidates for split. Ifnil, shards are not split due to load. Defaults tonil.:load_per_query_to_missing_keyRaftKV.query/4returns{:error, :key_not_found}if targetkeydoes not exist. This value is used as the “load” for such queries. Defaults to0.:merge_threshold_ratio: For each of the 3 types of split thresholds above (:max_keys_per_shard,:max_size_per_shardand:max_load_per_shard), merge thresholds are calculated by multiplying this ratio. Consecutive 2 shards become candidates for merge if they together (1) contain less keys than the threshold, (2) contain smaller size than the threshold, and (3) experience less load than the threshold. Defaults to0.5.
Link to this section Summary
Functions
Type-aware getter for load_per_query_to_missing_key
Type-aware setter for load_per_query_to_missing_key
Type-aware getter for max_keys_per_shard
Type-aware setter for max_keys_per_shard
Type-aware getter for max_load_per_shard
Type-aware setter for max_load_per_shard
Type-aware getter for max_shards
Type-aware setter for max_shards
Type-aware getter for max_size_per_shard
Type-aware setter for max_size_per_shard
Type-aware getter for merge_threshold_ratio
Type-aware setter for merge_threshold_ratio
Type-aware getter for min_shards
Type-aware setter for min_shards
Creates a new instance of RaftKV.SplitMergePolicy by using the given dict
A variant of new/1 which returns t or raise if validation fails
Updates an existing instance of RaftKV.SplitMergePolicy with the given dict.
The values in the dict are validated by each field’s valid?/1 function.
Returns {:ok, valid_struct} or {:error, reason}
A variant of update/2 which returns t or raise if validation fails.
In other words, update/2 followed by Croma.Result.get!/1
Checks if the given value belongs to t/0 or not
Link to this section Types
t() :: %RaftKV.SplitMergePolicy{
load_per_query_to_missing_key: Croma.NonNegInteger.t(),
max_keys_per_shard: Croma.TypeGen.Nilable.Croma.PosInteger.t(),
max_load_per_shard: Croma.TypeGen.Nilable.Croma.PosInteger.t(),
max_shards: Croma.PosInteger.t(),
max_size_per_shard: Croma.TypeGen.Nilable.Croma.PosInteger.t(),
merge_threshold_ratio: RaftKV.SplitMergePolicy.MergeThresholdRatio.t(),
min_shards: Croma.PosInteger.t()
}
Link to this section Functions
load_per_query_to_missing_key(t()) :: Croma.NonNegInteger.t()
Type-aware getter for load_per_query_to_missing_key.
load_per_query_to_missing_key(t(), Croma.NonNegInteger.t()) :: t()
Type-aware setter for load_per_query_to_missing_key.
max_keys_per_shard(t()) :: Croma.TypeGen.Nilable.Croma.PosInteger.t()
Type-aware getter for max_keys_per_shard.
max_keys_per_shard(t(), Croma.TypeGen.Nilable.Croma.PosInteger.t()) :: t()
Type-aware setter for max_keys_per_shard.
max_load_per_shard(t()) :: Croma.TypeGen.Nilable.Croma.PosInteger.t()
Type-aware getter for max_load_per_shard.
max_load_per_shard(t(), Croma.TypeGen.Nilable.Croma.PosInteger.t()) :: t()
Type-aware setter for max_load_per_shard.
max_shards(t()) :: Croma.PosInteger.t()
Type-aware getter for max_shards.
Type-aware setter for max_shards.
max_size_per_shard(t()) :: Croma.TypeGen.Nilable.Croma.PosInteger.t()
Type-aware getter for max_size_per_shard.
max_size_per_shard(t(), Croma.TypeGen.Nilable.Croma.PosInteger.t()) :: t()
Type-aware setter for max_size_per_shard.
merge_threshold_ratio(t()) :: RaftKV.SplitMergePolicy.MergeThresholdRatio.t()
Type-aware getter for merge_threshold_ratio.
merge_threshold_ratio(t(), RaftKV.SplitMergePolicy.MergeThresholdRatio.t()) :: t()
Type-aware setter for merge_threshold_ratio.
min_shards(t()) :: Croma.PosInteger.t()
Type-aware getter for min_shards.
Type-aware setter for min_shards.
Creates a new instance of RaftKV.SplitMergePolicy by using the given dict.
For missing fields, default/0 of each field type will be used.
Returns {:ok, valid_struct} or {:error, reason}.
The values in the dict are validated by each field’s valid?/1 function.
A variant of new/1 which returns t or raise if validation fails.
In other words, new/1 followed by Croma.Result.get!/1.
Updates an existing instance of RaftKV.SplitMergePolicy with the given dict.
The values in the dict are validated by each field’s valid?/1 function.
Returns {:ok, valid_struct} or {:error, reason}.
A variant of update/2 which returns t or raise if validation fails.
In other words, update/2 followed by Croma.Result.get!/1.
Checks if the given value belongs to t/0 or not.