sub read_txn_slots {
my $self = shift;
- my $bitfield_len = ($self->num_txns) / 8;
- if ( $bitfield_len > int( $bitfield_len ) ) {
- $bitfield_len = int( $bitfield_len ) + 1;
- }
- my $num_bits = $bitfield_len * 8;
+ my $bl = $self->txn_bitfield_len;
+ my $num_bits = $bl * 8;
return split '', unpack( 'b'.$num_bits,
$self->storage->read_at(
- $self->trans_loc, $bitfield_len,
+ $self->trans_loc, $bl,
)
);
}
sub write_txn_slots {
my $self = shift;
- my $bitfield_len = ($self->num_txns) / 8;
- if ( $bitfield_len > int( $bitfield_len ) ) {
- $bitfield_len = int( $bitfield_len ) + 1;
- }
- my $num_bits = $bitfield_len * 8;
+ my $num_bits = $self->txn_bitfield_len * 8;
$self->storage->print_at( $self->trans_loc,
pack( 'b'.$num_bits, join('', @_) ),
);
my $self = shift;
my $nt = $self->num_txns;
- my $bitfield_len = ($nt) / 8;
- if ( $bitfield_len > int( $bitfield_len ) ) {
- $bitfield_len = int( $bitfield_len ) + 1;
- }
+ my $bl = $self->txn_bitfield_len;
- my $header_var = 1 + 1 + 1 + 1 + $bitfield_len + $STALE_SIZE * ($nt - 1) + 3 * $self->byte_size;
+ my $header_var = 1 + 1 + 1 + 1 + $bl + $STALE_SIZE * ($nt - 1) + 3 * $self->byte_size;
my $loc = $self->storage->request_space( $header_fixed + $header_var );
pack('C', $self->data_sector_size - 1),
pack('C', $nt),
- pack('C' . $bitfield_len, 0 ), # Transaction activeness bitfield
+ pack('C' . $bl, 0 ), # Transaction activeness bitfield
pack($StP{$STALE_SIZE}.($nt-1), 0 x ($nt-1) ), # Transaction staleness counters
pack($StP{$self->byte_size}, 0), # Start of free chain (blist size)
pack($StP{$self->byte_size}, 0), # Start of free chain (data size)
#XXX Set these less fragilely
$self->set_trans_loc( $header_fixed + 4 );
- $self->set_chains_loc( $header_fixed + 4 + $bitfield_len + $STALE_SIZE * ($nt-1) );
+ $self->set_chains_loc( $header_fixed + 4 + $bl + $STALE_SIZE * ($nt-1) );
return;
}
$self->{max_buckets} += 1;
$self->{data_sector_size} += 1;
- my $bitfield_len = ($self->num_txns) / 8;
- if ( $bitfield_len > int( $bitfield_len ) ) {
- $bitfield_len = int( $bitfield_len ) + 1;
- }
+ my $bl = $self->txn_bitfield_len;
- my $header_var = scalar(@values) + $bitfield_len + $STALE_SIZE * ($self->num_txns - 1) + 3 * $self->byte_size;
+ my $header_var = scalar(@values) + $bl + $STALE_SIZE * ($self->num_txns - 1) + 3 * $self->byte_size;
unless ( $size == $header_var ) {
$self->storage->close;
DBM::Deep->_throw_error( "Unexpected size found ($size <-> $header_var)." );
}
$self->set_trans_loc( $header_fixed + scalar(@values) );
- $self->set_chains_loc( $header_fixed + scalar(@values) + $bitfield_len + $STALE_SIZE * ($self->num_txns - 1) );
+ $self->set_chains_loc( $header_fixed + scalar(@values) + $bl + $STALE_SIZE * ($self->num_txns - 1) );
return length($buffer) + length($buffer2);
}
sub blank_md5 { chr(0) x $_[0]->hash_size }
sub data_sector_size { $_[0]{data_sector_size} }
+# This is a calculated value
+sub txn_bitfield_len {
+ my $self = shift;
+ unless ( exists $self->{txn_bitfield_len} ) {
+ my $temp = ($self->num_txns) / 8;
+ if ( $temp > int( $temp ) ) {
+ $temp = int( $temp ) + 1;
+ }
+ $self->{txn_bitfield_len} = $temp;
+ }
+ return $self->{txn_bitfield_len};
+}
+
sub trans_id { $_[0]{trans_id} }
sub set_trans_id { $_[0]{trans_id} = $_[1] }