hash_size => 16, # In bytes
hash_chars => 256, # Number of chars the algorithm uses per byte
max_buckets => 16,
- num_txns => 16, # HEAD plus 15 running txns
- trans_id => 0, # Default to the HEAD
+ num_txns => 2, # HEAD plus 1 additional transaction for importing
+ trans_id => 0, # Default to the HEAD
entries => {}, # This is the list of entries for transactions
storage => undef,
sub _write_file_header {
my $self = shift;
- my $header_var = 1 + 1 + 4 + 4 * $self->num_txns + 3 * $self->byte_size;
+ my $header_var = 1 + 1 + 1 + 4 + 4 * $self->num_txns + 3 * $self->byte_size;
my $loc = $self->storage->request_space( $header_fixed + $header_var );
# --- Above is $header_fixed. Below is $header_var
pack('C', $self->byte_size),
pack('C', $self->max_buckets),
+ pack('C', $self->num_txns),
pack('N', 0 ), # Transaction activeness bitfield
pack('N' . $self->num_txns, 0 x $self->num_txns ), # 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 (index size)
);
- $self->set_trans_loc( $header_fixed + 2 );
- $self->set_chains_loc( $header_fixed + 2 + 4 + 4 * $self->num_txns );
+ $self->set_trans_loc( $header_fixed + 3 );
+ $self->set_chains_loc( $header_fixed + 3 + 4 + 4 * $self->num_txns );
return;
}
}
my $buffer2 = $self->storage->read_at( undef, $size );
- my @values = unpack( 'C C', $buffer2 );
+ my @values = unpack( 'C C C', $buffer2 );
- $self->set_trans_loc( $header_fixed + 2 );
- $self->set_chains_loc( $header_fixed + 2 + 4 + 4 * $self->num_txns );
-
- if ( @values < 2 || grep { !defined } @values ) {
+ if ( @values != 3 || grep { !defined } @values ) {
$self->storage->close;
DBM::Deep->_throw_error("Corrupted file - bad header");
}
+ $self->set_trans_loc( $header_fixed + scalar(@values) );
+ $self->set_chains_loc( $header_fixed + scalar(@values) + 4 + 4 * $self->num_txns );
+
#XXX Add warnings if values weren't set right
- @{$self}{qw(byte_size max_buckets)} = @values;
+ @{$self}{qw(byte_size max_buckets num_txns)} = @values;
- my $header_var = 1 + 1 + 4 + 4 * $self->num_txns + 3 * $self->byte_size;
+ my $header_var = scalar(@values) + 4 + 4 * $self->num_txns + 3 * $self->byte_size;
unless ( $size == $header_var ) {
$self->storage->close;
DBM::Deep->_throw_error( "Unexpected size found ($size <-> $header_var)." );