• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

database unlock()

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,
Iam doing the FBN assignment. have few questions about the database unlock.
1. The requirement doesn't talk about *unlocking* the entire database. so what do we do after locking the entire database successfully ?
should we just print a log and return ?
A client may lock the database for the purpose of doing changes to the database and may want to release the lock right after it without restarting the server. In this scenario don't we need the database unlocking implementation ?
if the purpose of locking the database is only for shutting down the server, then I agree there's no point in having database unlock.
2. My implementation of database locking waits for all the record level locks to expire and rejects new lock requests by throwing an exception.
please let me know your comments.
-venky
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Venkatesh,
1) I have implemented unlock(-1) just like regular record lock. One of possible uses for it is shuting down, but there might be others, like put the database in maintenance mode, do some work and release it to the clients.
2) In my implementation, lock(-1) has priority over regular record locks. lock(-1) waits for all record locks to be released and, during this time, blocks new lock requests instead of throwing exceptions.
But I havent submitted my assignment yet...
Marcos
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marcos, my implementation of lock(-1) is just built on top of lock(!-1), meaning it sequentially locks each record starting from the beginning. If all clients performing a full database lock start from the first record, then there is no danger of deadlock, as only the client which obtains the first record lock will suceed until it has released all the locks.


In my implementation, lock(-1) has priority over regular record locks. lock(-1) waits for all record locks to be released and, during this time, blocks new lock requests instead of throwing exceptions.


Certainly the requirements says that methods to lock an already locked record should block and not throw an exception.
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Venkatesh

The requirement doesn't talk about *unlocking* the entire database. so what do we do after locking the entire database successfully ?
should we just print a log and return ?


All you need some way of indicating that the entire database is now locked. You could do it like Marcos and grant a lock on record number -1 or you could do it like Patrick and lock each individual record. I don't see any problems with either option - they will both eventually work.
Once you have done that, it is up to the client who locked the entire database to decide what to do next.

A client may lock the database for the purpose of doing changes to the database and may want to release the lock right after it without restarting the server. In this scenario don't we need the database unlocking implementation ?
if the purpose of locking the database is only for shutting down the server, then I agree there's no point in having database unlock.


We do not know what purpose the architect planned for locking the entire database. I chose to allow the entire database to be unlocked again just in case the architecht has some other use aside from shutting down the server.

My implementation of database locking waits for all the record level locks to expire and rejects new lock requests by throwing an exception.


I also waited for existing locks to be released before granting the database lock.
Like Marcos, I gave database locks priority over record locks.
But I did not throw an exception for new attempts to lock a record - they just blocked. Again, not knowing why the database was locked, I did not know if it would eventually be released in which case the individual record locks could be aquired.
Regards, Andrew
 
Venkatesh Krishnappa
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks so much for your answers.
-venky
 
reply
    Bookmark Topic Watch Topic
  • New Topic