From: rkinyon Date: Mon, 25 Dec 2006 03:41:36 +0000 (+0000) Subject: Removed notion of trans_ctr as an attribute - still having issues with multiple runni... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=41e27db355919fd7bf6d8bd8d8e468256df0e4dc;p=dbsrgits%2FDBM-Deep.git Removed notion of trans_ctr as an attribute - still having issues with multiple running txns --- diff --git a/lib/DBM/Deep/Engine3.pm b/lib/DBM/Deep/Engine3.pm index 90044b0..a64672e 100644 --- a/lib/DBM/Deep/Engine3.pm +++ b/lib/DBM/Deep/Engine3.pm @@ -331,10 +331,6 @@ sub begin_work { DBM::Deep->_throw_error( "Cannot begin_work - no available transactions" ); } - $self->set_trans_ctr( - $self->get_txn_staleness_counter( $self->trans_id ), - ); - return; } @@ -370,7 +366,6 @@ sub rollback { $slots[$self->trans_id] = 0; $self->write_txn_slots( @slots ); $self->inc_txn_staleness_counter( $self->trans_id ); - $self->set_trans_ctr( 0 ); $self->set_trans_id( 0 ); return 1; @@ -415,7 +410,6 @@ sub commit { $slots[$self->trans_id] = 0; $self->write_txn_slots( @slots ); $self->inc_txn_staleness_counter( $self->trans_id ); - $self->set_trans_ctr( 0 ); $self->set_trans_id( 0 ); return 1; @@ -446,18 +440,21 @@ sub get_running_txn_ids { sub get_txn_staleness_counter { my $self = shift; my ($trans_id) = @_; - return unpack( 'N', + my $x = unpack( 'N', $self->storage->read_at( - $self->trans_loc + 4 * ($trans_id - 1), 4, + $self->trans_loc + 4 * ($trans_id - 1), + 4, ) ); + print "$trans_id => $x\n"; + return $x; } sub inc_txn_staleness_counter { my $self = shift; my ($trans_id) = @_; $self->storage->print_at( - $self->trans_loc, + $self->trans_loc + 4 * ($trans_id - 1), pack( 'N', $self->get_txn_staleness_counter( $trans_id ) + 1 ), ); } @@ -511,7 +508,6 @@ sub clear_entries { $self->set_trans_loc( $header_fixed + 2 ); $self->set_chains_loc( $header_fixed + 2 + 4 + 4 * $self->num_txns ); - $self->set_trans_ctr( 0 ); return; } @@ -541,7 +537,6 @@ sub clear_entries { $self->set_trans_loc( $header_fixed + 2 ); $self->set_chains_loc( $header_fixed + 2 + 4 + 4 * $self->num_txns ); - $self->set_trans_ctr( 0 ); if ( @values < 2 || grep { !defined } @values ) { $self->storage->close; @@ -674,9 +669,6 @@ sub blank_md5 { chr(0) x $_[0]->hash_size } sub trans_id { $_[0]{trans_id} } sub set_trans_id { $_[0]{trans_id} = $_[1] } -sub trans_ctr { $_[0]{trans_ctr} } -sub set_trans_ctr { $_[0]{trans_ctr} = $_[1] } - sub trans_loc { $_[0]{trans_loc} } sub set_trans_loc { $_[0]{trans_loc} = $_[1] } @@ -1392,7 +1384,8 @@ sub get_data_location_for { my ($loc, $staleness) = unpack( $StP{$e->byte_size} . ' N', $buffer ); # We have found an entry that is old, so get rid of it - if ( $staleness != $e->get_txn_staleness_counter( $args->{trans_id} ) ) { + if ( $staleness != (my $s = $e->get_txn_staleness_counter( $args->{trans_id} ) ) ) { + print "Killing $args->{trans_id} ( $staleness <-> $s )\n"; $e->storage->print_at( $spot, pack( $StP{$e->byte_size} . ' N', (0) x 2 ), diff --git a/t/35_transaction_multiple.t b/t/35_transaction_multiple.t index 5236699..8b52af4 100644 --- a/t/35_transaction_multiple.t +++ b/t/35_transaction_multiple.t @@ -49,9 +49,9 @@ ok( !exists $db3->{bar}, "After DB1 set bar to foo, DB3's bar doesn't exist" ); $db2->begin_work; -is( $db1->{foo}, 'bar2', "After DB2 transaction begin, DB1's foo is bar2" ); -is( $db2->{foo}, 'bar', "After DB2 transaction begin, DB2's foo is bar" ); -is( $db3->{foo}, 'bar', "After DB2 transaction begin, DB3's foo is bar" ); +is( $db1->{foo}, 'bar2', "After DB2 transaction begin, DB1's foo is still bar2" ); +is( $db2->{foo}, 'bar', "After DB2 transaction begin, DB2's foo is still bar" ); +is( $db3->{foo}, 'bar', "After DB2 transaction begin, DB3's foo is still bar" ); __END__ ok( exists $db1->{bar}, "After DB2 transaction begin, DB1's bar exists" ); ok( !exists $db2->{bar}, "After DB2 transaction begin, DB2's bar doesn't exist" ); diff --git a/t/40_freespace.t b/t/40_freespace.t index 718502c..7bbaba1 100644 --- a/t/40_freespace.t +++ b/t/40_freespace.t @@ -25,3 +25,11 @@ cmp_ok( $size, '==', -s $filename, "Deleted space isn't released" ); $size = -s $filename; $db->{bar} = '2345'; cmp_ok( $size, '==', -s $filename, "Added a new key after a delete reuses space" ); + +__END__ +$db->{bar} = [ 1 .. 3 ]; + +$size = -s $filename; + +$db->{bar} = [ 3 .. 5 ]; +cmp_ok( $size, '==', -s $filename, "Overwritten arrays of the same number of keys reuses space" );