db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Øystein Grøvlen <Oystein.Grov...@Sun.COM>
Subject Re: DERBY-800, lock scheduling issue?
Date Sat, 11 Feb 2006 17:22:17 GMT
Bryan Pendleton wrote:
>> When a thread tries to create a table, it will first get a shared lock 
>> on the dictionary (DataDictionaryImpl.startReading).  This is released 
>> before it tries to lock the dictionary exclusively.  The way 
>> DataDictionaryImpl.startwriting works is that it first checks whether 
>> someone is holding a lock on the dictionary. If so, it will sleep for 
>> a while a then try again.  This goes on for a while until it gets 
>> impatient and actually requests an exclusive lock and enters the lock 
>> queue.  In the mean time, a lot more threads have acquired a shared 
>> lock and the updating thread will have to wait for all of them to 
>> release it. 
> 
> 
> This sounds like there is a lock scheduling fairness issue.
> 
> Your description makes it sounds like this:
>  - One or more transactions get shared locks on a resource
>  - A transaction requests an exclusive lock on a resource, and blocks
>  - Additional transactions arrive, requesting shared locks, and their
>    locks are granted.
> 
> It is possible to implement a lock scheduling policy such that those
> later locks, even though they are compatible with all currently granted
> locks, are not immediately granted, but instead are placed onto the
> resource queue behind the pending exclusive request.

The locking system behave as you describe.  However, in the particular 
case with the dictionary lock, the writer does not request the lock if 
it is already granted to some other transaction.  Instead, it sleeps, 
checks again, sleeps and so on for a while before it actually request 
the lock.  It seems to me that someone must have had a good reason in 
order to add this complexity to the code.

> 
> Perhaps we should consider whether there is an opportunity to enhance
> the locking policies to be more fair to writers?

We could look into this, but I am not sure fair scheduling of DDL 
operations is what we should spend our time on.

--
Øystein


Mime
View raw message