[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

Using locking with BerkeleyDB

I am using the BerkeleyDB Perl module on Windows using ActivePerl.

I am trying to get it to work with locking.

The documentation is quite light on this and just tells you how to initalise locking,

I read through the documentation provided by Oracle for the database and am trying to mimic that to implement locking in Perl.

This is where Oracle tell you to use locking:
http://www.oracle.com/technology/documentation/berkeley-db/db/api_c/lock_list.html

I have attached the code that I'm using which gives me the error:
"Can't call method "lock_id" on an undefined value at testa.pl line 10."

I also tried calling lock_id() on $dbEnv and got this error:
"Can't locate object method "lock_id" via package "BerkeleyDB::Env" at testa.pl l
ine 10."

Does anyone know how I should be doing it so that I can use this module with locking.
use strict;
use BerkeleyDB;
 
my %tData;
 
my $dbEnv = BerkeleyDB::Env -> new ( -Flags => DB_CREATE | DB_INIT_LOCK );
my $hDb = tie %tData , 'BerkeleyDB::Hash' , { -Env => $dbEnv , -Filename => 'tData.db' , -Flags => DB_CREATE };
 
#get a locker id
$hDb -> lock_id();

Open in new window

0
intechfs
Asked:
intechfs
1 Solution
 
Adam314Commented:

#To lock
my $lock = $hDb->cds_lock();
 
#To unlock
#either $lock goes out of scope, or
$lock->cds_unlock();

Open in new window

0
 
intechfsAuthor Commented:
Thanks for this.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now