|
|
|
|
|
|
| Author |
Message |
Mark E. Perkins *nix forums beginner
Joined: 28 Feb 2005
Posts: 2
|
Posted: Thu Mar 03, 2005 11:47 pm Post subject:
Re: problem with BerkeleyDB module and subdatabases
|
|
|
On 3/3/05 12:08, Paul Marquess wrote:
| Quote: | "Mark E. Perkins" <perkinsm@bway.net> wrote in message
news:zfydnRNmcbbr67_fRVn-vQ@bway.net...
|
<snip>
| Quote: | 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(
| Quote: | Below is you code with rewritten to use an environment.
|
<snip>
Thanks for the help.
Mark |
|
| Back to top |
|
 |
Paul Marquess *nix forums beginner
Joined: 03 Mar 2005
Posts: 29
|
Posted: Thu Mar 03, 2005 4:08 pm Post subject:
Re: problem with BerkeleyDB module and subdatabases
|
|
|
"Mark E. Perkins" <perkinsm@bway.net> wrote in message
news:zfydnRNmcbbr67_fRVn-vQ@bway.net...
| Quote: | 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 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{k1} = v1
h2{k2} = v2
h3{k3} = v3
h4{k4} = v4
subdb names are:
hash_1
hash_4
-> ./bdb-tst
h1{k1} = v1
h2{k2} = v2
h3{k3} = v3
h4{k3} = v3
h4{k4} = v4
subdb names are:
hash_1
hash_3
hash_4
-> ./bdb-tst
h1{k1} = v1
h2{k2} = v2
h3{k3} = v3
h4{k3} = v3
h4{k4} = v4
subdb names are:
hash_1
hash_2
hash_3
hash_4
-> ./bdb-tst
h1{k1} = v1
h2{k2} = v2
h3{k3} = v3
h4{k3} = v3
h4{k4} = 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::Error\n";
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{k1} = 'v1';
$h2{k2} = 'v2';
$h3{k3} = 'v3';
$h4{k4} = 'v4';
for my $k ( sort keys %h1 ) {
print "h1{$k} = $h1{$k}\n";
}
for my $k ( sort keys %h2 ) {
print "h2{$k} = $h2{$k}\n";
}
for my $k ( sort keys %h3 ) {
print "h3{$k} = $h3{$k}\n";
}
for my $k ( sort keys %h4 ) {
print "h4{$k} = $h4{$k}\n";
}
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::Error\n";
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; |
|
| Back to top |
|
 |
Mark E. Perkins *nix forums beginner
Joined: 28 Feb 2005
Posts: 2
|
Posted: Mon Feb 28, 2005 12:40 am Post subject:
problem with BerkeleyDB module and subdatabases
|
|
|
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 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{k1} = v1
h2{k2} = v2
h3{k3} = v3
h4{k4} = v4
subdb names are:
hash_1
hash_4
-> ./bdb-tst
h1{k1} = v1
h2{k2} = v2
h3{k3} = v3
h4{k3} = v3
h4{k4} = v4
subdb names are:
hash_1
hash_3
hash_4
-> ./bdb-tst
h1{k1} = v1
h2{k2} = v2
h3{k3} = v3
h4{k3} = v3
h4{k4} = v4
subdb names are:
hash_1
hash_2
hash_3
hash_4
-> ./bdb-tst
h1{k1} = v1
h2{k2} = v2
h3{k3} = v3
h4{k3} = v3
h4{k4} = 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{k1} = 'v1';
$h2{k2} = 'v2';
$h3{k3} = 'v3';
$h4{k4} = 'v4';
for my $k ( sort keys %h1 ) {
print "h1{$k} = $h1{$k}\n";
}
for my $k ( sort keys %h2 ) {
print "h2{$k} = $h2{$k}\n";
}
for my $k ( sort keys %h3 ) {
print "h3{$k} = $h3{$k}\n";
}
for my $k ( sort keys %h4 ) {
print "h4{$k} = $h4{$k}\n";
}
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; |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Wed Jan 07, 2009 9:22 pm | All times are GMT
|
|
Xbox Mod Chip | Loans | Fish Tank Help | Mobile Phones | Guitar Lesson
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|