• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to handle this situation

 
Amit Kr Kumar
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers
How should we handle the following condition:
Suppose a client calls lock(5) and then he calls lock(-1) without unlocking the previous rec 5.
a. Should the lock manager wait for a call of unlock(-5)
b. should the lock managet smart enough to give whole db lock as it knows the rec 5 is locked by the same client (subject to condition that all the other records are free)
I know some people argue that lock(-1) is for shutdown so this will never happen but i still believe that db lock can also be taken by clients as the application grows

Amit
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In what world will a client have to lock all the records? I would not worry about it for this assignment.
Mark
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

a. Should the lock manager wait for a call of unlock(-5)

This is a typo, right? You meant to say "Should the lock manager wait for a call of unlock(5)"?
Eugene.
 
Amit Kr Kumar
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Eugene, you are right
I mean unlock(5)
Amit
 
Eduard Jodas
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In what world will a client have to lock all the records?

IT world. Imagine you must add a record to a db based on the values of the last record stored. Imagine there is a field which contains a date value, so that you can compute which is the last stored record. So, you read and lock this last record, compute new values and add a new record. Let's suppose there is another application that is constantly modifying the date field of stored records and adding new records. How do you prevent this second application from corrupting your data? The only way is blocking the database (the table, at least). This block must prevent record modification, deletion and addition.
Amit, I treat differently database locks from record locks. A client can get a database lock if all the locked records in the database are his. After that, to unlock all the records the client must unlock the database and still unlock the individual records previously locked.
After getting a database lock no other client can add, delete or modify records.
However, after seeing a lot of posts I don't think this is required in this assignment. I wish I had realized that before implementing it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic