File: mnesia_frag_hash.3

package info (click to toggle)
erlang-manpages 1%3A12.b.3-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,188 kB
  • ctags: 2
  • sloc: makefile: 68; perl: 30; sh: 15
file content (131 lines) | stat: -rw-r--r-- 4,250 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
.TH mnesia_frag_hash 3 "mnesia  4.4.3" "Ericsson AB" "ERLANG MODULE DEFINITION"
.SH MODULE
mnesia_frag_hash \- Defines mnesia_frag_hash callback behaviour
.SH DESCRIPTION
.LP
The module \fImnesia_frag_hash\fR defines a callback behaviour for user defined hash functions of fragmented tables\&.
.LP
Which module that is selected to implement the \fImnesia_frag_hash\fR behaviour for a particular fragmented table is specified together with the other \fIfrag_properties\fR\&. The \fIhash_module\fR defines the module name\&. The \fIhash_state\fR defines the initial hash state\&.
.LP
It 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

.SH EXPORTS
.LP
.B
init_state(Tab, State) -> NewState | abort(Reason)
.br
.RS
.TP
Types
Tab = atom()
.br
State = term()
.br
NewState = term()
.br
Reason = term()
.br
.RE
.RS
.LP
This function is invoked when a fragmented table is created with \fImnesia:create_table/2\fR or when a normal (un-fragmented) table is converted to be a fragmented table with \fImnesia:change_table_frag/2\fR\&.
.LP
Note that the \fIadd_frag/2\fR function will be invoked one time each for the rest of the fragments (all but number 1) as a part of the table creation procedure\&.
.LP
\fIState\fR is the initial value of the \fIhash_state\fR\fIfrag_property\fR\&. The \fINewState\fR will be stored as \fIhash_state\fR among the other \fIfrag_properties\fR\&. 
.RE
.LP
.B
add_frag(State) -> {NewState, IterFrags, AdditionalLockFrags} | abort(Reason)
.br
.RS
.TP
Types
State = term()
.br
NewState = term()
.br
IterFrags = [integer()]
.br
AdditionalLockFrags = [integer()]
.br
Reason = term()
.br
.RE
.RS
.LP
In order to scale well, it is a good idea ensure that the records are evenly distributed over all fragments including the new one\&.
.LP
The \fINewState\fR will be stored as \fIhash_state\fR among the other \fIfrag_properties\fR\&. 
.LP
As a part of the \fIadd_frag\fR procedure, Mnesia will iterate over all fragments corresponding to the \fIIterFrags\fR numbers and invoke \fIkey_to_frag_number(NewState, RecordKey)\fR for each record\&. If the new fragment differs from the old fragment, the record will be moved to the new fragment\&.
.LP
As the \fIadd_frag\fR procedure is a part of a schema transaction Mnesia will acquire a write locks on the affected tables\&. That is both the fragments corresponding to \fIIterFrags\fR and those corresponding to \fIAdditionalLockFrags\fR\&.
.RE
.LP
.B
del_frag(State) -> {NewState, IterFrags, AdditionalLockFrags} | abort(Reason)
.br
.RS
.TP
Types
State = term()
.br
NewState = term()
.br
IterFrags = [integer()]
.br
AdditionalLockFrags = [integer()]
.br
Reason = term()
.br
.RE
.RS
.LP
The \fINewState\fR will be stored as \fIhash_state\fR among the other \fIfrag_properties\fR\&. 
.LP
As a part of the \fIdel_frag\fR procedure, Mnesia will iterate over all fragments corresponding to the \fIIterFrags\fR numbers and invoke \fIkey_to_frag_number(NewState, RecordKey)\fR for each record\&. If the new fragment differs from the old fragment, the record will be moved to the new fragment\&.
.LP
Note that all records in the last fragment must be moved to another fragment as the entire fragment will be deleted\&.
.LP
As the \fIdel_frag\fR procedure is a part of a schema transaction Mnesia will acquire a write locks on the affected tables\&. That is both the fragments corresponding to \fIIterFrags\fR and those corresponding to \fIAdditionalLockFrags\fR\&.
.RE
.LP
.B
key_to_frag_number(State, Key) -> FragNum | abort(Reason)
.br
.RS
.TP
Types
FragNum = integer()()
.br
Reason = term()
.br
.RE
.RS
.LP
This function is invoked whenever Mnesia needs to determine which fragment a certain record belongs to\&. It is typically invoked at read, write and delete\&.
.RE
.LP
.B
match_spec_to_frag_numbers(State, MatchSpec) -> FragNums | abort(Reason)
.br
.RS
.TP
Types
MatcSpec = ets_select_match_spec()
.br
FragNums = [FragNum]
.br
FragNum = integer()
.br
Reason = term()
.br
.RE
.RS
.LP
This function is invoked whenever Mnesia needs to determine which fragments that needs to be searched for a MatchSpec\&. It is typically invoked at select and match_object\&.
.RE
.SH SEE ALSO
.LP
mnesia(3)