Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Concurrency control in web applications

by pg (Canon)
on Oct 24, 2003 at 18:47 UTC ( [id://301924]=note: print w/replies, xml ) Need Help??


in reply to Concurrency control in web applications

Another simple but useful way is to have an artificial column in the table, which you have locking concern. You may call it something like “mod_count” or whatever makes sense to you. At the beginning of a transaction, you read the mod_count, and remember its value. At the end of the transaction, when it comes to the point you update the database, you lock, and then check the mod_count, see whether it is still the number you got. If the mod_count is different now, fail the transaction (assume you don’t want accidental overwrite), otherwise, do the update, also increase mod_count by 1 in the same update statement.

By doing this, you don't need to lock the table thru out the transaction, but only briefly at the end.

  • Comment on Re: Concurrency control in web applications

Replies are listed 'Best First'.
Re: Re: Concurrency control in web applications
by simonm (Vicar) on Oct 24, 2003 at 19:33 UTC
    Another simple but useful way is to have an artificial column in the table ... call it something like “mod_count”

    I think that's what the OP meant by "Add a version counter to each record," also known as "optomistic locking."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://301924]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-23 15:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found