Click here to get back home

problem with BerkeleyDB module and subdatabases

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
problem with BerkeleyDB module and subdatabases Mark E. Perkins 02-27-2005
Posted by Mark E. Perkins on February 27, 2005, 9:40 pm
Please log in for more thread options


Greetings,

Executive Summary:
I can't get the latest version of the BerkeleyDB module (v0.26) with the
latest version of Sleepycat (v4.3.27) to create subdatabases properly.
Sample code at end illustrates my problem.

Details:
Using the BerkeleyDB module (v0.26), Sleepycat 4.3.27 and Perl 5.8.6 under
Mac OS X 10.3.8, attempts to create a db with four subdatabases only
creates two of them. A second run of the sample code adds one of the
subdatabases that was missing, but one of those that *was* created on the
first run turns out to have data that were intended for one that went
missing on the first run. A third run of the code finally gets all four
subdatabases, but (understandably) with the same unwanted data as noted
after the second run.

I don't think this is the way subdatabases are intended to work 8) But I
can't see my error.

The sample code included below (when saved as bdb-tst), produces the
following output ('-> ' is the shell prompt string):

-> rm -f junk.db
-> ./bdb-tst
h1 = v1
h2 = v2
h3 = v3
h4 = v4
subdb names are:
hash_1
hash_4
-> ./bdb-tst
h1 = v1
h2 = v2
h3 = v3
h4 = v3
h4 = v4
subdb names are:
hash_1
hash_3
hash_4
-> ./bdb-tst
h1 = v1
h2 = v2
h3 = v3
h4 = v3
h4 = v4
subdb names are:
hash_1
hash_2
hash_3
hash_4
-> ./bdb-tst
h1 = v1
h2 = v2
h3 = v3
h4 = v3
h4 = v4
subdb names are:
hash_1
hash_2
hash_3
hash_4

Additional observations:
I see similar (erroneous) behavior when I use the 'new' form of the the
BerkeleyDB::Hash constructor for each of the subdatabases; which
subdatabases get created on which runs is different, but still two on the
first and one on each subsequent, with similarly erroneous data. My app
needs MLDBM, hence the tied hash version in the sample code.

I see exactly the same results under Solaris 9 with Perl 5.8.4 and the same
versions of BerkeleyDB and Sleepycat noted above.

Everything works as expected under Mac OS X 10.3.8 with Perl 5.8.6,
Sleepycat 4.1.25 and BerkeleyDB 0.26.

Sample code below follows closely (and borrows from) the subdb.t test
module from BerkeleyDB...

After all that explanation, can someone point me at what I'm doing wrong?

Thanks,
Mark


---------------8<--------------- cut here ---------------8<---------------
#!/usr/bin/perl
#
#bdb-tst to illustrate subdatabase problem

use strict;
use warnings;

use BerkeleyDB;

tie my %h1, 'BerkeleyDB::Hash', -Filename => "junk.db",
-Subname => "hash_1",
-Flags => DB_CREATE
or die "cannot tie h1: ($!)";

tie my %h2, 'BerkeleyDB::Hash', -Filename => "junk.db",
-Subname => "hash_2",
-Flags => DB_CREATE
or die "cannot tie h2: ($!)";

tie my %h3, 'BerkeleyDB::Hash', -Filename => "junk.db",
-Subname => "hash_3",
-Flags => DB_CREATE
or die "cannot tie h3: ($!)";

tie my %h4, 'BerkeleyDB::Hash', -Filename => "junk.db",
-Subname => "hash_4",
-Flags => DB_CREATE
or die "cannot tie h4: ($!)";

$h1 = 'v1';
$h2 = 'v2';
$h3 = 'v3';
$h4 = 'v4';

for my $k ( sort keys %h1 ) {
print "h1 = $h1n";
}

for my $k ( sort keys %h2 ) {
print "h2 = $h2n";
}

for my $k ( sort keys %h3 ) {
print "h3 = $h3n";
}

for my $k ( sort keys %h4 ) {
print "h4 = $h4n";
}

untie %h1;
untie %h2;
untie %h3;
untie %h4;

# check to see what subdatabases are actually in the db

my $db = new BerkeleyDB::Unknown -Filename => "junk.db",
-Flags => DB_RDONLY;

my $cursor = $db->db_cursor();
my ($k, $v) = ("", "");
my $status;
my @dbnames = ();
while ( ($status = $cursor->c_get($k, $v, DB_NEXT) ) == 0) {
push @dbnames, $k;
}

print "subdb names are:n";
print "$_n"        for @dbnames;


Posted by Paul Marquess on March 3, 2005, 6:08 pm
Please log in for more thread options


