[OpenAFS] file access
Paul Blackburn
mpb@est.ibm.com
Thu, 05 Dec 2002 13:10:34 +0000
Derrick J Brashear wrote:
>On 5 Dec 2002, amar deep kumar wrote:
>
>
>
>>Hi,
>> in AFS how file writes are synchronised, if suppose two
>>processes are writing the same file, how the file will be updated.
>>
>>
>
>last writer wins
>
>
Exactly. Just like with local files in a local filesystem.
>
>
>>or is there any method to lock a file while writing to it, but
>>again what would happen if that file is already cached on other
>>machines, does the file server breaks the callback of all those
>>machines.
>>
>>
>
>it does, but if the file is open already that won't help.
>
There are various tricks.
One is to rename the file before trying to update it
and then return it to its original name when done.
(similar example: SCCS or RCS file checkout).
This is not perfect since a race condition can occur
if two try this at exactly the same time.
The general problem of mutual exclusion to access resources
one process at a time occurs in many places including local filesystems.
Mutual exclusion is a much studied problem
and a Dutch computer scientist, Edsger Dijkstra
http://www.thocp.net/biographies/dijkstra_edsger.htm
proposed a clever solution using "semaphores"
to the famous "five philosphers around a dining table" problem.
A semaphore operation is an atomic "test and set".
(test if free and set flag "used" in a single operation.)
The bottom line is: you have to have an agreed convention
(or protocol) between the consumer processes trying to
access the resource.
This problem is not any different in /afs than it is in other places.
--
cheers
paul http://acm.org/~mpb