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."