return;
}
+=head2 load_sector( $loc )
+
+This takes an id/location/offset and loads the sector based on the engine's
+defined sector type.
+
+=cut
+
+sub load_sector { $_[0]->sector_type->load( @_ ) }
+
+=head2 ACCESSORS
+
+The following are readonly attributes.
+
+=over 4
+
+=item * storage
+
+=back
+
+=cut
+
+sub storage { $_[0]{storage} }
+
+sub sector_type { die "sector_type must be implemented in a child class" }
+
1;
__END__
use base 'DBM::Deep::Engine';
+use DBM::Deep::Sector::DBI ();
+use DBM::Deep::Storage::DBI ();
+
+sub sector_type { 'DBM::Deep::Sector::DBI' }
+
+__END__
+
sub read_value {
my $self = shift;
my ($obj, $key) = @_;
use DBM::Deep::Sector::File ();
use DBM::Deep::Storage::File ();
+sub sector_type { 'DBM::Deep::Sector::File' }
+
my $STALE_SIZE = 2;
# Please refer to the pack() documentation for further information
my ($obj, $key) = @_;
# This will be a Reference sector
- my $sector = DBM::Deep::Sector::File->load( $self, $obj->_base_offset )
+ my $sector = $self->load_sector( $obj->_base_offset )
or return;
if ( $sector->staleness != $obj->_staleness ) {
my ($obj) = @_;
# This will be a Reference sector
- my $sector = DBM::Deep::Sector::File->load( $self, $obj->_base_offset )
+ my $sector = $self->load_sector( $obj->_base_offset )
or DBM::Deep->_throw_error( "How did get_classname fail (no sector for '$obj')?!" );
if ( $sector->staleness != $obj->_staleness ) {
my ($obj, $old_key, $new_key) = @_;
# This will be a Reference sector
- my $sector = DBM::Deep::Sector::File->load( $self, $obj->_base_offset )
+ my $sector = $self->load_sector( $obj->_base_offset )
or DBM::Deep->_throw_error( "How did make_reference fail (no sector for '$obj')?!" );
if ( $sector->staleness != $obj->_staleness ) {
my ($obj, $key) = @_;
# This will be a Reference sector
- my $sector = DBM::Deep::Sector::File->load( $self, $obj->_base_offset )
+ my $sector = $self->load_sector( $obj->_base_offset )
or return '';
if ( $sector->staleness != $obj->_staleness ) {
my $self = shift;
my ($obj, $key) = @_;
- my $sector = DBM::Deep::Sector::File->load( $self, $obj->_base_offset )
+ my $sector = $self->load_sector( $obj->_base_offset )
or return;
if ( $sector->staleness != $obj->_staleness ) {
}
# This will be a Reference sector
- my $sector = DBM::Deep::Sector::File->load( $self, $obj->_base_offset )
+ my $sector = $self->load_sector( $obj->_base_offset )
or DBM::Deep->_throw_error( "Cannot write to a deleted spot in DBM::Deep." );
if ( $sector->staleness != $obj->_staleness ) {
}
#XXX Can this use $loc?
- my $value_sector = DBM::Deep::Sector::File->load( $self, $tmpvar->_base_offset );
+ my $value_sector = $self->load_sector( $tmpvar->_base_offset );
$sector->write_data({
key => $key,
key_md5 => $self->_apply_digest( $key ),
$self->storage->print_at( $read_loc, pack( $StP{$self->byte_size}, 0 ) );
if ( $data_loc > 1 ) {
- DBM::Deep::Sector::File->load( $self, $data_loc )->free;
+ $self->load_sector( $data_loc )->free;
}
}
);
if ( $head_loc > 1 ) {
- DBM::Deep::Sector::File->load( $self, $head_loc )->free;
+ $self->load_sector( $head_loc )->free;
}
}
=over 4
-=item * storage
-
=item * byte_size
=item * hash_size
=cut
-sub storage { $_[0]{storage} }
sub byte_size { $_[0]{byte_size} }
sub hash_size { $_[0]{hash_size} }
sub hash_chars { $_[0]{hash_chars} }
SECTOR:
while ( $spot < $self->storage->{end} ) {
# Read each sector in order.
- my $sector = DBM::Deep::Sector::File->load( $self, $spot );
+ my $sector = $self->load_sector( $spot );
if ( !$sector ) {
# Find it in the free-sectors that were found already
foreach my $type ( keys %sectors ) {
my $self = shift;
my ($loc) = @_;
- my $sector = DBM::Deep::Sector::File->load( $self->{engine}, $loc )
+ my $sector = $self->{engine}->load_sector( $loc )
or return;
if ( $sector->isa( 'DBM::Deep::Sector::File::Index' ) ) {
unless ( @$crumbs ) {
# This will be a Reference sector
- my $sector = DBM::Deep::Sector::File->load( $e, $self->{base_offset} )
+ my $sector = $e->load_sector( $self->{base_offset} )
# If no sector is found, this must have been deleted from under us.
or return;
--- /dev/null
+package DBM::Deep::Sector::DBI;
+
+use 5.006_000;
+
+use strict;
+use warnings FATAL => 'all';
+
+use base 'DBM::Deep::Sector';
+
+1;
+__END__
# Delete the keysector
my $l = unpack( $StP{$e->byte_size}, substr( $rest, $e->hash_size, $e->byte_size ) );
- my $s = DBM::Deep::Sector::File->load( $e, $l ); $s->free if $s;
+ my $s = $e->load_sector( $l ); $s->free if $s;
# Delete the HEAD sector
$l = unpack( $StP{$e->byte_size},
$e->byte_size,
),
);
- $s = DBM::Deep::Sector::File->load( $e, $l ); $s->free if $s;
+ $s = $e->load_sector( $l ); $s->free if $s;
foreach my $txn ( 0 .. $e->num_txns - 2 ) {
my $l = unpack( $StP{$e->byte_size},
$e->byte_size,
),
);
- my $s = DBM::Deep::Sector::File->load( $e, $l ); $s->free if $s;
+ my $s = $e->load_sector( $l ); $s->free if $s;
}
}
$key_sector->free;
- my $data_sector = DBM::Deep::Sector::File->load( $self->engine, $location );
+ my $data_sector = $self->engine->load_sector( $location );
my $data = $data_sector->data({ export => 1 });
$data_sector->free;
my $location = $self->get_data_location_for({
allow_head => $args->{allow_head},
});
- return DBM::Deep::Sector::File->load( $self->engine, $location );
+ return $self->engine->load_sector( $location );
}
sub get_key_for {
$location = unpack( $StP{$self->engine->byte_size}, $location );
DBM::Deep->_throw_error( "get_key_for: No location?" ) unless $location;
- return DBM::Deep::Sector::File->load( $self->engine, $location );
+ return $self->engine->load_sector( $location );
}
1;
for my $i ( 0 .. $e->hash_chars - 1 ) {
my $l = $self->get_entry( $i ) or next;
- DBM::Deep::Sector::File->load( $e, $l )->free;
+ $e->load_sector( $l )->free;
}
$self->SUPER::free();
my $location = $self->get_data_location_for( $args )
or return;
- return DBM::Deep::Sector::File->load( $self->engine, $location );
+ return $self->engine->load_sector( $location );
}
sub write_data {
my $location = $blist->get_data_location_for({
allow_head => 0,
});
- my $old_value = $location && DBM::Deep::Sector::File->load( $self->engine, $location );
+ my $old_value = $location && $self->engine->load_sector( $location );
my @trans_ids = $self->engine->get_running_txn_ids;
return $blist;
}
- my $sector = DBM::Deep::Sector::File->load( $engine, $blist_loc )
+ my $sector = $engine->load_sector( $blist_loc )
or DBM::Deep->_throw_error( "Cannot read sector at $blist_loc in get_bucket_list()" );
my $i = 0;
my $last_sector = undef;
$blist_loc = $sector->get_entry( ord( substr( $args->{key_md5}, $i++, 1 ) ) );
$last_sector = $sector;
if ( $blist_loc ) {
- $sector = DBM::Deep::Sector::File->load( $engine, $blist_loc )
+ $sector = $engine->load_sector( $blist_loc )
or DBM::Deep->_throw_error( "Cannot read sector at $blist_loc in get_bucket_list()" );
}
else {
return unless $class_offset;
- return DBM::Deep::Sector::File->load( $self->engine, $class_offset )->data;
+ return $self->engine->load_sector( $class_offset )->data;
}
sub data {
delete $self->engine->cache->{ $self->offset };
my $blist_loc = $self->get_blist_loc;
- DBM::Deep::Sector::File->load( $self->engine, $blist_loc )->free if $blist_loc;
+ $self->engine->load_sector( $blist_loc )->free if $blist_loc;
my $class_loc = $self->get_class_offset;
- DBM::Deep::Sector::File->load( $self->engine, $class_loc )->free if $class_loc;
+ $self->engine->load_sector( $class_loc )->free if $class_loc;
$self->SUPER::free();
}
$self->SUPER::free();
if ( $chain_loc ) {
- DBM::Deep::Sector::File->load( $self->engine, $chain_loc )->free;
+ $self->engine->load_sector( $chain_loc )->free;
}
return;
last unless $chain_loc;
- $self = DBM::Deep::Sector::File->load( $self->engine, $chain_loc );
+ $self = $self->engine->load_sector( $chain_loc );
}
return $data;