> Greetings,
>
> Executive Summary:
> I can't get the latest version of the BerkeleyDB module (v0.26) with the
> latest version of Sleepycat (v4.3.27) to create subdatabases properly.
> Sample code at end illustrates my problem.
>
> Details:
> Using the BerkeleyDB module (v0.26), Sleepycat 4.3.27 and Perl 5.8.6 under
> Mac OS X 10.3.8, attempts to create a db with four subdatabases only
> creates two of them. A second run of the sample code adds one of the
> subdatabases that was missing, but one of those that *was* created on the
> first run turns out to have data that were intended for one that went
> missing on the first run. A third run of the code finally gets all four
> subdatabases, but (understandably) with the same unwanted data as noted
> after the second run.
>
> I don't think this is the way subdatabases are intended to work 8) But I
> can't see my error.
>
> The sample code included below (when saved as bdb-tst), produces the
> following output ('-> ' is the shell prompt string):
>
> -> rm -f junk.db
> -> ./bdb-tst
> h1 = v1
> h2 = v2
> h3 = v3
> h4 = v4
> subdb names are:
> hash_1
> hash_4
> -> ./bdb-tst
> h1 = v1
> h2 = v2
> h3 = v3
> h4 = v3
> h4 = v4
> subdb names are:
> hash_1
> hash_3
> hash_4
> -> ./bdb-tst
> h1 = v1
> h2 = v2
> h3 = v3
> h4 = v3
> h4 = v4
> subdb names are:
> hash_1
> hash_2
> hash_3
> hash_4
> -> ./bdb-tst
> h1 = v1
> h2 = v2
> h3 = v3
> h4 = v3
> h4 = v4
> subdb names are:
> hash_1
> hash_2
> hash_3
> hash_4
>
> Additional observations:
> I see similar (erroneous) behavior when I use the 'new' form of the the
> BerkeleyDB::Hash constructor for each of the subdatabases; which
> subdatabases get created on which runs is different, but still two on the
> first and one on each subsequent, with similarly erroneous data. My app
> needs MLDBM, hence the tied hash version in the sample code.
>
> I see exactly the same results under Solaris 9 with Perl 5.8.4 and the
same
> versions of BerkeleyDB and Sleepycat noted above.
>
> Everything works as expected under Mac OS X 10.3.8 with Perl 5.8.6,
> Sleepycat 4.1.25 and BerkeleyDB 0.26.
>
> Sample code below follows closely (and borrows from) the subdb.t test
> module from BerkeleyDB...
>
> After all that explanation, can someone point me at what I'm doing wrong?

Have a read at this http://www.sleepycat.com/docs/ref/am/opensub.html

In particular, this part

"...if any of the databases in a file is opened for

updates, all of the databases in the file must share

a memory pool."



Below is you code with rewritten to use an environment.



Paul



use strict;
use warnings;

use BerkeleyDB;

my $home = './home';

mkdir $home ;

my $Env = new BerkeleyDB::Env -Home => $home,
-ErrFile => "$home/err",
-Flags => DB_CREATE|DB_INIT_MPOOL
or die "Create env in "$home" failed: $! /
$BerkeleyDB::Errorn";

tie my %h1, 'BerkeleyDB::Hash', -Filename => "junk.db",
-Subname => "hash_1",
-Flags => DB_CREATE,
-Env => $Env
or die "cannot tie h1: ($!)";

tie my %h2, 'BerkeleyDB::Hash', -Filename => "junk.db",
-Subname => "hash_2",
-Flags => DB_CREATE,
-Env => $Env
or die "cannot tie h2: ($!)";

tie my %h3, 'BerkeleyDB::Hash', -Filename => "junk.db",
-Subname => "hash_3",
-Flags => DB_CREATE,
-Env => $Env
or die "cannot tie h3: ($!)";

tie my %h4, 'BerkeleyDB::Hash', -Filename => "junk.db",
-Subname => "hash_4",
-Flags => DB_CREATE,
-Env => $Env
or die "cannot tie h4: ($!)";

$h1 = 'v1';
$h2 = 'v2';
$h3 = 'v3';
$h4 = 'v4';

for my $k ( sort keys %h1 ) {
print "h1 = $h1n";
}

for my $k ( sort keys %h2 ) {
print "h2 = $h2n";
}

for my $k ( sort keys %h3 ) {
print "h3 = $h3n";
}

for my $k ( sort keys %h4 ) {
print "h4 = $h4n";
}

untie %h1;
untie %h2;
untie %h3;
untie %h4;

# check to see what subdatabases are actually in the db

my $db = new BerkeleyDB::Unknown -Filename => "junk.db",
-Env => $Env,
-Flags => DB_RDONLY
or die "Cannot open unknown $! $BerkeleyDB::Errorn";

my $cursor = $db->db_cursor();
my ($k, $v) = ("", "");
my $status;
my @dbnames = ();
while ( ($status = $cursor->c_get($k, $v, DB_NEXT) ) == 0) {
push @dbnames, $k;
}

print "subdb names are:n";
print "$_n" for @dbnames;





Posted by Mark E. Perkins on March 3, 2005, 8:47 pm
Please log in for more thread options


On 3/3/05 12:08, Paul Marquess wrote:


<snip>

>>After all that explanation, can someone point me at what I'm doing wrong?
>
>
> Have a read at this http://www.sleepycat.com/docs/ref/am/opensub.html
>
> In particular, this part
>
> "...if any of the databases in a file is opened for
>
> updates, all of the databases in the file must share
>
> a memory pool."
>

I actually did read that at some point, but made the mistaken assumption
that since I was opening/creating "all at once" that they would be in the
same environment and that any defaults would be all I needed... 8(

> Below is you code with rewritten to use an environment.

<snip>

> Paul

Thanks for the help.

Mark


Similar ThreadsPosted
Cant load ...BerkeleyDB.so for module BerkeleyDB: libdb-4.4.so January 19, 2006, 1:53 pm
Trying to build berkeleyDB module against M$ VStudio 2005 SDK stuff September 24, 2008, 10:53 pm
How to increase performance BerkeleyDB? November 14, 2007, 7:25 am
BerkeleyDB: Graduating from text files; tutorial? September 25, 2004, 6:18 am
ANNOUNCE: Search::InvertedIndex::Simple::BerkeleyDB V 1.00 April 17, 2005, 3:18 am
BerkeleyDB Queue Database Array Size August 14, 2006, 2:50 am
Problem with Net::SSH::Perl module December 22, 2004, 12:38 pm
Problem using C module in perl January 5, 2006, 5:03 am
Problem installing GD module April 4, 2006, 12:26 pm
Problem Installing Module April 4, 2007, 10:02 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap