Hi,
My directions do not require me to lock down the complete database in response
to the client sending in a -1 argument to the lock() method. However, my server
needs to shut down elegantly without damaging the file or losing information.
When my server is told to start shutting down, when a client then calls the lock
method, the server raises an exception: "Server shutting down, no lock requests
are being accepted at this time."
Then, my original idea was simply to monitor the number of threads attempting
to complete from the LockManager. However, I noticed that the number of threads
in the LockManager can be zero, and the server still isn't ready to shut
down!
So, what I will do is the following to safely shut down the server:
1. When it is time to shut down, the server will no longer accept lock
requests, and raise an exception as discussed above.
2. Furthermore, the server will monitor disk writes; so, for instance, if
no create, delete, or update method has been called in the last two minutes,
the server will conclude that there are no outstanding writes.
When both conditions above are true:
1. No threads in the lock manager,
2. No disk writes in the last two minutes,
only then will the server assume that it is safe to shut down.
Here are my
test runs. I'm again using my version of George's Super Software
Exerciser to drive the tests, but in this particular run, updates, creates,
and deletes are all occuring. Note how the number of waiting threads drops
to zero for a quite a few minutes in the middle of the run! Only to pick up
again later. I suspect that this behavior is related to the Mac OS X operating
system.
Aside: in this test run, I've doubled the usual size of the database file to
contain 62 records. Also, there were 620 instantiations of the tester class
wherein each instantiation represents one Data instance (i.e., it contains one
Data instance).
Thanks,
Javini Javono