Hi,

I'm a novice perl programmer and have written a set of functions that use DB_File write to a hash that consists of a filename and some of its contents. It's actually quarantine files from amavisd-new and some info about the files, such as the subject, spam score, etc.

I've been using these routines for quite some time, but every once in a while, searching through one of the db files causes my scripts to just hang.

Is there a known problem with corruption, perhaps caused by locking, with db_file?

For example, when I use the typical routines to scan through the hash:

#!/usr/bin/perl -w # use perl; use DB_File; use DBI; use File::Basename qw(basename); use strict; my @nochosts = qw(); my $qdir = '/var/www/noc.mydomain.com-80/'; push @nochosts, 'nocmail01'; foreach my $noc (@nochosts) { my $file = sprintf('%s/%s/%02x.db', $qdir, $noc, 170); print "file: $file\n"; tie (my %hash, 'DB_File', $file, O_RDWR, 0600, $DB_HASH) || die " +Cannot tie $file\n"; print "tie finished\n"; foreach my $key ( keys %hash ) { print "processing key: $key\n"; } untie %hash; }

The 170 represents 'aa', so in this case I'm trying to read aa.db. I've hard-coded it here, where I normally have a loop that iterates through 256 db files. I've just done it here for brevity and the aa.db file is the one with the problem.

On occasion, the script will just hang after tieing to the db on the foreach line. I don't know how the file gets corrupt, but recreating it from the source of all the amavisd-new quarantine entries for that bucket fixes the problem.

So, what would cause the script to hang when trying to process the foreach line?

I've tried several other ways, including while loops, to process the hash, and they also lock up at that point.

The script that creates the hash is much more involved, so I've not posted that here for now.

Any ideas greatly appreciated.
Thanks,
Dave

In reply to Dealing with corrupt db_file files by gossamer

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.