From: rkinyon Date: Wed, 27 Dec 2006 05:17:07 +0000 (+0000) Subject: Almost ready to add in the reindexing code and t/28.t X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d938be6a0e108ca97e17954188616bf2040b2b27;p=dbsrgits%2FDBM-Deep.git Almost ready to add in the reindexing code and t/28.t --- diff --git a/lib/DBM/Deep/Engine3.pm b/lib/DBM/Deep/Engine3.pm index 7270a67..41d2a08 100644 --- a/lib/DBM/Deep/Engine3.pm +++ b/lib/DBM/Deep/Engine3.pm @@ -1037,6 +1037,18 @@ sub _init { return; } +sub free { + my $self = shift; + + my $blist_loc = $self->get_blist_loc; + $self->engine->_load_sector( $blist_loc )->free if $blist_loc; + + my $class_loc = $self->get_class_offset; + $self->engine->_load_sector( $class_loc )->free if $class_loc; + + $self->SUPER::free(); +} + sub staleness { $_[0]{staleness} } sub get_data_for { @@ -1076,7 +1088,7 @@ sub write_data { # Handle any transactional bookkeeping. if ( $self->engine->trans_id ) { - if ( ! $blist->{found} ) { + if ( ! $blist->has_md5 ) { $blist->mark_deleted({ trans_id => 0, }); @@ -1084,7 +1096,7 @@ sub write_data { } else { my @trans_ids = $self->engine->get_running_txn_ids; - if ( $blist->{found} ) { + if ( $blist->has_md5 ) { if ( @trans_ids ) { my $old_value = $blist->get_data_for; foreach my $other_trans_id ( @trans_ids ) { @@ -1202,20 +1214,43 @@ sub get_bucket_list { return $blist; } - return DBM::Deep::Engine::Sector::BucketList->new({ - engine => $engine, - offset => $blist_loc, - key_md5 => $args->{key_md5}, - }); + # Add searching here through the index layers, if any + my $sector = $engine->_load_sector( $blist_loc ) + or die "Cannot read sector at $blist_loc in get_bucket_list()"; + my $i = 0; + my $last_sector = undef; + while ( $sector->isa( 'DBM::Deep::Engine::Sector::Index' ) ) { + $blist_loc = $sector->location_for( 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()"; + } + + $sector->find_md5( $args->{key_md5} ); + + # See whether or not we need to reindex the bucketlist + if ( !$sector->has_md5 && $args->{create} ) { + } + + return $sector; } -sub get_classname { +sub get_class_offset { my $self = shift; - my $class_offset = $self->engine->storage->read_at( - $self->offset + $self->base_size + 1 * $self->engine->byte_size, $self->engine->byte_size, + my $e = $self->engine; + return unpack( + $StP{$e->byte_size}, + $e->storage->read_at( + $self->offset + $self->base_size + 1 * $e->byte_size, $e->byte_size, + ), ); - $class_offset = unpack ( $StP{$self->engine->byte_size}, $class_offset ); +} + +sub get_classname { + my $self = shift; + + my $class_offset = $self->get_class_offset; return unless $class_offset; @@ -1274,7 +1309,8 @@ sub size { my $self = shift; unless ( $self->{size} ) { my $e = $self->engine; - $self->{size} = $self->base_size + $e->max_buckets * $self->bucket_size; # Base + numbuckets * bucketsize + # Base + numbuckets * bucketsize + $self->{size} = $self->base_size + $e->max_buckets * $self->bucket_size; } return $self->{size}; } @@ -1306,6 +1342,10 @@ sub find_md5 { $self->{found} = undef; $self->{idx} = -1; + if ( @_ ) { + $self->{key_md5} = shift; + } + # If we don't have an MD5, then what are we supposed to do? unless ( exists $self->{key_md5} ) { DBM::Deep->_throw_error( "Cannot find_md5 without a key_md5 set" ); @@ -1530,5 +1570,32 @@ sub size { sub free_meth { return '_add_free_index_sector' } +sub free { + my $self = shift; + my $e = $self->engine; + + for my $i ( 0 .. $e->hash_chars - 1 ) { + my $l = $self->location_for( $i ) or next; + $e->_load_sector( $l )->free; + } + + $self->SUPER::free(); +} + +sub location_for { + my $self = shift; + my ($idx) = @_; + + my $e = $self->engine; + + return unpack( + $StP{$e->byte_size}, + $e->storage->read_at( + $self->offset + $self->base_size + $idx * $self->byte_size, + $self->byte_size, + ), + ); +} + 1; __END__