MySQL::NameLocker

3,074 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
3,074
On SlideShare
0
From Embeds
0
Number of Embeds
47
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

MySQL::NameLocker

  1. 1. Application Level Lock by MySQL with MoFedge. Tokuhiro Matsuno 2007-01-26(Fri) 社内勉強会
  2. 2. Bad Flow Validation Add Validation Add Session1 Session2 DB DOUBLE!
  3. 3. GET_LOCK/RELEASE_LOCK <ul><li>SELECT GET_LOCK(‘HOGE’, 10); </li></ul><ul><ul><li>10 is timeout. </li></ul></ul><ul><li>SELECT RELEASE_LOCK(‘HOGE’); </li></ul>
  4. 4. Good Flow Validation Add Redirect Session1 Session2 DB Lock Lock another page
  5. 5. How to lock. <ul><li>use Mysql::NameLocker. </li></ul>
  6. 6. Mysql::NameLocker <ul><li>use Mysql::NameLocker; </li></ul><ul><li>sub valid_add { </li></ul><ul><li># GET_LOCK() </li></ul><ul><ul><li>$self->{locker} = Mysql::Namelocker->new( </li></ul></ul><ul><ul><ul><li>$self->model->store->dbh, </li></ul></ul></ul><ul><ul><ul><li>$self->session->session_id, </li></ul></ul></ul><ul><ul><ul><li>$self->config->lock_timeout, </li></ul></ul></ul><ul><ul><li>); </li></ul></ul><ul><ul><li>unless ($self->{locker}) { </li></ul></ul><ul><ul><li>$self->validator->set_error(‘lock’ => ‘failed’); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><li>} </li></ul>
  7. 7. Mysql::NameLocker (2) <ul><li>sub post_dispatch_add { </li></ul><ul><li># snip ... </li></ul><ul><li>undef $self->{locker}; # RELEASE_LOCK() </li></ul><ul><li>} </li></ul>
  8. 8. SEE ALSO <ul><li>CVS Repository - markup - SourceForge: sledge/Sledge/lib/Sledge/Session/MySQL.pm </li></ul><ul><li>http://cvs.sourceforge.jp/cgi-bin/viewcvs.cgi/sledge/Sledge/lib/Sledge/Session/MySQL.pm?view=markup </li></ul>

×