Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!decwrl!pa.dec.com!shlump.nac.dec.com!decvax.DEC.COM!evans From: evans@decvax.DEC.COM (Marc Evans) Newsgroups: comp.lang.perl Subject: Re: locking dbm files Keywords: dbmopen, dbmclose, flock Message-ID: <21131@shlump.nac.dec.com> Date: 15 Mar 91 12:50:43 GMT References: <21090@shlump.nac.dec.com> <1991Mar14.205242.23220@convex.com> <125585@uunet.UU.NET> Sender: news@shlump.nac.dec.com Reply-To: evans@decvax.DEC.COM Organization: Synergytics Lines: 42 In article <125585@uunet.UU.NET>, rbj@uunet.UU.NET (Root Boy Jim) writes: |> In article <1991Mar14.205242.23220@convex.com> tchrist@convex.COM (Tom Christiansen) writes: |> ?From the keyboard of evans@decvax.DEC.COM: |> ?This is certainly true. dbm doesn't do locking. To do record locking |> ?would be hard. You could easily enough protect it with file |> ?locking though, but you should do this in your own code. |> |> Record locking might well be impossible, dunno. |> |> File locking is easy, unless, of course you are using NFS. |> |> Another thing to do is run a database demon and ask it to do things for you. Let's assume for the moment that I'm not using NFS (even though I am in reality, and to make things even worse, locking is done because many machines want write access to this dbm database). In perl, dbmopen doesn't use a FILEHANDLE, and flock requires a FILEHANDLE. We therefore end up with something like the following: $dbname = "foo"; open(LOCKDB,"$dbname.pag"); flock(LOCKDB,2); dbmopen(%foo,$dbname,0666); [...] dbmclose(%foo); flock(LOCKDB,8); It really seems ugly to me that the script needs to understand dbm naming conventions to perform the locking. Also, think about the exception handling that really should be added to the above for the cases of open, flock and dbm* functions failing. Not very pretty. However, it would appear that short of creating a network dbm data server, this technique is probably my best option. Any other suggestions? - Marc -- =========================================================================== Marc Evans - WB1GRH - evans@decvax.DEC.COM | Synergytics (603)635-8876 Unix and X Software Consultant | 21 Hinds Ln, Pelham, NH 03076 ===========================================================================