开发者

Question for Conflict in insertion of data in DB by user and admin, see below for description

I have a case that what will happen when at one end Admin is editing the Details of user "A" in a table "users" and at the same time user "A" itself edits its details in table users. Whose effect will reflected.. And what can be done to make开发者_StackOverflow社区 it specific to some one or to give the priority?

Thanks and Regards...


As Michael J.V. says, the last one wins - unless you have a locking mechanism, or build application logic to deal with this case.

Locking mechanisms tend to dramatically reduce the performance of your database. http://dev.mysql.com/doc/refman/5.5/en/internal-locking.html gives an overview of the options in MySQL. However, the scenario you describe - Admin accesses record, has a lock on that record until they modify the record - will cause all kinds of performance issues.

The alternative is to check for a "dirty" record prior to writing the record back. Pseudocode:

User finds record
Application stores (hash of) record in memory
User modifies copy of record
User instructs application to write record to database
Application retrieves current database state, compares to original
If identical
     write change to database
If not identical 
     notify user

In this model, the admin's change would trigger the "notify user" flow; your application may decide to stop the write, or force the user to refresh the record from the database prior to modifying it and trying again.

More code, but far less likely to cause performance/scalability issues.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