Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

BerkeleyDB continue

by lskatz (Novice)
on Jul 15, 2011 at 04:01 UTC ( #914501=perlquestion: print w/replies, xml ) Need Help??

lskatz has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks!

I was wondering how to continue building a BerkeleyDB. I am building a BerkeleyDB but it keeps getting interrupted! When I start the script again it truncates the file. How can I put in a "continue" flag?

My initial code is the following:
tie(%uniprot_h, "BerkeleyDB::Hash", -Filename => $dbfile, -Flags => DB +_CREATE, -Property => DB_DUP) or die "Cannot open file $dbfile: $! $BerkeleyDB::Error\n";
And then I begin adding onto the hash again.

Replies are listed 'Best First'.
Re: BerkeleyDB continue
by Anonymous Monk on Jul 15, 2011 at 07:31 UTC

    Hi monks! I was wondering how to continue building a BerkeleyDB. I am building a BerkeleyDB but it keeps getting interrupted! When I start the script again it truncates the file. How can I put in a "continue" flag?

    What do you mean by interrupt?

    The code you have posted, will continue, it won't truncate -- maybe you need to flush?

      Interrupted: I have to turn off my computer and it stops the code from running. What is the flush step? It is truncating the database whenever it is initialized with that tie command and writes to the hash. So maybe I need to put a flush statement into an END block?

        What is the flush step?

        Its calling the flush function

        It is truncating the database whenever it is initialized with that tie command and writes to the hash.

        No , berkeleydb won't do that -- if truncation is occurring, its a problem with the code you did not show

        So maybe I need to put a flush statement into an END block?

        Sure, if an END block will get executed after you interrupt it, put it there -- see Signals and END block

Re: BerkeleyDB continue
by flexvault (Monsignor) on Jul 15, 2011 at 13:16 UTC

    You need to periodically do a 'db_sync()', not just at the end of the program. BerkeleyDB is never in a finished state unless you do a 'db_sync' and then a 'db_close' when you are finished. For performance reasons, BDB only writes the data to disk when the internal buffers are full or when it receives the 'db_sync()'. I guess doing a periodic 'untie' and then 'tie' might work also. I stopped using 'tie' with BerkeleyDB because I didn't have the control over the cache size that you get when you use BerkeleyDB commands directly.

    If your script runs continuously then you may want to look at 'signals' to help shutdown you application ('db_sync' then 'db_close' or 'untie') before you turn off the computer.

    Thank you

    "Well done is better than well said." - Benjamin Franklin

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://914501]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2021-01-19 02:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?