[erlang-questions] How to extend mensia lock to support conditionally lock?
Ulf Wiger
ulf@REDACTED
Thu Jul 24 22:09:41 CEST 2008
As far as I know there are no docs on the locker implementation
in mnesia, but I do recall some tricky bugs in this area. For
one thing, the locker also handles the deadlock prevention
logic, so it must keep track of dependencies to some extent.
You can read the code and try to form your own opinion,
but before you start trying to extend this part of mnesia,
possibly introducing deadlock bugs in your application,
you should carefully measure the performance of the
existing locking solutions: record locks, sticky locks
and table locks. You should also write a wrapper and see
if it gives you the kind of performance improvement you're
after. If it doesn't, you may be able to come up with some
really nifty extension of mnesia_locker through deep
meditation over the code. The next challenge, after ensuring
that it's stable, would then be to try to get it accepted as
an official extension to mnesia - otherwise, you'll be stuck
maintaining your own mnesia patches, and that's no fun
(been there, done that).
Table locks can be surprisingly efficient, esp if you don't
mix record and table locks too much. I'd advice some
experimentation down that alley first.
BR,
Ulf W
BR,
Ulf W
2008/7/24 devdoer bird <devdoer2@REDACTED>:
>
>
>
> 2008/7/24, Ulf Wiger <ulf@REDACTED>:
>>
>> If you are to gain any performance compared to a wrapper, or using
>> only table locks, you must do brain surgery on mnesia_locker. I
>> strongly advise against that. The relationship between record locks
>> and table locks is quite intricate.
>
>
> Yes.I want to gain some performance to lock part of the table.
> What's the intricate part of the locking system design?Can you give any docs
> about the design of the mensia table-lock and record lock?
>>
>> BR,
>> Ulf W
>>
>> 2008/7/24, devdoer bird <devdoer2@REDACTED>:
>> > The example I give is not good.,but I just need hack the mnesia lock :(.
>> >
>> > I want to lock part of the table and which part is controled by the
>> > record's
>> > key's value range .Currently mnesia only support record lock and table
>> > lock.
>> >
>> >
>> > 2008/7/24, Ulf Wiger <ulf@REDACTED>:
>> >>
>> >> I don't think you should hack mnesia for that. A simple wrapper
>> >> function will do nicely.
>> >>
>> >> BR,
>> >> Ulf W
>> >>
>> >> 2008/7/23, devdoer bird <devdoer2@REDACTED>:
>> >> > HI:
>> >> >
>> >> > I want to extend mnesia 's lock to add this function
>> >> > "mnesia:lock(LockItem,LockType,ConditionFun)" .
>> >> >
>> >> > This function works in this way: If a table 's record passes the
>> >> > ConditionFun test,the the record is locked.
>> >> >
>> >> > Eg.
>> >> > I have a user table with the record: -record(user,{name,age}).
>> >> >
>> >> > I want to lock the user's whose name begines with 'a' ,I can code
>> >> > using
>> >> my
>> >> > customized " mnesia:lock(LockItem,LockType,ConditionFun)"
>> >> >
>> >> > like this:
>> >> >
>> >> > ConditionFun=fun(U)->
>> >> > if
>> >> > U#user.name=='a' -> true;
>> >> > true->false
>> >> > end
>> >> > end
>> >> > mnesia:lock(user,write,ConditionFun).
>> >> >
>> >> > that is I want to lock part of the table.
>> >> >
>> >> > Have anyone done this before? How shall I extend the mensia lock? Any
>> >> > information will be helpful, I 'm quite unfamiliar with mnesia lock
>> >> > system.
>> >> >
>> >>
>> >
>
>
More information about the erlang-questions
mailing list