Hello Monks,

I'm trying to do consistent writes to a NFS folder that can go offline for maybe 30 seconds while i'm writing in it. I tried different things and ended with the following code :

$| = 1 ; my $fh ; for my $master (1..100) { for my $fast (1..50000) { unless ( print $fh "PRINT OK $master $fast\n" ) { my $now = localtime ; print "Failed $it $master $fast at ", $now, " +\n" ; close $fh ; sleep 1 ; my $ok = 0 ; while ($ok == 0) { if (open $fh, ">>", "/mnt/fs_1/ttt.$it +.txt") { print $fh "PRINT OK $master $f +ast\n" ; $ok = 1 ; } else { my $now = localtime ; print "Failed delayed write fo +r $it $master $fast ", $now, "\n" ; sleep 1 ; } } } }}

I also tried without closing the filehandle, just repeating the if (print "...) until it's ok, but in both versions i still end up losing some data ! That is, it seems there's a delay between the moment the nfs folder becomes unavailable and the moment the OS (and my script) become aware of it.

Is there a specific way to handle writes to nfs folders ?

Thanks for your advice !


In reply to Delaying NFS writes by ZlR

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.