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 {
# Handle any transactional bookkeeping.
if ( $self->engine->trans_id ) {
- if ( ! $blist->{found} ) {
+ if ( ! $blist->has_md5 ) {
$blist->mark_deleted({
trans_id => 0,
});
}
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 ) {
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;
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};
}
$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" );
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__