• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What exactly constitutes "Booking Time"?

 
George Lawniczak
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the requirements:
"The aim is to ensure that if two customers attempt to book a seat on the same flight concurrently, then the number of available seats is definitely reduced by two, unless there was only one seat, in which case, one customer will be advised at booking time time that no more seats are available."
My confusion is what exactly constitutes "booking time." Is it when the user first hits the book button (i.e., before the book dialog appears), or is it after the user has specified the customer information (number of seats) in the dialog (just before the database actually gets updated)?
The question concerns when the lock should be applied. If you apply it earlier (pessimistic locking), the user could walk away from the dialog, thus keeping the record locked. If the lock is applied later, the number of seats may change, such that by the time the dialog window is filled out, the remaining seats are taken and the customer is SOL.
My thought is that FBN would lose a lot of business if an agent told a client seats were available, but upon actually updating the database found out they were gone. Maybe a solution would be that if there are a certain number of seats left, the system would automatically institute pessimistic locking. Of course this probably is beyond the scope of the requirements.
Just curious about which approach others are taking. I've programmed it both ways so it would be easy enough to change it.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Booking tim eis the actual time when you want ot go and modify the record. Not when your dialog pops up. And at booking time is when you will lock the record.
This of the travel websites now. If you find a flight and go to book it, you have the flight on your scren, but you haven't bought it yet, it should be fair game to someone else buying it before you if you wait too long.
Mark
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi George,
Mark is right for this assignment. If you were to implement lock on demand on the client then it effectively becomes a read lock. All this assignment requires is that no two clients can modify the same record at the same time and that a client cannot book a flight once all the seats have been booked. So it's easiest to handle locking on the server using a write lock only as the instructions indicate.
Hope this helps,
Michael Morris
 
George Lawniczak
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot guys. I think I've got that part squared away. Now it's on to figuring out the Lock(-1) part.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lock(-1) is pretty easy. Just imagine the call by the server is just like a client, it will try to lock a record, and if someone else has that record it waits till it is umlocked. So all yuo ahve to do is loop through the records and lock them.
Mark
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

So all yuo ahve to do is loop through the records and lock them.

... or set a flag and wait() until all records have been unlocked (as indicated by empty collection of locks).
Eugene.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... or set a flag and wait() until all records have been unlocked (as indicated by empty collection of locks).

What happens when all records are not all unlocked at the same time?
Especially if it's a busy program with lots of users.
My way kind of reminds me of the video game Frogger, you have to wait patiently to move to the next step, then wait to move again. Rather than wait till the road is completely clear and trying to run across in one move. Then you get run over.
Mark
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What happens when all records are not all unlocked at the same time?

It doesn't matter, because once the "database is locking" flag is set, no new locks are allowed. So both your and mine approaches will take exactly the same amount of time to lock the database. The difference is just in the concept: you wait() and lock every record, and I wait() and do not allow subsequent locks.
Eugene.
[ August 14, 2002: Message edited by: Eugene Kononov ]
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did it the same way Eugene did. Once the dblock request is set, no clients can lock any further records and once all pending locks are relinquished, the dblock is established. I must admit, though, that I did consider using Mark's method, it just seemed easier to use the other approach.
Michael Morris
 
Nate Johnson
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did it the same as Michael and Eugene too... I would have done it the other way, but my LockManager did not know how many records there were in the first place so I could not loop through all of them asking for locks on each row.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the classes has a recordcount which you could have used to know how many records to loop through.
But all ways work as long as the lock(-1) locks all the records.
Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic