• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Questions regarding Safe Server Shutdown

 
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all
I think I have completed the actual requirements part of the assignment but have a couple of questions regarding safe server shutdown
Safe server shutdown
I will try to explain what I understood are the things we need to do for safe server shutdown. Please comment on it.
1. While the server is running, if the CSR presses Ctrl-C or HaltServer button on the GUI, then the server should shutdown gracefully.
2. What I understood by the term "gracefully" is: (a) No new clients are allowed to get a reference to Adapter from ConnectionFactory. (b) Allow some time(Maybe, sleep for a couple of seconds to let the current threads complete their work) and then exit using System.exit(0).
3. This is achieved by Runtime.addShutdownHook()[i.e. do the sleep thing here and do not allow new clients]
4. I have gone through many of the past posts but could not understand the reason why they are locking the complete database. I mean if you're not giving access to any new clients then its OK right? What is the point of lockdown the complete database while you're however shutting down the JVM?
5. I also saw some of the posts discussing about lock(-1) call. What is it about? I am guessing it is regarding old assignment.
Once server starts shutting down I donot see anything else to do other than waiting for a second or a couple of seconds to complete the current operations. Please correct me if I'm wrong. Thanks.
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Satish,
You are soo far ahead of me. I'm still ramping up. Some things are clear and some are not. When my code is more complete, then I'll have a slew of questions. Hope you are still around to help straigten me out.


Safe server shutdown
I will try to explain what I understood are the things we need to do for safe server shutdown. Please comment on it.
1. While the server is running, if the CSR presses Ctrl-C or HaltServer button on the GUI, then the server should shutdown gracefully.
2. What I understood by the term "gracefully" is: (a) No new clients are allowed to get a reference to Adapter from ConnectionFactory. (b) Allow some time(Maybe, sleep for a couple of seconds to let the current threads complete their work) and then exit using System.exit(0).
3. This is achieved by Runtime.addShutdownHook()[i.e. do the sleep thing here and do not allow new clients]
4. I have gone through many of the past posts but could not understand the reason why they are locking the complete database. I mean if you're not giving access to any new clients then its OK right? What is the point of lockdown the complete database while you're however shutting down the JVM?
5. I also saw some of the posts discussing about lock(-1) call. What is it about? I am guessing it is regarding old assignment.


I agree with 1. and 2a.
My preference is different from 2b and 3 (see below). I just don't like idle timeouts hoping that the timing is right. Most of the time, the time out is wasteful as nothing is going on. When you do need it, how do you know that the 1 or 2 seconds is enough?
As for question 4, the reason some people are locking the complete database is to ensure no transaction is cut off in mid stream. No new requests can come in but the issue then is when are the threads that are already in going to be done? One thorough but slow approach is to lock every record. This is probably a fine solution for this assignment.
The answer to question 5 is yes, the lock(-1) is for an old assignment but the concept is relevant for server shutdown.
A Different Approach
I had my idea mostly worked out when I found this thread which is pretty close to what my plan is. See Robin's post. There's not a lot of details but you don't need all that much to make it work.
Lock Db
What I like about this approach is that we can make the shutdown event driven. Once we know all the threads are out we can shutdown. Most of the time this will be immediately. When it is not, we can still shut down as soon as the last record is unlocked.
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Don

Originally posted by Don Wood:
Hi Satish,
My preference is different from 2b and 3 (see below). I just don't like idle timeouts hoping that the timing is right. Most of the time, the time out is wasteful as nothing is going on. When you do need it, how do you know that the 1 or 2 seconds is enough?

Considering the worst possible time to complete a single operation, I guessed that it should not take more than a couple of seconds to perform a operation(reading/writing/deleting). I know this does'nt sound like a technically right approach, but...

As for question 4, the reason some people are locking the complete database is to ensure no transaction is cut off in mid stream. No new requests can come in but the issue then is when are the threads that are already in going to be done? One thorough but slow approach is to lock every record. This is probably a fine solution for this assignment.

I thought if NO new clients are coming, then obvioulsy no all new requests are stopped right? However we want to let all the correct working threads to complete their operations.
Oh, I get it. Say suppose if 3-4 threads are waiting on a record and if shutdown the server, we just want the currently operating thread on the record to complete and not any new threads to do any further operations. This might be the reason to lock the complete db and then shutdown the JVM.

The answer to question 5 is yes, the lock(-1) is for an old assignment but the concept is relevant for server shutdown.

Yeah, I too thought that its for the old assignment.

A Different Approach
I had my idea mostly worked out when I found this thread which is pretty close to what my plan is. See Robin's post. There's not a lot of details but you don't need all that much to make it work.
Lock Db

Don, thanks alot for pointing out to this thread. Its a very good approach. BTW, at first I implemented lockDB and unlockDB for reading and creating records besides the given locking. Later I thought locking/unlocking compelte DB is'nt required for reading/creating and took out the methods. Now, I think this is the time to revisit those two methods and refactor them accordingly.

What I like about this approach is that we can make the shutdown event driven. Once we know all the threads are out we can shutdown. Most of the time this will be immediately. When it is not, we can still shut down as soon as the last record is unlocked.
I still need to workout(basically think alot on this) on this and do accordingly. The thing is this fancy server shutdown and client crashes dealing though is not required, I think doing them is good not only for exam point of view, but personally also.

 
Don Wood
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I thought if NO new clients are coming, then obvioulsy no all new requests are stopped right? However we want to let all the correct working threads to complete their operations.
Oh, I get it. Say suppose if 3-4 threads are waiting on a record and if shutdown the server, we just want the currently operating thread on the record to complete and not any new threads to do any further operations. This might be the reason to lock the complete db and then shutdown the JVM.


Yes, that's the reason. That way all clients get responses to their requests. Some responses are completions and some are server shutting down. But none have the request lost because the server just went away.


I still need to workout(basically think alot on this) on this and do accordingly. The thing is this fancy server shutdown and client crashes dealing though is not required, I think doing them is good not only for exam point of view, but personally also.


Actually, locking the db for server shutdown is pretty simple as I see it. If you think you need to do something fancy, let's talk it through.
 
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I would recommend finding a design solution, if not already mentioned above,
which allows a client to finish a business level transaction. For instance, the
following, I believe, I would not find acceptable:
data.lock(client1, record100);
fields = data.read(client1, record100);
//Manipulate and calculate and write out first result.
data.update(client1, record100, fields);
//Manipulate and calculate and write out secondary result.
//But now the server rejects all subsequent processing.
//And, a partial result is present. This may be more likely
//to occur in a scenario where multiple rooms are being
//booked, and multiple locks are now held by one client.
So, I would be inclined to let everyone already holding
a record lock or locks, complete their business transaction.
Thanks,
Javini Javono
 
Don Wood
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Javini,
Your point is well taken. Perhaps it wasn't said very well above but the idea is to let any clients that have locks complete their requests. So a client that held a record lock would continue with that request and subsequent requests until it unlocked the record. No new locks would be accepted.
I haven't thought far enough ahead to decide whether or not I will allow a client that does not have a lock to complete requests that do not require one (such as a read). I think I would like to allow only clients with locks to continue but I'll have to decide that when I get to the implementation.
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Don & Javini

Originally posted by Don Wood:
Javini,
Your point is well taken. Perhaps it wasn't said very well above but the idea is to let any clients that have locks complete their requests.

That's exactly the idea Don.

So a client that held a record lock would continue with that request and subsequent requests until it unlocked the record. No new locks would be accepted.

Exactly Don.

I haven't thought far enough ahead to decide whether or not I will allow a client that does not have a lock to complete requests that do not require one (such as a read).

I want to allow read/create operations if there are any as they do not need any locking and if we stop in the middle, clients may get corrupted information or corrupted data will be written to the file.

I think I would like to allow only clients with locks to continue but I'll have to decide that when I get to the implementation.

 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To add, if 4 clients are waiting to book the same record and if one has already locked. Only this trasaction will be done. The rest of the clients are not even allowed to lock. Once the current thread does its book operation, server shuts down.
It can also be seen as, at shutdown, am trying to make total lockRecords size zero.
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did not find shutdown server as a requirement, perhaps I am missing something here?
 
Don Wood
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric,
I've been thinking about your question for a while:

I did not find shutdown server as a requirement, perhaps I am missing something here?


I agree that it is not listed as a requirement. But it seems to me that there is a locking issue that should not be ignored.
We lock records to ensure that the data remains consistent. Of course, you know this. But what if someone shuts down the server while one or more threads are in the middle of updating/creating records? If the server is not safely shutdown (that is, it terminates while locks are held) isn't there is a risk that the data becomes inconsistent because records are partially written?
It seems to me, that safe server shutdown is needed to preserve the ability of the locking mechanism to keep data consistent.
I wonder if not implementing a safe sever shutdown contributes to some of the 44/80 locking scores we have been seeing.
In short, I view safe server shutdown as a required piece of locking functionality even though it is not explicitly stated as such in the instructions.
 
Bring me the box labeled "thinking cap" ... and then read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic