session - How to use exclusive locks in MySQL? -


i'm trying implement own version of session handler using mysql in php. version differs existing ones (like zend's) in mine namespaced , each namespace stored , locked separately. here's scenario should implemented in code:

  1. acquire exclusive lock sid+ns
  2. read sid+ns's data
  3. ... request takes course ...
  4. write sid+ns's data db
  5. release lock

sid: session id - ns: namespace

now question arises is:

how use exclusive locks in mysql?

there number of issues 1 needs keep in mind before answering question:

  1. there arbitrary number of namespaces in each session.
  2. one single request might need hold more 1 ex-locks (one request might need work on more 1 namespace @ time).
  3. locks need implemented using mysql's internal mechanism. implementing own application-level ex-locks pretty simple. have implement queues , semaphores mimic same behavior mysql giving makes hard. i'm saying want code work on of machines without going through heavy changes , i'm not willing implement polling system waste of system's resources , time. if implemented using mysql locks, when conflict happens code freeze without wasting cpu time or resources.
  4. keep in mind not record exists sid+ns. there first timer requests have insert record sid+ns before can lock it.

important: question not how use mysql locks in general. i've read mysql documents on how so. question comes specific scenario eyes makes impossible implement. that's why i've asked here, make sure if i'm missing or not.

ps. an open source project.

just know, managed implement in mentioned project. if anyone's interested he/she can find there.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -