• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lock the database

 
Raju, Gentle
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

One of the requirement is to lock the entire database if the argument in lock method is -1. My understandin of this is :
If there are already records locked by some other threads we should let them continue to procede with bookFlight execution and unlocking even if the current thread locks the Database. Because when the time other threds entered into bookFlight method there was no database lock. So it is better for these threads to continue booking even after database locked by current thread. However once the database is locked, any subsequent threads will have to wait for the database lock to be removed. They can continue only after the database lock is removed. Is my understanding correct here ?

The second question is : Who will unlock the database once it is locked. I do not see it as a requirement. Do we need to give some kind of special permissions to special users who can lock and unlock the database ?
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Raju, Gentle:
If there are already records locked by some other threads we should let them continue to procede with bookFlight execution and unlocking even if the current thread locks the Database. Because when the time other threds entered into bookFlight method there was no database lock. So it is better for these threads to continue booking even after database locked by current thread. However once the database is locked, any subsequent threads will have to wait for the database lock to be removed. They can continue only after the database lock is removed. Is my understanding correct here ?

Essentially, yes. Consider whether new record locks should be granted while a client is waiting for a database lock to be granted. The answer is not as obvious as it might seem.
The second question is : Who will unlock the database once it is locked. I do not see it as a requirement. Do we need to give some kind of special permissions to special users who can lock and unlock the database ?

unlock(-1). There is no authorisation requirement.
- Peter
 
Raju, Gentle
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter Again thanks for reply.
Is it not required to implement code for unlock(-1) ?
 
Raju, Gentle
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter thanks !
So it is not a must to implement unlock(-1) ?
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Raju, Gentle:
Is it not required to implement code for unlock(-1) ?
Oh yes it is. There is no requirement for the "special permissions" you mentioned though.
- Peter
 
mitchner green
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My lock method doesn't work that way. I don't grant a global lock until all the other locks have expired, or been unlocked. The way you described it, records 1, 2 and -1 could all have locks at the same time. I think that is bad. Why not wait for locks 1 and 2 to be unlocked before granting the -1 lock?
 
Raju, Gentle
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi mitchner,
Yes I agree with you mitchner. It it better to wait for all other threads to call unlock and then grant the whole database
lock. However there are some problems with this approach. The database lock will not be applied if there are clients continuously calling bookflight. It will have to wait for no one to be present. This may take a longer time for database lock to be applied. But on the other hand this may be ok because the whole database lock will be applied only for maint.
 
mitchner green
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, the way I have it coded as soon as the global lock is *requested*, I quit granting any more locks. When the existing locks go away, I grant the global lock. This way I'll never wait and wait for the global lock.
The way I figured it, if a global lock is requested, that gets priority over clients requesting "normal" locks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic