persistence problems using DB_File and MLDBM 
Author Message
 persistence problems using DB_File and MLDBM

[Posted & Mailed ]

: This is a weird situation, but I'm hoping that I've overlooked a simple
: answer.

: I have a bunch of objects stored in a hash tied to a DB_File via
: MLDBM, but they keep getting "lost".  By that I mean if I *know*
: the name of the key, I can get the value, but not all the keys
: show in "keys %tiedhash".

: Some simple code below demonstrates the problem.  In it, I just copy the
: members of one tied hash to another, and then find that the number of
: keys aren't the same.  When run, it produces the following output:

: 140 keys in Project.DB
: 0 keys in New.DB to start
: 140 keys in New.DB when built
: 13 keys in New.DB when reopened
: J00127
: J00128
: J02908
: J05213
: L10347
: L10349
: L13616
: M32313
: M81104
: U37022
: U37028
: U95299
: X68452
: ProbeSet=HASH(0x1400415b8)

: Here's the code:

: #!/usr2/local/bin/perl -w

: use lib qw(/usr2/users/gtk/lib/perl5);

: use strict;
: use Carp;
: use Data::Dumper;
: use DB_File;
: use MLDBM;
: $MLDBM::UseDB = 'DB_File';

: # %STARTLIST contains a bunch of objects that I've
: # placed before.  Just open this puppy up.

: my ($startlist,%STARTLIST);

: $startlist = tie (%STARTLIST,'MLDBM',"Project.DB",
:                 O_RDWR,0664,$DB_HASH) or croak $!;

: print (scalar keys %STARTLIST, " keys in Project.DB\n");

: # Now copy the elements into %NEWLIST, which should be a new
: # file.

: my %NEWLIST;
: my $newlist;

: $newlist = tie (%NEWLIST,'MLDBM',"New.DB",
:                 O_RDWR | O_CREAT,0664,$DB_HASH) or croak $!;

: print (scalar keys %NEWLIST, " keys in New.DB to start\n");  # This
: should be zero

: my $name;
: foreach $name (sort keys %STARTLIST) {
:   $NEWLIST{$name} = $STARTLIST{$name};
:   $newlist->sync;  # for good measure, apparently makes no difference
: }

: print (scalar keys %NEWLIST, " keys in New.DB when built\n");

: # This should be equal to the number of keys in %STARTLIST;

: undef $newlist;
: untie %NEWLIST;
: undef %NEWLIST;

: my %CHECKLIST;   # This will be identical to %NEWLIST, right?
: my $checklist;

: $checklist  = tie (%CHECKLIST,'MLDBM',"New.DB",
:                 O_RDWR,0664,$DB_HASH) or croak $!;

: print (scalar keys %CHECKLIST, " keys in New.DB when reopened\n");

: print join("\n",sort keys %CHECKLIST), "\n";

: if (defined $CHECKLIST{'U49844'}) { print $CHECKLIST{'U49844'}, "\n"; }

: # Huh?  Why should this be defined if it isn't found in
: # keys(%CHECKLIST)?

This sounds like a known problem with the version of Berkeley DB you
are using. I would guess it is 1.85.

If you upgrade to 1.86 the problem should go away.

Paul

ps 1.86 is available on the Berkeley DB home page www.sleepycat.com



Thu, 20 Apr 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. DB_File and seq function (using MLDBM)

2. Problem using MLDBM

3. Problem using MLDBM

4. MLDBM qw(DB_File Storable) & concurrent access

5. MLDBM qw(DB_File Storable) & concurrent access

6. MLDBM/DB_File, file size, deleting records

7. DB_file, MLDBM and core dumped

8. Problem adding to Berkeley DB file using DB_File

9. problem with dynaloader using db_file

10. DB_File - using the DB interface directly - problem with object reference

11. Problem using fd on DB_Files

12. DB_File - using the DB interface directly - problem with object reference

 

 
Powered by phpBB® Forum Software