Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Dealing with corrupt db_file files

by grondilu (Pilgrim)
on Jan 16, 2013 at 06:52 UTC ( #1013510=note: print w/ replies, xml ) Need Help??


in reply to Dealing with corrupt db_file files

When calling keys %hash, you load all keys in memory at once. This can take quite some time if your database is not small. Are you sure your programm hangs dead? How long have you been waiting? Maybe a look at a process watcher such as top could help.

Normally to loop through the keys of a tied database you should use the tied object (not the tied hash, see below) and a cursor using the seq method:

my $X = tie my %hash, 'DB_File', $filename; my ($key, $value); for ( my $status = $X->seq($key, $value, R_FIRST); $status == 0; $status = $X->seq($key, $value, R_NEXT) ) { ... }

I advise you to do something like that if you really need sequential access.


Comment on Re: Dealing with corrupt db_file files
Select or Download Code
Re^2: Dealing with corrupt db_file files
by gossamer (Novice) on Jan 17, 2013 at 01:18 UTC

    > When calling keys %hash, you load all keys in memory at once. This can take quite some time if your database is not small. Are you sure your programm hangs dead? How long have you been waiting? Maybe a look at a process watcher such as top could help.

    No, I'm sure the process is hung. I've let it sit overnight.

    It only happens once every few weeks. Rebuilding the corrupt db on the originating server fixes the problem, but the only way to find out I need to do this is after learning my script has been running all night. I then need to isolate which db file it is that's causing the issue, and rebuild that one file.

    I will work to try and implement your changes. Do you think that will be better at dealing with corrupt entries in the db file?

    Thanks,
    Dave

      I don't know if using seq will solve the issue then. It's definitely the correct way to access your database sequentially, though.

      I'd also suggest you add some lines to log the execution of your script, so that you can know at which point exactly it hangs.

      Other than that, I don't see much else to do, especially considering it is difficult to reproduce.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1013510]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (13)
As of 2014-07-31 20:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (253 votes), past polls