Writing to a file when disk is full? 
Author Message
 Writing to a file when disk is full?

% perl -v
version 5.004_04 built for sun4-solaris

I have a situation that proceeds something like this:

    ## Open statsfile, lock it, and gather results
    sysopen(FH, $Nsrc, O_RDWR|O_CREAT)
        or &Error( "Cannot open $Nsrc for read/write: $!\n" );
    flock(FH,LOCK_EX)
        or &Error( "Cannot read/write lock num file: $!\n" );
    $results = <FH> || 0;
    seek(FH,0,0)
        or &Error( "Cannot rewind num file: $!\n" );
    truncate(FH,0)
        or &Error( "Cannot truncate num file: $!\n" );

    ## $results is in a format like this: 'A,1,B,9,C,3[\n]?'
    chomp $results;             # just in case
    %Results = split /,/,$results;

### do some stuff with %Results, like incrementing some values

    print FH (join ',', %Results );
    close FH;

We recently had a situation where the disk it's
writing to ran out of space.  I'd like to be able
to check for available diskspace before doing the
read/write, and if it is not available do the read
and write on a different partition (like /tmp) as
a temporary measure to prevent data loss.

I'd also like to be able to do this without doing
a system call to 'df -k' or somesuch.  Is there a
module available for checking diskspace in an
efficient manner (this program gets used a LOT,
potentially several times a second).

I'd appreciate having any responses cc:'d to my

Thank you.
--e--



Fri, 08 Mar 2002 03:00:00 GMT  
 Writing to a file when disk is full?

  EQB> I'd also like to be able to do this without doing
  EQB> a system call to 'df -k' or somesuch.  Is there a
  EQB> module available for checking diskspace in an
  EQB> efficient manner (this program gets used a LOT,
  EQB> potentially several times a second).

Filesys::DiskSpace

it does syscalls and not process forking according to its docs.

i found by searching for 'disk space' at

http://theoryx5.uwinnipeg.ca/mod_perl/pause?request=search

uri

--
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering

Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.



Fri, 08 Mar 2002 03:00:00 GMT  
 Writing to a file when disk is full?


Quote:

>  EQB> I'd also like to be able to do this without doing
>  EQB> a system call to 'df -k' or somesuch.  Is there a
>  EQB> module available for checking diskspace in an
>  EQB> efficient manner (this program gets used a LOT,
>  EQB> potentially several times a second).

>Filesys::DiskSpace

>it does syscalls and not process forking according to its docs.

>i found by searching for 'disk space' at

>http://theoryx5.uwinnipeg.ca/mod_perl/pause?request=search

Odd that that module doesn't show up on search.cpan.org for the same
search.  It does mention Filesys::Df, though, which purports to use
Filesys::Statvfs, and so presumably doesn't fork.

        Brand
--
Grimace is purple.  Grimace looks dumb.  Grimace has a moronic voice.
Yet Barney gets all the glory.  The world is an unfair place, my friend.
  -- Derek Littlefield



Fri, 08 Mar 2002 03:00:00 GMT  
 Writing to a file when disk is full?



  >> http://theoryx5.uwinnipeg.ca/mod_perl/pause?request=search

  BH> Odd that that module doesn't show up on search.cpan.org for the same
  BH> search.  It does mention Filesys::Df, though, which purports to use
  BH> Filesys::Statvfs, and so presumably doesn't fork.

search.cpan.org is not stable from what i know. i have been using the
other site for a while with good results. in fact graham barr liked what
he saw on this site and want s.c.o to be as good if not better.

when that is ready and mirrored on faster machines i may switch. for now
i will stick with the uwinnepeg site.

uri

--
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering

Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.



Fri, 08 Mar 2002 03:00:00 GMT  
 Writing to a file when disk is full?

# search.cpan.org is not stable from what i know. i have been using the

It is extremely stable from what I know.

--

%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])



Sat, 09 Mar 2002 03:00:00 GMT  
 Writing to a file when disk is full?

Quote:

> I have a situation that proceeds something like this:

>     ## Open statsfile, lock it, and gather results
>     sysopen(FH, $Nsrc, O_RDWR|O_CREAT)
>         or &Error( "Cannot open $Nsrc for read/write: $!\n" );
>     flock(FH,LOCK_EX)
>         or &Error( "Cannot read/write lock num file: $!\n" );
>     $results = <FH> || 0;
>     seek(FH,0,0)
>         or &Error( "Cannot rewind num file: $!\n" );
>     truncate(FH,0)
>         or &Error( "Cannot truncate num file: $!\n" );

>     ## $results is in a format like this: 'A,1,B,9,C,3[\n]?'
>     chomp $results;             # just in case
>     %Results = split /,/,$results;

> ### do some stuff with %Results, like incrementing some values

>     print FH (join ',', %Results );
>     close FH;

> We recently had a situation where the disk it's
> writing to ran out of space.  I'd like to be able
> to check for available diskspace before doing the
> read/write, and if it is not available do the read
> and write on a different partition (like /tmp) as
> a temporary measure to prevent data loss.

The ultimate test of whether or not you can write something to
disk, is to write it and check if it succeeded.

Let me suggest a different algorithm:

    .  open an alternate file for locking only - "$Nsrc.lck"

    .  obtain an exclusive lock on "$Nsrc.lck"

    .  read $Nsrc into %Results and update

    .  write %Results to a tmpfile "$Nsrc.tmp$$"

    .  If all writes succeed (including close) then rename
       "$Nsrc.tmp$$" to $Nsrc.

    .  If a write failed then save %Results on different
       partition.

    .  close and release "$Nsrc.lck"

--
Jay Rogers



Sat, 09 Mar 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. RX library

2. database app without BDE?

3. Net::FTP bug when disk full?

4. Disk for 99% full alert

5. fred - full screen editor written mainly in perl

6. Who can help me write full-text search engine in Perl with indexing

7. Permissions -is 750 full read write access?

8. Dbgrid database update

9. Student help--records, linked lists, sorting

10. Getting Interbase User info

11. ANNOUNCE: LibA2 0.003 (read/write Apple II ProDOS disk images)

12. Corrupted disk writes with SDBM

 

 
Powered by phpBB® Forum Software