User's Guide
Reference Manual
Release Notes
PDF
Top

Mnesia
Reference Manual
Version 4.13.2

Expand All
Contract All

Table of Contents

- mnesia
  - Top of manual page
  - abort/1
  - activate_checkpoint/1
  - activity/2
  - activity/4
  - add_table_copy/3
  - add_table_index/2
  - all_keys/1
  - async_dirty/2
  - backup/1
  - backup_checkpoint/2
  - change_config/2
  - change_table_access_mode/2
  - change_table_copy_type/3
  - change_table_load_order/2
  - change_table_majority/2
  - clear_table/1
  - create_schema/1
  - create_table/2
  - deactivate_checkpoint/1
  - del_table_copy/2
  - del_table_index/2
  - delete/1
  - delete/3
  - delete_object/1
  - delete_object/3
  - delete_schema/1
  - delete_table/1
  - dirty_all_keys/1
  - dirty_delete/1
  - dirty_delete/2
  - dirty_delete_object/1
  - dirty_delete_object/2
  - dirty_first/1
  - dirty_index_match_object/2
  - dirty_index_match_object/3
  - dirty_index_read/3
  - dirty_last/1
  - dirty_match_object/1
  - dirty_match_object/2
  - dirty_next/2
  - dirty_prev/2
  - dirty_read/1
  - dirty_read/2
  - dirty_select/2
  - dirty_slot/2
  - dirty_update_counter/2
  - dirty_update_counter/3
  - dirty_write/1
  - dirty_write/2
  - dump_log/0
  - dump_tables/1
  - dump_to_textfile/1
  - error_description/1
  - ets/2
  - first/1
  - foldl/3
  - foldr/3
  - force_load_table/1
  - index_match_object/2
  - index_match_object/4
  - index_read/3
  - info/0
  - install_fallback/1
  - install_fallback/1
  - install_fallback/2
  - is_transaction/0
  - last/1
  - load_textfile/1
  - lock/2
  - match_object/1
  - match_object/3
  - move_table_copy/3
  - next/2
  - prev/2
  - read/1
  - read/2
  - read/3
  - read_lock_table/1
  - report_event/1
  - restore/2
  - s_delete/1
  - s_delete_object/1
  - s_write/1
  - schema/0
  - schema/1
  - select/2
  - select/4
  - select/1
  - set_debug_level/1
  - set_master_nodes/1
  - set_master_nodes/2
  - snmp_close_table/1
  - snmp_get_mnesia_key/2
  - snmp_get_next_index/2
  - snmp_get_row/2
  - snmp_open_table/2
  - start/0
  - stop/0
  - subscribe/1
  - sync_dirty/2
  - sync_log/0
  - sync_transaction/3
  - system_info/1
  - table/1
  - table_info/2
  - transaction/2
  - transform_table/4
  - transform_table/3
  - traverse_backup/4
  - uninstall_fallback/0
  - uninstall_fallback/1
  - unsubscribe/1
  - wait_for_tables/2
  - wread/1
  - write/1
  - write/3
  - write_lock_table/1
- mnesia_frag_hash
  - Top of manual page
  - init_state/2
  - add_frag/1
  - del_frag/1
  - key_to_frag_number/2
  - match_spec_to_frag_numbers/2
- mnesia_registry
  - Top of manual page
  - create_table/1
  - create_table/2

# mnesia_frag_hash

### MODULE

mnesia_frag_hash

### MODULE SUMMARY

Defines mnesia_frag_hash callback behavior

### DESCRIPTION

This module defines a callback behavior for user-defined hash functions of fragmented tables.

Which module that is selected to implement the mnesia_frag_hash behavior for a particular fragmented table is specified together with the other frag_properties. The hash_module defines the module name. The 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.

### 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.

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.

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.

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.

### See Also

mnesia(3)