[REBOL] Re: Multiuser database
From: SunandaDH:aol at: 20-Mar-2006 6:19
> 1) Create a "lock" file when you access the database. The first thing
> you do is check for its existence, create it if not there, and
> delete it when you're done.
Though that gums things up if the task fails and does not delete the lock
file -- all future tasks are blocked waiting for the lock file to be deleted by a
One way around that is to write the lock file with an expiry time -- say 2
seconds in the future. Tasks can then overwrite the lock file if the timestamp
has expired. Of course:
* Still delete it at the end (otherwise you could only have 30 updates a
* Extend it by a second if you've taken over a second of elapse time
(otherwise other tasks may overlap yours if you take more than 2 seconds to complete.
Getting ownership of the lock file can be tricky if you are running Windows
as it does not, by default, always lock files -- so two or more tasks could
overwrite it; and then they all think they have the all clear to run. There are
ways to fix that -- let me know if you want to know them.
Basically, you either have a database or you need to build the equivalent
access controls for a multi-user environment. How clever your controls need to
be depends in part on how often you are happy to lose data. If once every
10,000 updates is fine, then you can deploy a simpler set of controls than if you
need to be safe for 1,000,000 on average.