problem with sysopen() on nfs

Discussion in 'Perl Misc' started by Michele Dondi, Sep 18, 2004.

  1. I want to implement a locking system for a script that shouldn't allow
    more than one instance on each machine of a cluster by means of a
    lockfile. The relevant code snippet is:

    my $lockfile = "$lockdir/$pfx-$host";
    sysopen my $lock, $lockfile, O_CREAT | O_EXCL
    or die "$0 already running on $host";

    Now I'm aware that file operations on nfs are not atomic, but this is
    not a big issue since *in this case* the probability of collisions if
    ridiculously small.

    However it seems that I have another problem, and a more serious one.
    Namely the lockfile is actually created in the specified directory,
    but it is named .nfs* (I mean, it matches that wildcard...)

    Am I missing something obvious? Any workaround/alternative strategy?


    TIA
    Michele
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
     
    Michele Dondi, Sep 18, 2004
    #1
    1. Advertising

  2. Michele Dondi

    Joe Smith Guest

    Michele Dondi wrote:
    > However it seems that I have another problem, and a more serious one.
    > Namely the lockfile is actually created in the specified directory,
    > but it is named .nfs* (I mean, it matches that wildcard...)
    >
    > Am I missing something obvious? Any workaround/alternative strategy?


    The workaround is to not delete the file while it is open for reading.

    When a local file is openned for reading, and it then deleted (unlinked),
    the file is still there even though it does not have a directory entry.
    So the process that openned the file can continue reading this now
    nameless file.

    When a file on an NFS mount is openned for reading, and then is deleted
    on the NFS client, the client tells the NFS server to rename the file
    to be .nfs{something}, so it can still be read on the client.

    To avoid the symptoms you're seeing, just be sure to close all open
    file handles that reference the lockfile before deleting the lockfile.
    -Joe
     
    Joe Smith, Sep 19, 2004
    #2
    1. Advertising

  3. On Sun, 19 Sep 2004 03:57:19 GMT, Joe Smith <>
    wrote:

    >> Am I missing something obvious? Any workaround/alternative strategy?

    >
    >The workaround is to not delete the file while it is open for reading.


    Huh?!? I don't *think* I'm deleting it anywhere. Granted, I've set a
    pair of signal handlers and an END block in which I do delete it
    (before closing it). But they shouldn't have been called at all...

    [snip explanation]

    >To avoid the symptoms you're seeing, just be sure to close all open
    >file handles that reference the lockfile before deleting the lockfile.


    D'Oh! Now that I think of it I make my program C<fork and exit> to go
    in bg, so the END block *is* executed. I'll have to change the logic
    of the script.


    TY,
    Michele
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
     
    Michele Dondi, Sep 19, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    643
  2. Hon Guin Lee - Web Producer - SMI Marketing

    sysopen problem

    Hon Guin Lee - Web Producer - SMI Marketing, Oct 7, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    119
  3. Michele Dondi

    Q re sysopen() and more...

    Michele Dondi, Oct 13, 2004, in forum: Perl Misc
    Replies:
    6
    Views:
    123
    Michele Dondi
    Oct 15, 2004
  4. Tomasz Chmielewski

    sysopen - die only if EBUSY?

    Tomasz Chmielewski, Oct 2, 2008, in forum: Perl Misc
    Replies:
    3
    Views:
    132
    Ben Morrow
    Oct 2, 2008
  5. Marc Girod

    sysopen failures

    Marc Girod, Aug 6, 2010, in forum: Perl Misc
    Replies:
    19
    Views:
    258
    Peter J. Holzer
    Aug 13, 2010
Loading...

Share This Page