Topic: 怎么判断当前数据是否过期?(b/s环境)

  Print this page

1.怎么判断当前数据是否过期?(b/s环境) Copy to clipboard
Posted by: jigsaw
Posted on: 2004-11-18 13:21

story:

1. user A get row1 from table1, edting;
2. user B get row1 from table1, edting;
3. user B submit row1, database update row1 of table1;
4. user A submit row1, ------- how can we get to know the data
that user A holding has expired?

--------------------
solution: add 2 columns, LAST_UPDATED_BY, LAST_UPDATED_AT,
to table1.
each time we are going to update table1, check LAST_UPDATED_BY, LAST_UPDATED_AT, if identical, update it, otherwise, throw out an exception
to tell user she/he must retrieve row1 again.

---------------------------
anyother solutions?

THX IN ADVANCE

2.Re:怎么判断当前数据是否过期?(b/s环境) [Re: jigsaw] Copy to clipboard
Posted by: xidaboy
Posted on: 2004-11-18 15:04

应该是谁先提交谁成功,后面的会自动放弃,注意把数据库事务级别设置好

3.Re:怎么判断当前数据是否过期?(b/s环境) [Re: jigsaw] Copy to clipboard
Posted by: jigsaw
Posted on: 2004-11-18 15:33

不 xidaboy 误会了
这个跟数据库的lock无关
这个并发的问题并不是说两个用户同时提交的问题
而是先后提交的情况下 怎么让第一个用户知道他的数据其实已经过期了(也就是被别人更新过了)
也就是fast fail/optimise locking这类的问题

4.Re:怎么判断当前数据是否过期?(b/s环境) [Re: jigsaw] Copy to clipboard
Posted by: floater
Posted on: 2004-11-18 23:46

no way unless user A's page has an auto refresh. Web is using pull mode, but you need a push mode.

5.Re:怎么判断当前数据是否过期?(b/s环境) [Re: floater] Copy to clipboard
Posted by: jigsaw
Posted on: 2004-11-19 09:15

floater wrote:
no way unless user A's page has an auto refresh. Web is using pull mode, but you need a push mode.


我并不要求A在他的数据过期后,立刻得到通知。
只要A在试图update他手上的数据(row1)的时候,系统
能够检测到row1已经被别的用户(B)更新过了。
除了用加入LAST_UPDATED_AT这种字段的方法,还有什么其他方法吗?

比如,能不能加入一个LOCK_IND,当他为'Y'的时候,说明这行数据
只能VIEW不能UPDATE,为'N'则可以UPDATE。当用户试图修改数据的时候,
先把这个设置为'Y'。
但是这样是不是太pessimistic了?而且会不会有concurrency的问题?

谢谢~

6.Re:怎么判断当前数据是否过期?(b/s环境) [Re: jigsaw] Copy to clipboard
Posted by: haibo
Posted on: 2004-11-19 10:50

用户要求编辑时
retrive出的每行作为map中的一个,上锁,或抢占试检测

7.Re:怎么判断当前数据是否过期?(b/s环境) [Re: jigsaw] Copy to clipboard
Posted by: floater
Posted on: 2004-11-19 10:51

you may have a timestamp field in the table and have a timestamp on the page,
when read from table to the page, set the page time to the table time.
when A or B update the row, compare the two timestamps, if the page is earlier, then someone else updated it, if the same, you can update the row and set the new time.

8.Re:怎么判断当前数据是否过期?(b/s环境) [Re: floater] Copy to clipboard
Posted by: jigsaw
Posted on: 2004-11-19 11:29

floater wrote:
you may have a timestamp field in the table and have a timestamp on the page,
when read from table to the page, set the page time to the table time.
when A or B update the row, compare the two timestamps, if the page is earlier, then someone else updated it, if the same, you can update the row and set the new time.


这正是我现在的做法 就是想印证下这是不是通用的解决方法
谢谢floater

9.Re:怎么判断当前数据是否过期?(b/s环境) [Re: jigsaw] Copy to clipboard
Posted by: floater
Posted on: 2004-11-19 22:39

I am not sure about 通用的解决方法, Tounge.

I did see a lot of dbs have timestamps everywhere with some rather odd/strange usages. All I can tell you is that even if this is bad, this is definitely not the worst Tounge.

10.Re:怎么判断当前数据是否过期?(b/s环境) [Re: jigsaw] Copy to clipboard
Posted by: WeiterWay
Posted on: 2004-11-24 10:20

可以参考Hibernate的Version Control的机制,在表中加入一个Version字段,这种做法也是optimistic的,跟timestamp具有同等效果。

11.Re:怎么判断当前数据是否过期?(b/s环境) [Re: jigsaw] Copy to clipboard
Posted by: yqyan
Posted on: 2004-11-24 12:44

我的一般做法是在数据库中增加时间戳字段做判断。


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923