From: rkinyon Date: Sun, 31 Dec 2006 19:39:17 +0000 (+0000) Subject: Can write to and read from multiple index levels X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=625a24b4c64f49006f511f4199b11b7010cb5f90;p=dbsrgits%2FDBM-Deep.git Can write to and read from multiple index levels --- diff --git a/lib/DBM/Deep/Engine3.pm b/lib/DBM/Deep/Engine3.pm index ee6319d..1818659 100644 --- a/lib/DBM/Deep/Engine3.pm +++ b/lib/DBM/Deep/Engine3.pm @@ -1224,15 +1224,37 @@ sub get_bucket_list { while ( $sector->isa( 'DBM::Deep::Engine::Sector::Index' ) ) { $blist_loc = $sector->get_entry( ord( substr( $args->{key_md5}, $i++, 1 ) ) ); $last_sector = $sector; - $sector = $engine->_load_sector( $blist_loc ) - or die "Cannot read sector at $blist_loc in get_bucket_list()"; + if ( $blist_loc ) { + $sector = $engine->_load_sector( $blist_loc ) + or die "Cannot read sector at $blist_loc in get_bucket_list()"; + } + else { + $sector = undef; + last; + } + } + + # This means we went through the Index sector(s) and found an empty slot + unless ( $sector ) { + return unless $args->{create}; + + die "No last_sector when attempting to build a new entry" + unless $last_sector; + + my $blist = DBM::Deep::Engine::Sector::BucketList->new({ + engine => $engine, + key_md5 => $args->{key_md5}, + }); + + $last_sector->set_entry( ord( substr( $args->{key_md5}, $i - 1, 1 ) ) => $blist->offset ); + + return $blist; } $sector->find_md5( $args->{key_md5} ); # See whether or not we need to reindex the bucketlist if ( !$sector->has_md5 && $args->{create} && $sector->{idx} == -1 ) { - #print "Reindexing\n"; my $new_index = DBM::Deep::Engine::Sector::Index->new({ engine => $engine, }); @@ -1370,7 +1392,7 @@ sub chopped_up { my $e = $self->engine; - my @md5s; + my @buckets; foreach my $idx ( 0 .. $e->max_buckets - 1 ) { my $md5 = $e->storage->read_at( $self->offset + $self->base_size + $idx * $self->bucket_size, $e->hash_size, @@ -1379,10 +1401,10 @@ sub chopped_up { last if $md5 eq $e->blank_md5; my $rest = $e->storage->read_at( undef, $self->bucket_size - $e->hash_size ); - push @md5s, $md5 . $rest; + push @buckets, $md5 . $rest; } - return @md5s; + return @buckets; } sub write_at_next_open { @@ -1390,10 +1412,10 @@ sub write_at_next_open { my ($md5) = @_; #XXX This is such a hack! - $self->{_idx} = 0 unless exists $self->{_idx}; + $self->{_next_open} = 0 unless exists $self->{_next_open}; $self->engine->storage->print_at( - $self->offset + $self->base_size + $self->{_idx}++ * $self->bucket_size, + $self->offset + $self->base_size + $self->{_next_open}++ * $self->bucket_size, $md5, ); } diff --git a/t/03_bighash.todo b/t/03_bighash.t similarity index 97% rename from t/03_bighash.todo rename to t/03_bighash.t index 81215fd..9b81f87 100644 --- a/t/03_bighash.todo +++ b/t/03_bighash.t @@ -28,7 +28,6 @@ my $db = DBM::Deep->new( my $max_keys = 4000; for ( 0 .. $max_keys ) { - print "Adding $_\n"; $db->put( "hello $_" => "there " . $_ * 2 ); }