DBM-Deep
view release on metacpan or search on metacpan
utils/lib/DBM/Deep/10002.pm view on Meta::CPAN
$self->trans_loc, $bl,
)
);
}
sub write_txn_slots {
my $self = shift;
my $num_bits = $self->txn_bitfield_len * 8;
$self->storage->print_at( $self->trans_loc,
pack( 'b'.$num_bits, join('', @_) ),
);
}
sub get_running_txn_ids {
my $self = shift;
my @transactions = $self->read_txn_slots;
my @trans_ids = map { $_+1} grep { $transactions[$_] } 0 .. $#transactions;
}
sub get_txn_staleness_counter {
my $self = shift;
my ($trans_id) = @_;
# Hardcode staleness of 0 for the HEAD
return 0 unless $trans_id;
return unpack( $StP{$STALE_SIZE},
$self->storage->read_at(
$self->trans_loc + 4 + $STALE_SIZE * ($trans_id - 1),
4,
)
);
}
sub inc_txn_staleness_counter {
my $self = shift;
my ($trans_id) = @_;
# Hardcode staleness of 0 for the HEAD
return unless $trans_id;
$self->storage->print_at(
$self->trans_loc + 4 + $STALE_SIZE * ($trans_id - 1),
pack( $StP{$STALE_SIZE}, $self->get_txn_staleness_counter( $trans_id ) + 1 ),
);
}
sub get_entries {
my $self = shift;
return [ keys %{ $self->{entries}{$self->trans_id} ||= {} } ];
}
sub add_entry {
my $self = shift;
my ($trans_id, $loc) = @_;
$self->{entries}{$trans_id} ||= {};
$self->{entries}{$trans_id}{$loc} = undef;
}
# If the buckets are being relocated because of a reindexing, the entries
# mechanism needs to be made aware of it.
sub reindex_entry {
my $self = shift;
my ($old_loc, $new_loc) = @_;
TRANS:
while ( my ($trans_id, $locs) = each %{ $self->{entries} } ) {
foreach my $orig_loc ( keys %{ $locs } ) {
if ( $orig_loc == $old_loc ) {
delete $locs->{orig_loc};
$locs->{$new_loc} = undef;
next TRANS;
}
}
}
}
sub clear_entries {
my $self = shift;
delete $self->{entries}{$self->trans_id};
}
################################################################################
{
my $header_fixed = length( SIG_FILE ) + 1 + 4 + 4;
my $this_file_version = 2;
sub _write_file_header {
my $self = shift;
my $nt = $self->num_txns;
my $bl = $self->txn_bitfield_len;
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 );
$self->storage->print_at( $loc,
SIG_FILE,
SIG_HEADER,
pack('N', $this_file_version), # At this point, we're at 9 bytes
pack('N', $header_var), # header size
# --- Above is $header_fixed. Below is $header_var
pack('C', $self->byte_size),
# These shenanigans are to allow a 256 within a C
pack('C', $self->max_buckets - 1),
pack('C', $self->data_sector_size - 1),
pack('C', $nt),
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)
pack($StP{$self->byte_size}, 0), # Start of free chain (index size)
);
#XXX Set these less fragilely
$self->set_trans_loc( $header_fixed + 4 );
( run in 0.616 second using v1.01-cache-2.11-cpan-71847e10f99 )