mnesia_frag_hash(3erl)
π NAME π
mnesia_frag_hash β defines the mnesia_frag_hash callback behavior. This is the Erlang Module Definition page for mnesia_frag_hash(3erl), bestie. π
β¨ DESCRIPTION β¨
This module defines a callback behavior for user-defined hash functions of fragmented tables.
Which module gets selected to implement the mnesia_frag_hash behavior for a particular fragmented table is specified together with the other frag_properties. hash_module defines the module name. hash_state defines the initial hash state.
This module implements dynamic hashing, which is a kind of hashing that grows nicely when new fragments are added. It is well suited for scalable hash tables. Iconic behavior, honestly. π
π EXPORTS π
π«Ά init_state(Tab, State) -> NewState | abort(Reason) π«Ά
Types:
Tab = atom()
State = term()
NewState = term()
Reason = term()
Starts when a fragmented table is created with the function mnesia:create_table/2 or when a normal (unfragmented) table is converted to be a fragmented table with mnesia:change_table_frag/2.
Notice that the function add_frag/2 is started one time for each of the other fragments (except number 1) as a part of the table creation procedure.
State is the initial value of the hash_state frag_property. NewState is stored as hash_state among the other frag_properties.
π¦ add_frag(State) -> {NewState, IterFrags, AdditionalLockFrags} | abort(Reason) π¦
Types:
State = term()
NewState = term()
IterFrags = [integer()]
AdditionalLockFrags = [integer()]
Reason = term()
To scale well, it is a good idea to ensure that the records are evenly distributed over all fragments, including the new one.
NewState is stored as hash_state among the other frag_properties.
As a part of the add_frag procedure, Mnesia iterates over all fragments corresponding to the IterFrags numbers and starts key_to_frag_number(NewState,RecordKey) for each record. If the new fragment differs from the old fragment, the record is moved to the new fragment.
As the add_frag procedure is a part of a schema transaction, Mnesia acquires write locks on the affected tables. That is, both the fragments corresponding to IterFrags and those corresponding to AdditionalLockFrags. Lock moment, periodt. π
πΈ del_frag(State) -> {NewState, IterFrags, AdditionalLockFrags} | abort(Reason) πΈ
Types:
State = term()
NewState = term()
IterFrags = [integer()]
AdditionalLockFrags = [integer()]
Reason = term()
NewState is stored as hash_state among the other frag_properties.
As a part of the del_frag procedure, Mnesia iterates over all fragments corresponding to the IterFrags numbers and starts key_to_frag_number(NewState,RecordKey) for each record. If the new fragment differs from the old fragment, the record is moved to the new fragment.
Notice that all records in the last fragment must be moved to another fragment, as the entire fragment is deleted.
As the del_frag procedure is a part of a schema transaction, Mnesia acquires write locks on the affected tables. That is, both the fragments corresponding to IterFrags and those corresponding to AdditionalLockFrags. Same lock energy, different fragment situation. π
π key_to_frag_number(State, Key) -> FragNum | abort(Reason) π
Types:
FragNum = integer()
Reason = term()
Starts whenever Mnesia needs to determine which fragment a certain record belongs to. It is typically started at read, write, and delete. Main character lookup behavior, fr fr. π₯
π§ match_spec_to_frag_numbers(State, MatchSpec) -> FragNums | abort(Reason) π§
Types:
MatcSpec = ets_select_match_spec()
FragNums = [FragNum]
FragNum = integer()
Reason = term()
This function is called whenever Mnesia needs to determine which fragments that need to be searched for a MatchSpec. It is typically called by select and match_object.
Yes, MatcSpec is spelled exactly like that in the original types list β copying it character for character, bestie. π
π SEE ALSO π
okay that's the whole page, bestie! π«Ά Source: Ericsson AB. Version: mnesia 4.21.4.2. Date: the original footer does not show one, so I am not inventing it. Page: mnesia_frag_hash(3erl). π
π¦ where this page comes from
- ubuntu noble: erlang-manpages 1:25.3.2.8+dfsg-1ubuntu4 Β· Apache-2.0
- ubuntu noble: erlang-manpages 1:25.3.2.8+dfsg-1ubuntu4.8 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms