[erlang-questions] Why is Mnesia read-locking an entire table?
Dan Gudmundsson
dangud@REDACTED
Sat Nov 3 18:49:23 CET 2012
Mnesia grabs locks before the actual operation is performed,
a select call thus requires a table lock since mnesia does not analyse
the select expression.
/Dan
On Sat, Nov 3, 2012 at 2:32 PM, Jim <jrosenblum@REDACTED> wrote:
> Dear List
>
> I am having trouble understanding why Mnesia is grabbing a read-lock on an
> entire table. Can someone give me any insight?
>
> Here are some facts (beliefs ;)
>
> * The table is of type ordered_set
> * My key is a two-tuple, {unix-style-milliseconds-since-1970, Key} as in,
> {1351872742126278,"BI13626"}},
> * There are two additional indexed columns
> * I am frequently, in the same transaction, deleting and inserting two
> records which differ *only* in the time-stamp portion of the key – I am
> replacing an older version of the record with a newer version
> * All access is done within a function that is passed to
> mnesia:transaction/1
> * All access to the table in question is via:
> o mnesia:index_read/3 where all three variables being passed in are
> *always* bound, or
> o mnesia:select/2 as shown below
>
>
> lookup_since(Since) ->
> M = [{#key_to_value{update_map={'$1', '_'}, _='_'},
> [{'>', '$1', Since}], ['$_']}]
> {ok, mnesia:select(key_to_value, M)}.
>
> or
>
> lookup_keylist(Keys, Since) ->
> M = [{#key_to_value{update_map={'$1', K}, _='_'},
> [{'>', '$1', Since}], ['$_']} || K <- Keys],
> {ok, mnesia:select(key_to_value, M)}.
>
> Mnesia:info reports the following
>
>
>
> Lock: {{key_to_value,'______WHOLETABLE_____'},read,{tid,247,<0.1717.0>}}
>
> Lock:
> {{key_to_value,{1351872742126278,"BI13626"}},write,{tid,247,<0.1717.0>}}
>
> Lock:
> {{key_to_value,{1351872742130724,"BI13623"}},write,{tid,247,<0.1717.0>}}
>
> Lock:
> {{key_to_value,{1351872742136170,"BI13621"}},write,{tid,247,<0.1717.0>}}
>
> Lock:
> {{key_to_value,{1351872742140957,"BI13616"}},write,{tid,247,<0.1717.0>}}
>
> Lock:
> {{key_to_value,{1351872746638841,"BI13628"}},write,{tid,247,<0.1717.0>}}
>
> Lock:
> {{key_to_value,{1351872746640989,"BI13626"}},write,{tid,247,<0.1717.0>}}
>
> Lock:
> {{key_to_value,{1351872746642481,"BI13623"}},write,{tid,247,<0.1717.0>}}
>
> Lock:
> {{key_to_value,{1351872746643406,"BI13621"}},write,{tid,247,<0.1717.0>}}
>
> Lock:
> {{key_to_value,{1351872746644468,"BI13616"}},write,{tid,247,<0.1717.0>}}
>
> Lock: {{scope_to_keys,"6B-PED"},write,{tid,247,<0.1717.0>}}
>
> Lock: {{scope_to_keys,"InPatient"},write,{tid,247,<0.1717.0>}}
>
> Lock: {{type_to_keys,"b_index"},write,{tid,247,<0.1717.0>}}
>
> ---> Processes waiting for locks <---
>
> ---> Participant transactions <---
>
> ---> Coordinator transactions <---
>
> Tid: 247 (owned by <0.1717.0>)
>
> ---> Uncertain transactions <---
>
>
>
>
>
> Here is a second example of the mnesia:info() output
>
>
>
> ---> Processes holding locks <---
>
> Lock: {{key_to_value,'______WHOLETABLE_____'},read,{tid,707,<0.1876.0>}}
>
> Lock:
> {{key_to_value,{1351872861465784,"VI14543"}},write,{tid,707,<0.1876.0>}}
>
> Lock:
> {{key_to_value,{1351872868375564,"VI14543"}},write,{tid,707,<0.1876.0>}}
>
> ---> Processes waiting for locks <---
>
> ---> Participant transactions <---
>
> ---> Coordinator transactions <---
>
> Tid: 707 (owned by <0.1876.0>)
>
> ---> Uncertain transactions <---
>
> Any help would be greatly appreciated,
> Jr0
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
More information about the erlang-questions
mailing list