ZlR has asked for the wisdom of the Perl Monks concerning the following question:
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 !
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Delaying NFS writes
by Generoso (Prior) on Dec 10, 2010 at 15:02 UTC | |
by ZlR (Chaplain) on Dec 10, 2010 at 15:57 UTC | |
Re: Delaying NFS writes
by JavaFan (Canon) on Dec 10, 2010 at 16:03 UTC | |
by ZlR (Chaplain) on Dec 10, 2010 at 16:26 UTC | |
Re: Delaying NFS writes
by afoken (Chancellor) on Dec 11, 2010 at 12:22 UTC | |
by ZlR (Chaplain) on Dec 11, 2010 at 16:22 UTC |