sub SIG_BLIST () { 'B' }
sub SIG_FREE () { 'F' }
sub SIG_SIZE () { 1 }
-sub STALE_SIZE () { 1 }
+
+my $STALE_SIZE = 2;
# Please refer to the pack() documentation for further information
my %StP = (
+ $self->hash_size
+ $self->byte_size
+ $self->byte_size
- + ($self->trans_id - 1) * ( $self->byte_size + 4 );
+ + ($self->trans_id - 1) * ( $self->byte_size + $STALE_SIZE );
my $data_loc = $self->storage->read_at( $read_loc, $self->byte_size );
$data_loc = unpack( $StP{$self->byte_size}, $data_loc );
my $head_loc = $self->storage->read_at( $base, $self->byte_size );
$head_loc = unpack( $StP{$self->byte_size}, $head_loc );
- my $spot = $base + $self->byte_size + ($self->trans_id - 1) * ( $self->byte_size + 4 );
+ my $spot = $base + $self->byte_size + ($self->trans_id - 1) * ( $self->byte_size + $STALE_SIZE );
my $trans_loc = $self->storage->read_at(
$spot, $self->byte_size,
);
$self->storage->print_at( $base, $trans_loc );
$self->storage->print_at(
$spot,
- pack( $StP{$self->byte_size} . ' N', (0) x 2 ),
+ pack( $StP{$self->byte_size} . ' ' . $StP{$STALE_SIZE}, (0) x 2 ),
);
if ( $head_loc > 1 ) {
# Hardcode staleness of 0 for the HEAD
return 0 unless $trans_id;
- return unpack( 'N',
+ return unpack( $StP{$STALE_SIZE},
$self->storage->read_at(
- $self->trans_loc + 4 + 4 * ($trans_id - 1),
+ $self->trans_loc + 4 + $STALE_SIZE * ($trans_id - 1),
4,
)
);
return unless $trans_id;
$self->storage->print_at(
- $self->trans_loc + 4 + 4 * ($trans_id - 1),
- pack( 'N', $self->get_txn_staleness_counter( $trans_id ) + 1 ),
+ $self->trans_loc + 4 + $STALE_SIZE * ($trans_id - 1),
+ pack( $StP{$STALE_SIZE}, $self->get_txn_staleness_counter( $trans_id ) + 1 ),
);
}
my $nt = $self->num_txns;
- my $header_var = 1 + 1 + 1 + 1 + 4 + 4 * ($nt - 1) + 3 * $self->byte_size;
+ my $header_var = 1 + 1 + 1 + 1 + 4 + $STALE_SIZE * ($nt - 1) + 3 * $self->byte_size;
my $loc = $self->storage->request_space( $header_fixed + $header_var );
pack('C', $nt),
#XXX This is a problem - it limits everything to 32 transactions
pack('N', 0 ), # Transaction activeness bitfield
- pack('N' . ($nt-1), 0 x ($nt-1) ), # Transaction staleness counters
+ 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)
pack($StP{$self->byte_size}, 0), # Start of free chain (index size)
#XXX Set these less fragilely
$self->set_trans_loc( $header_fixed + 4 );
- $self->set_chains_loc( $header_fixed + 4 + 4 + 4 * ($nt-1) );
+ $self->set_chains_loc( $header_fixed + 4 + 4 + $STALE_SIZE * ($nt-1) );
return;
}
$self->{max_buckets} += 1;
$self->{data_sector_size} += 1;
- my $header_var = scalar(@values) + 4 + 4 * ($self->num_txns - 1) + 3 * $self->byte_size;
+ my $header_var = scalar(@values) + 4 + $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) + 4 + 4 * ($self->num_txns - 1) );
+ $self->set_chains_loc( $header_fixed + scalar(@values) + 4 + $STALE_SIZE * ($self->num_txns - 1) );
return length($buffer) + length($buffer2);
}
# Increment staleness.
# XXX Can this increment+modulo be done by "&= 0x1" ?
- my $staleness = unpack( $StP{STALE_SIZE()}, $storage->read_at( $offset + SIG_SIZE, STALE_SIZE ) );
- $staleness = ($staleness + 1 ) % ( 2 ** ( 8 * STALE_SIZE ) );
- $storage->print_at( $offset + SIG_SIZE, pack( $StP{STALE_SIZE()}, $staleness ) );
+ my $staleness = unpack( $StP{$STALE_SIZE}, $storage->read_at( $offset + SIG_SIZE, $STALE_SIZE ) );
+ $staleness = ($staleness + 1 ) % ( 2 ** ( 8 * $STALE_SIZE ) );
+ $storage->print_at( $offset + SIG_SIZE, pack( $StP{$STALE_SIZE}, $staleness ) );
my $old_head = $storage->read_at( $self->chains_loc + $chains_offset, $self->byte_size );
);
# Record the old head in the new sector after the signature and staleness counter
- $storage->print_at( $offset + SIG_SIZE + STALE_SIZE, $old_head );
+ $storage->print_at( $offset + SIG_SIZE + $STALE_SIZE, $old_head );
}
sub _request_blist_sector { shift->_request_sector( 0, @_ ) }
}
# Read the new head after the signature and the staleness counter
- my $new_head = $self->storage->read_at( $loc + SIG_SIZE + STALE_SIZE, $self->byte_size );
+ my $new_head = $self->storage->read_at( $loc + SIG_SIZE + $STALE_SIZE, $self->byte_size );
$self->storage->print_at( $self->chains_loc + $chains_offset, $new_head );
$self->storage->print_at(
- $loc + SIG_SIZE + STALE_SIZE,
+ $loc + SIG_SIZE + $STALE_SIZE,
pack( $StP{$self->byte_size}, 0 ),
);
sub base_size {
my $self = shift;
- return $self->engine->SIG_SIZE + $self->engine->STALE_SIZE;
+ return $self->engine->SIG_SIZE + $STALE_SIZE;
}
sub free {
}
$self->{staleness} = unpack(
- $StP{$e->STALE_SIZE},
- $e->storage->read_at( $self->offset + $e->SIG_SIZE, $e->STALE_SIZE ),
+ $StP{$STALE_SIZE},
+ $e->storage->read_at( $self->offset + $e->SIG_SIZE, $STALE_SIZE ),
);
return;
my $self = shift;
unless ( $self->{bucket_size} ) {
my $e = $self->engine;
- #XXX Convert the 4 to STALE_SIZE()
# Key + head (location) + transactions (location + staleness-counter)
- my $location_size = $e->byte_size + $e->byte_size + ($e->num_txns - 1) * ($e->byte_size + 4);
+ my $location_size = $e->byte_size + $e->byte_size + ($e->num_txns - 1) * ($e->byte_size + $STALE_SIZE);
$self->{bucket_size} = $e->hash_size + $location_size;
}
return $self->{bucket_size};
+ $engine->hash_size
+ $engine->byte_size;
- #XXX Convert the 4 to STALE_SIZE()
if ( $args->{trans_id} ) {
- $loc += $engine->byte_size + ($args->{trans_id} - 1) * ( $engine->byte_size + 4 );
+ $loc += $engine->byte_size + ($args->{trans_id} - 1) * ( $engine->byte_size + $STALE_SIZE );
$engine->storage->print_at( $loc,
pack( $StP{$engine->byte_size}, $args->{value}->offset ),
- pack( 'N', $engine->get_txn_staleness_counter( $args->{trans_id} ) ),
+ pack( $StP{$STALE_SIZE}, $engine->get_txn_staleness_counter( $args->{trans_id} ) ),
);
}
else {
+ $engine->hash_size
+ $engine->byte_size;
- #XXX Convert the 4 to STALE_SIZE()
if ( $args->{trans_id} ) {
- $loc += $engine->byte_size + ($args->{trans_id} - 1) * ( $engine->byte_size + 4 );
+ $loc += $engine->byte_size + ($args->{trans_id} - 1) * ( $engine->byte_size + $STALE_SIZE );
$engine->storage->print_at( $loc,
pack( $StP{$engine->byte_size}, 1 ), # 1 is the marker for deleted
- pack( 'N', $engine->get_txn_staleness_counter( $args->{trans_id} ) ),
+ pack( $StP{$STALE_SIZE}, $engine->get_txn_staleness_counter( $args->{trans_id} ) ),
);
}
else {
+ $e->hash_size
+ $e->byte_size;
- #XXX Convert the 4 to STALE_SIZE()
if ( $args->{trans_id} ) {
- $spot += $e->byte_size + ($args->{trans_id} - 1) * ( $e->byte_size + 4 );
+ $spot += $e->byte_size + ($args->{trans_id} - 1) * ( $e->byte_size + $STALE_SIZE );
}
- #XXX Convert the 4 to STALE_SIZE()
my $buffer = $e->storage->read_at(
$spot,
- $e->byte_size + 4,
+ $e->byte_size + $STALE_SIZE,
);
- my ($loc, $staleness) = unpack( $StP{$e->byte_size} . ' N', $buffer );
+ my ($loc, $staleness) = unpack( $StP{$e->byte_size} . ' ' . $StP{$STALE_SIZE}, $buffer );
if ( $args->{trans_id} ) {
# We have found an entry that is old, so get rid of it
if ( $staleness != (my $s = $e->get_txn_staleness_counter( $args->{trans_id} ) ) ) {
$e->storage->print_at(
$spot,
- pack( $StP{$e->byte_size} . ' N', (0) x 2 ),
+ pack( $StP{$e->byte_size} . ' ' . $StP{$STALE_SIZE}, (0) x 2 ),
);
$loc = 0;
}