Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: can't manage to use BerkeleyDB::Env

by flexvault (Monsignor)
on Aug 23, 2012 at 14:24 UTC ( [id://989322]=note: print w/replies, xml ) Need Help??


in reply to can't manage to use BerkeleyDB::Env

grondilu,

This is a code snippet from a working program, to show you how to use the 'BerkeleyDB::Env'. Think of the environment as a holding directory, where related databases are stored, and the related BerkeleyDB internal files and cache are stored. I wouldn't use '/tmp' since it's world readable, but that's your call.

I pulled a lot of unrelated testing out, so it may not compile, but you'll be in the ballpark. This shows with the default cache size, but I usually 16MB in production.

One important thing, I left the 'Fcntl' in to help you think about the potential for race conditions. I use an extra file to lock the BerkeleyDB environment before using the BerkeleyDB calls. Without it, you are suspect to many race conditions. If you are going to run in single user mode, you don't need it. But for multi-user or multi-tasking you'll save yourself a lot of headaches. BerkeleyDB is very fast and you don't notice any overhead with the extra flocks.

use strict; + use BerkeleyDB; our %Session = (); use Fcntl qw( :flock ); my $DBHome = "/home/FlexBase/"; system("rm /home/FlexBase/*"); ## Temporary for testing our $filename = "/home/FlexBase/TestBDB"; use constant CACHE => '1048576'; my $Cachesize = CACHE; our $env = new BerkeleyDB::Env ( -Home => '/home/FlexBase', -Cachesize => CACHE, -Flags => DB_INIT_MPOOL|DB_INIT_CDB|DB_CREATE ) or die "cannot open ENV: $! $BerkeleyDB::Error\n"; our %Pyr = (); our $db1 = tie %Pyr, 'BerkeleyDB::Btree', ( -Filename => "$filename", -Env => $env, # -Pagesize => 4096, ## Use of this makes the Berk +eleyDB operate worst! -Flags => DB_CREATE );

If you super search on BerkeleyDB, you'll find some examples of subroutines that show the external locking and some timing information.

Good Luck!

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

Replies are listed 'Best First'.
Re^2: can't manage to use BerkeleyDB::Env
by grondilu (Friar) on Aug 23, 2012 at 21:14 UTC
    Thanks. That should definitely help.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-19 01:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found