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,
});
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,
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 {
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,
);
}