1mnesia_frag_hash(3) Erlang Module Definition mnesia_frag_hash(3)
2
3
4
6 mnesia_frag_hash - Defines mnesia_frag_hash callback behavior
7
9 This module defines a callback behavior for user-defined hash functions
10 of fragmented tables.
11
12 Which module that is selected to implement the mnesia_frag_hash behav‐
13 ior for a particular fragmented table is specified together with the
14 other frag_properties. The hash_module defines the module name. The
15 hash_state defines the initial hash state.
16
17 This module implements dynamic hashing, which is a kind of hashing that
18 grows nicely when new fragments are added. It is well suited for scal‐
19 able hash tables.
20
22 init_state(Tab, State) -> NewState | abort(Reason)
23
24 Types:
25
26 Tab = atom()
27 State = term()
28 NewState = term()
29 Reason = term()
30
31 Starts when a fragmented table is created with the function mne‐
32 sia:create_table/2 or when a normal (unfragmented) table is con‐
33 verted to be a fragmented table with mnesia:change_table_frag/2.
34
35 Notice that the function add_frag/2 is started one time for each
36 of the other fragments (except number 1) as a part of the table
37 creation procedure.
38
39 State is the initial value of the hash_state frag_property. New‐
40 State is stored as hash_state among the other frag_properties.
41
42 add_frag(State) -> {NewState, IterFrags, AdditionalLockFrags} |
43 abort(Reason)
44
45 Types:
46
47 State = term()
48 NewState = term()
49 IterFrags = [integer()]
50 AdditionalLockFrags = [integer()]
51 Reason = term()
52
53 To scale well, it is a good idea to ensure that the records are
54 evenly distributed over all fragments, including the new one.
55
56 NewState is stored as hash_state among the other frag_proper‐
57 ties.
58
59 As a part of the add_frag procedure, Mnesia iterates over all
60 fragments corresponding to the IterFrags numbers and starts
61 key_to_frag_number(NewState,RecordKey) for each record. If the
62 new fragment differs from the old fragment, the record is moved
63 to the new fragment.
64
65 As the add_frag procedure is a part of a schema transaction,
66 Mnesia acquires write locks on the affected tables. That is,
67 both the fragments corresponding to IterFrags and those corre‐
68 sponding to AdditionalLockFrags.
69
70 del_frag(State) -> {NewState, IterFrags, AdditionalLockFrags} |
71 abort(Reason)
72
73 Types:
74
75 State = term()
76 NewState = term()
77 IterFrags = [integer()]
78 AdditionalLockFrags = [integer()]
79 Reason = term()
80
81 NewState is stored as hash_state among the other frag_proper‐
82 ties.
83
84 As a part of the del_frag procedure, Mnesia iterates over all
85 fragments corresponding to the IterFrags numbers and starts
86 key_to_frag_number(NewState,RecordKey) for each record. If the
87 new fragment differs from the old fragment, the record is moved
88 to the new fragment.
89
90 Notice that all records in the last fragment must be moved to
91 another fragment, as the entire fragment is deleted.
92
93 As the del_frag procedure is a part of a schema transaction,
94 Mnesia acquires write locks on the affected tables. That is,
95 both the fragments corresponding to IterFrags and those corre‐
96 sponding to AdditionalLockFrags.
97
98 key_to_frag_number(State, Key) -> FragNum | abort(Reason)
99
100 Types:
101
102 FragNum = integer()
103 Reason = term()
104
105 Starts whenever Mnesia needs to determine which fragment a cer‐
106 tain record belongs to. It is typically started at read, write,
107 and delete.
108
109 match_spec_to_frag_numbers(State, MatchSpec) -> FragNums | abort(Rea‐
110 son)
111
112 Types:
113
114 MatcSpec = ets_select_match_spec()
115 FragNums = [FragNum]
116 FragNum = integer()
117 Reason = term()
118
119 This function is called whenever Mnesia needs to determine which
120 fragments that need to be searched for a MatchSpec. It is typi‐
121 cally called by select and match_object.
122
124 mnesia(3)
125
126
127
128Ericsson AB mnesia 4.22.1 mnesia_frag_hash(3)