DBM::Deep->_throw_error( "Cannot begin_work within a transaction" );
}
- my @slots = $self->read_transaction_slots;
+ my @slots = $self->read_txn_slots;
for my $i ( 1 .. @slots ) {
next if $slots[$i];
$slots[$i] = 1;
$self->set_trans_id( $i );
last;
}
- $self->write_transaction_slots( @slots );
+ $self->write_txn_slots( @slots );
if ( !$self->trans_id ) {
DBM::Deep->_throw_error( "Cannot begin_work - no available transactions" );
$self->clear_entries;
- my @slots = $self->read_transaction_slots;
+ my @slots = $self->read_txn_slots;
$slots[$self->trans_id] = 0;
- $self->write_transaction_slots( @slots );
+ $self->write_txn_slots( @slots );
$self->set_trans_id( 0 );
return 1;
$self->clear_entries;
- my @slots = $self->read_transaction_slots;
+ my @slots = $self->read_txn_slots;
$slots[$self->trans_id] = 0;
- $self->write_transaction_slots( @slots );
+ $self->write_txn_slots( @slots );
$self->set_trans_id( 0 );
return 1;
}
-sub read_transaction_slots {
+sub read_txn_slots {
my $self = shift;
- return split '', unpack( "b32", $self->storage->read_at( $self->trans_loc, 4 ) );
+ return split '', unpack( 'b32',
+ $self->storage->read_at(
+ $self->trans_loc, 4,
+ )
+ );
}
-sub write_transaction_slots {
+sub write_txn_slots {
my $self = shift;
$self->storage->print_at( $self->trans_loc,
- pack( "b32", join('', @_) ),
+ pack( 'b32', join('', @_) ),
);
}
+sub get_running_txn_ids {
+ my $self = shift;
+ my @transactions = $self->read_txn_slots;
+ my @trans_ids = grep { $transactions[$_] } 0 .. $#transactions;
+}
+
sub get_entries {
my $self = shift;
return [ keys %{ $self->{entries}{$self->trans_id} ||= {} } ];
sub _write_file_header {
my $self = shift;
- my $header_var = 1 + 1 + 4 + 2 * $self->byte_size;
+ my $header_var = 1 + 1 + 4 + 4 * $self->num_txns + 2 * $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('N', 0 ), # Running transactions
+ pack('N', 0 ), # Transaction cctiveness bitfield
+ pack('N' . $self->num_txns, 0 ), # 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)
);
$self->set_trans_loc( $header_fixed + 2 );
- $self->set_chains_loc( $header_fixed + 6 );
+ $self->set_chains_loc( $header_fixed + 2 + 4 + 4 * $self->num_txns );
return;
}
my @values = unpack( 'C C', $buffer2 );
$self->set_trans_loc( $header_fixed + 2 );
- $self->set_chains_loc( $header_fixed + 6 );
+ $self->set_chains_loc( $header_fixed + 2 + 4 + 4 * $self->num_txns );
if ( @values < 2 || grep { !defined } @values ) {
$self->storage->close;
#XXX Add warnings if values weren't set right
@{$self}{qw(byte_size max_buckets)} = @values;
- my $header_var = 1 + 1 + 4 + 2 * $self->byte_size;
+ my $header_var = 1 + 1 + 4 + 4 * $self->num_txns + 2 * $self->byte_size;
unless ( $size eq $header_var ) {
$self->storage->close;
DBM::Deep->_throw_error( "Unexpected size found ($size <-> $header_var)." );
}
}
else {
- my @transactions = $self->engine->read_transaction_slots;
- my @trans_ids = grep { $transactions[$_] } 0 .. $#transactions;
+ my @trans_ids = $self->engine->get_running_txn_ids;
if ( $blist->{found} ) {
if ( @trans_ids ) {
my $old_value = $blist->get_data_for;
my $old_value = $location && $self->engine->_load_sector( $location );
if ( $self->engine->trans_id == 0 ) {
- my @transactions = $self->engine->read_transaction_slots;
- my @trans_ids = grep { $transactions[$_] } 0 .. $#transactions;
+ my @trans_ids = $self->engine->get_running_txn_ids;
if ( @trans_ids ) {
foreach my $other_trans_id ( @trans_ids ) {
next if $blist->get_data_location_for({ trans_id => $other_trans_id, allow_head => 0 });