Rami
> This seems to be a very interesting idea... But I want to clarify, this
> means that one instance of the component will execute this select
> statement and take the lock. Then the other instance may execute the
> same statement again but get a failure because the rows are already
> locked. So the second instance will be blocked from handling
> transactions. Is this correct?
It does not block readers , it does block writers.
> In my case I want each instance to select 100 rows for example and
> process them completely before releasing them. But at the same time, I
> want the other instance of the component to lock another 100 rows and
> work on them exclusively.
Read about setting transaction isolation level in the BOL
> Thanks again,
>
[quoted text clipped - 69 lines]
>> >> > Thanks a lot for the help,
>> >> > Rami AlHasan
Rami - 17 Jan 2007 04:06 GMT
One last question:
I updated your sample query in the following form:
DECLARE @ord INT
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
BEGIN TRAN
SELECT @ord=MAX(ORDER_ID) FROM Order WITH (UPDLOCK, READPAST)
UPDATE Order SET ORDER_STATUS= something WHERE (ORDER_ID = @ord)
COMMIT TRAN
The basic change here is that I removed the HOLDLOCK and put the
READPAST hint instead. I think the READPAST hint, will help in
filtering out those locked transactions. so each instance will see
unlocked transactiosns. But I removed HOLDLOCK because there was an
error generated if I included it with READPAST.
For me this seems to be working, is there any problem with this or any
hidden implications?
Thanks,
Rami
> Rami
> > This seems to be a very interesting idea... But I want to clarify, this
[quoted text clipped - 86 lines]
> >> >> > Thanks a lot for the help,
> >> >> > Rami AlHasan
Uri Dimant - 17 Jan 2007 05:00 GMT
Rami
Why do you need READPAST hint? In very busy enviroment you can get DEADLOCK.
BOL says
READPAST
Skip locked rows. This option causes a transaction to skip rows locked by
other transactions that would ordinarily appear in the result set, rather
than block the transaction waiting for the other transactions to release
their locks on these rows. The READPAST lock hint applies only to
transactions operating at READ COMMITTED isolation and will read only past
row-level locks. Applies only to the SELECT statement.
> One last question:
>
[quoted text clipped - 119 lines]
>> >> >> > Thanks a lot for the help,
>> >> >> > Rami AlHasan
Rami - 17 Jan 2007 06:48 GMT
I need it because I need each instance of my component to handle
different set of transactions, So if the first instance selected 50
transactions to handle, then it will lock them.using the SELECT
WITH(UPDLOCK, READPAST). But the second instance should not get the
same 50, so I used the READPAST to filter out those who already been
locked. Does this make since?
But I didn't understand why deadlocks may happen?
Regards,
Rami
> Rami
> Why do you need READPAST hint? In very busy enviroment you can get DEADLOCK.
[quoted text clipped - 130 lines]
> >> >> >> > Thanks a lot for the help,
> >> >> >> > Rami AlHasan
Uri Dimant - 17 Jan 2007 10:02 GMT
> locked. Does this make since?
If it depends on your business requieremnts, it's OK
> But I didn't understand why deadlocks may happen?
Open more than three connection and run this script , well , in than
case you are going to get Primary Key Violation
--create table people (id int not null primary key, name char(1))
declare @id int
set @id=100
begin tran
if not exists (select * from people WITH ( updlock,readpast ) where id=@id )
begin
waitfor delay '00:00:30'
insert into people (id, name) values (@id ,'h')
end
commit tran
>I need it because I need each instance of my component to handle
> different set of transactions, So if the first instance selected 50
[quoted text clipped - 160 lines]
>> >> >> >> > Thanks a lot for the help,
>> >> >> >> > Rami AlHasan