File: mnesia_frag_hash.html

package info (click to toggle)
erlang-doc-html 1%3A11.b.2-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 23,284 kB
  • ctags: 10,724
  • sloc: erlang: 505; ansic: 323; makefile: 62; perl: 61; sh: 45
file content (210 lines) | stat: -rw-r--r-- 6,745 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- This document was generated using DocBuilder 3.3.3 -->
<HTML>
<HEAD>
  <TITLE>mnesia_frag_hash</TITLE>
  <SCRIPT type="text/javascript" src="../../../../doc/erlresolvelinks.js">
</SCRIPT>
  <STYLE TYPE="text/css">
<!--
    .REFBODY     { margin-left: 13mm }
    .REFTYPES    { margin-left: 8mm }
-->
  </STYLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#FF00FF"
      ALINK="#FF0000">
<!-- refpage -->
<CENTER>
<A HREF="http://www.erlang.se">
  <IMG BORDER=0 ALT="[Ericsson AB]" SRC="min_head.gif">
</A>
<H1>mnesia_frag_hash</H1>
</CENTER>

<H3>MODULE</H3>
<DIV CLASS=REFBODY>
mnesia_frag_hash
</DIV>

<H3>MODULE SUMMARY</H3>
<DIV CLASS=REFBODY>
Defines mnesia_frag_hash callback behaviour
</DIV>

<H3>DESCRIPTION</H3>
<DIV CLASS=REFBODY>

<P>The module <CODE>mnesia_frag_hash</CODE> defines a callback
        behaviour for user defined hash functions of fragmented tables.
<P>Which module that is selected to implement the <CODE>mnesia_frag_hash</CODE>
behaviour for a particular fragmented table is specified together
with the other <CODE>frag_properties</CODE>. The <CODE>hash_module</CODE> defines
the module name. The <CODE>hash_state</CODE> defines the initial hash state.
<P>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
</DIV>

<H3>EXPORTS</H3>

<P><A NAME="init_state/2"><STRONG><CODE>init_state(Tab, State) -&#62; NewState | abort(Reason)</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab = atom()</CODE></STRONG><BR>
<STRONG><CODE>State = term()</CODE></STRONG><BR>
<STRONG><CODE>NewState = term()</CODE></STRONG><BR>
<STRONG><CODE>Reason = term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>This function is invoked when a fragmented table is
created with <CODE>mnesia:create_table/2</CODE> or when a
normal (un-fragmented) table is converted to be a
fragmented table with <CODE>mnesia:change_table_frag/2</CODE>.
<P>Note that the <CODE>add_frag/2</CODE> 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.
<P><CODE>State</CODE> is the initial value of the <CODE>hash_state</CODE>
         <CODE>frag_property</CODE>. The <CODE>NewState</CODE> will be stored as
<CODE>hash_state</CODE> among the other <CODE>frag_properties</CODE>.


</DIV>

<P><A NAME="add_frag/1"><STRONG><CODE>add_frag(State) -&#62; {NewState, IterFrags, AdditionalLockFrags} | abort(Reason)</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>State = term()</CODE></STRONG><BR>
<STRONG><CODE>NewState = term()</CODE></STRONG><BR>
<STRONG><CODE>IterFrags = [integer()]</CODE></STRONG><BR>
<STRONG><CODE>AdditionalLockFrags = [integer()]</CODE></STRONG><BR>
<STRONG><CODE>Reason = term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>In order to scale well, it is a good idea ensure that the
         records are evenly distributed over all fragments including
         the new one.
<P>The <CODE>NewState</CODE> will be stored as <CODE>hash_state</CODE> among the
other <CODE>frag_properties</CODE>. 
        
         
<P>As a part of the <CODE>add_frag</CODE> procedure, Mnesia will iterate
over all fragments corresponding to the <CODE>IterFrags</CODE> numbers
and invoke <CODE>key_to_frag_number(NewState,RecordKey)</CODE> for
each record. If the new fragment differs from the old
fragment, the record will be moved to the new fragment.
<P>As the <CODE>add_frag</CODE> 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 <CODE>IterFrags</CODE> and those corresponding to
<CODE>AdditionalLockFrags</CODE>.

</DIV>

<P><A NAME="del_frag/1"><STRONG><CODE>del_frag(State) -&#62; {NewState, IterFrags, AdditionalLockFrags} | abort(Reason)</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>State = term()</CODE></STRONG><BR>
<STRONG><CODE>NewState = term()</CODE></STRONG><BR>
<STRONG><CODE>IterFrags = [integer()]</CODE></STRONG><BR>
<STRONG><CODE>AdditionalLockFrags = [integer()]</CODE></STRONG><BR>
<STRONG><CODE>Reason = term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>The <CODE>NewState</CODE> will be stored as <CODE>hash_state</CODE> among the
other <CODE>frag_properties</CODE>. 
        
         
<P>As a part of the <CODE>del_frag</CODE> procedure, Mnesia will iterate
over all fragments corresponding to the <CODE>IterFrags</CODE> numbers
and invoke <CODE>key_to_frag_number(NewState,RecordKey)</CODE> for
each record. If the new fragment differs from the old
fragment, the record will be moved to the new fragment.
<P>Note that all records in the last fragment must be moved to
another fragment as the entire fragment will be deleted.
<P>As the <CODE>del_frag</CODE> 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 <CODE>IterFrags</CODE> and those corresponding to
<CODE>AdditionalLockFrags</CODE>.

</DIV>

<P><A NAME="key_to_frag_number/2"><STRONG><CODE>key_to_frag_number(State, Key) -&#62; FragNum | abort(Reason)</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>FragNum = integer()()</CODE></STRONG><BR>
<STRONG><CODE>Reason = term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>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.
</DIV>

<P><A NAME="match_spec_to_frag_numbers/2"><STRONG><CODE>match_spec_to_frag_numbers(State, MatchSpec) -&#62; FragNums | abort(Reason)</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>MatcSpec = ets_select_match_spec()</CODE></STRONG><BR>
<STRONG><CODE>FragNums = [FragNum]</CODE></STRONG><BR>
<STRONG><CODE>FragNum = integer()</CODE></STRONG><BR>
<STRONG><CODE>Reason = term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>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.
</DIV>

<H3>See Also</H3>
<DIV CLASS=REFBODY>

<P> mnesia(3)


</DIV>

<H3>AUTHORS</H3>
<DIV CLASS=REFBODY>
 Hkan Mattsson - support@erlang.ericsson.se<BR>

</DIV>
<CENTER>
<HR>
<SMALL>mnesia 4.3.3<BR>
Copyright &copy; 1991-2006
<A HREF="http://www.erlang.se">Ericsson AB</A><BR>
</SMALL>
</CENTER>
</BODY>
</HTML>