Avoiding File Update Anomalies (Collisions) on a Server

Gregory Lypny gregory.lypny at videotron.ca
Mon Aug 22 11:05:58 EDT 2011

Hello everyone,

I would appreciate your thoughts on how to avoid collisions on a server on those presumably rare occasions when two or more visitors attempt to write to a file at exactly the same time.  In my case, it’s students writing via FTP to a text log file, but the same situation can occur if visitors to a web site, for example, submitting an entry to a guest book, do it at the same time.  I don’t know what the consequences of this are.

My crude and imperfect attempt to minimize this possibility is to have a Busy file that acts as a flag when the log file is being written to.  It contains just one line of data:

	False, the seconds

If the first item is False, it means that the log file is not currently being written to.  A user about to write to the file invokes a handler that changes this first item to True, and inserts a timestamp in the form of the seconds.  When they are finished writing to the file, the same handler sets the Busy file to False and inserts a new timestamp.  The purpose of the timestamp is to cover for the possibility of the write process or the handler being aborted, therefore failing to set the Busy file back to False.  If the timestamp is more than, say, four minutes old, the True flag can be overridden.  This method is obviously imperfect because it is possible that two people might be writing to the Busy file at the same time!  I’m curious to know of other handler-based approaches that do not involve setting up separate databases.



More information about the Use-livecode mailing list