[comp.unix.wizards] Need help with lockf

bks@alfa.berkeley.edu (Brad Sherman) (03/21/91)

[If this is the wrong group, I apologize and would appreciate a
pointer to the right one.]

On both a Sun3 (3.5) network and a SparcStation (4.1) network
we are experiencing file synchronization difficulties.  Two
processes on the same cpu work fine but separate clients, or
client and server seem to fail to work to spec.

    * A Process blocks waiting to aquire file1 via an exclusive lock (lockf()).
    * After gaining the lock, a record in file2 is read and written.
    * An fsync() is issued on file2.
    * The lock is then released on file1.


The problem:
   When running this process on two separate cpu's it seems that a read by
   one client occasionally does not reflect the last write by the other
   process, despite the fsync().

The locking/unlocking of file1 (and blocking caused by it) works fine.
Adding an O_SYNC (on sparc's) to the open() calls does not help.
No other processes are touching file1 or file2.
This is with the standard SUN distributed C compilers and libraries.

Are we doing something wrong here?
-------------------------------
	Brad Sherman (bks@alfa.berkeley.edu)

scott@convergent.com (Scott Lurndal) (03/22/91)

In article <1991Mar20.205800.14651@agate.berkeley.edu>, bks@alfa.berkeley.edu (Brad Sherman)
writes:
|> [If this is the wrong group, I apologize and would appreciate a
|> pointer to the right one.]
|> 

  [ explanation of problem wrt sync over NFS ]

|> The locking/unlocking of file1 (and blocking caused by it) works fine.
|> Adding an O_SYNC (on sparc's) to the open() calls does not help.
|> No other processes are touching file1 or file2.
|> This is with the standard SUN distributed C compilers and libraries.
|> 
|> Are we doing something wrong here?
Yes, you are using NFS.   Data on the client is not guaranteed to be 
fresh.  (i.e. you may get stale data)
|> -------------------------------
|> 	Brad Sherman (bks@alfa.berkeley.edu)
scott

martin@adpplz.UUCP (Martin Golding) (03/23/91)

In <1991Mar20.205800.14651@agate.berkeley.edu> bks@alfa.berkeley.edu (Brad Sherman) writes:

>On both a Sun3 (3.5) network and a SparcStation (4.1) network
>we are experiencing file synchronization difficulties.  Two
>processes on the same cpu work fine but separate clients, or
>client and server seem to fail to work to spec.

None of the unix vendors we have talked to (which is many, but not all)
were willing to guarantee buffer cache coherency across the network.
You'll have to change one or both of the routines to talk to a remote
server (ie, on the machine with the data).

If you get this working, or hear any other good stuff, or if somebody
out there wants to flame me (HA! We've been running a distributed database
over NFS for years...) it could save me two months of work on a project
I'm about to be forced to do.


Martin Golding    | sync, sync, sync, sank ... sunk:
Dod #0236         |  He who steals my code steals trash.
Blechtrottel CPU with many megs...
{mcspdx,pdxgate}!adpplz!martin or martin@adpplz.uucp