From: rkinyon Date: Wed, 17 Jan 2007 15:32:40 +0000 (+0000) Subject: Converted to using only 2 transactions by default and added the num_txns to the header X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=36d630c696ea4dc4960ff98ed85d24d8f6859ff9;p=dbsrgits%2FDBM-Deep.git Converted to using only 2 transactions by default and added the num_txns to the header --- diff --git a/lib/DBM/Deep.pm b/lib/DBM/Deep.pm index 4031271..a203c6e 100644 --- a/lib/DBM/Deep.pm +++ b/lib/DBM/Deep.pm @@ -274,7 +274,12 @@ sub optimize { my $db_temp = DBM::Deep->new( file => $self->_storage->{file} . '.tmp', - type => $self->_type + type => $self->_type, + + # Bring over all the parameters that we need to bring over + num_txns => $self->_engine->num_txns, + byte_size => $self->_engine->byte_size, + max_buckets => $self->_engine->max_buckets, ); $self->lock(); @@ -311,8 +316,11 @@ sub optimize { $self->unlock(); $self->_storage->close; + $self->_storage->open; + $self->lock(); $self->_engine->setup_fh( $self ); + $self->unlock(); return 1; } diff --git a/lib/DBM/Deep/Engine.pm b/lib/DBM/Deep/Engine.pm index 26c3000..0381bf1 100644 --- a/lib/DBM/Deep/Engine.pm +++ b/lib/DBM/Deep/Engine.pm @@ -50,8 +50,8 @@ sub new { 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, @@ -534,7 +534,7 @@ sub clear_entries { 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 ); @@ -546,6 +546,7 @@ sub clear_entries { # --- 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) @@ -553,8 +554,8 @@ sub clear_entries { 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; } @@ -580,20 +581,20 @@ sub clear_entries { } 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)." ); diff --git a/t/33_transactions.t b/t/33_transactions.t index 5fb61fc..672d226 100644 --- a/t/33_transactions.t +++ b/t/33_transactions.t @@ -10,12 +10,14 @@ my $db1 = DBM::Deep->new( file => $filename, locking => 1, autoflush => 1, + num_txns => 16, ); my $db2 = DBM::Deep->new( file => $filename, locking => 1, autoflush => 1, + num_txns => 16, ); $db1->{x} = 'y'; diff --git a/t/34_transaction_arrays.t b/t/34_transaction_arrays.t index ea50810..19503b0 100644 --- a/t/34_transaction_arrays.t +++ b/t/34_transaction_arrays.t @@ -10,6 +10,7 @@ my $db1 = DBM::Deep->new( file => $filename, locking => 1, autoflush => 1, + num_txns => 16, type => DBM::Deep->TYPE_ARRAY, ); @@ -17,6 +18,7 @@ my $db2 = DBM::Deep->new( file => $filename, locking => 1, autoflush => 1, + num_txns => 16, type => DBM::Deep->TYPE_ARRAY, ); diff --git a/t/35_transaction_multiple.t b/t/35_transaction_multiple.t index e283a63..901b5c0 100644 --- a/t/35_transaction_multiple.t +++ b/t/35_transaction_multiple.t @@ -10,18 +10,21 @@ my $db1 = DBM::Deep->new( file => $filename, locking => 1, autoflush => 1, + num_txns => 16, ); my $db2 = DBM::Deep->new( file => $filename, locking => 1, autoflush => 1, + num_txns => 16, ); my $db3 = DBM::Deep->new( file => $filename, locking => 1, autoflush => 1, + num_txns => 16, ); $db1->{foo} = 'bar'; diff --git a/t/36_transaction_deep.todo b/t/36_transaction_deep.todo index 818666e..0458f58 100644 --- a/t/36_transaction_deep.todo +++ b/t/36_transaction_deep.todo @@ -10,6 +10,7 @@ my $db = DBM::Deep->new( file => $filename, locking => 1, autoflush => 1, + num_txns => 16, ); my $outer = { a => 'b' }; diff --git a/t/38_transaction_add_item.todo b/t/38_transaction_add_item.todo index 7c2ae90..4306e1b 100644 --- a/t/38_transaction_add_item.todo +++ b/t/38_transaction_add_item.todo @@ -10,6 +10,7 @@ my $db = DBM::Deep->new( file => $filename, locking => 1, autoflush => 1, + num_txns => 16, ); { diff --git a/t/41_transaction_multilevel.t b/t/41_transaction_multilevel.t index 6874dc4..aa2a959 100644 --- a/t/41_transaction_multilevel.t +++ b/t/41_transaction_multilevel.t @@ -10,12 +10,14 @@ my $db1 = DBM::Deep->new( file => $filename, locking => 1, autoflush => 1, + num_txns => 16, ); my $db2 = DBM::Deep->new( file => $filename, locking => 1, autoflush => 1, + num_txns => 16, ); $db1->{x} = { foo => 'y' }; diff --git a/t/42_transaction_indexsector.t b/t/42_transaction_indexsector.t index 29ae607..99433cb 100644 --- a/t/42_transaction_indexsector.t +++ b/t/42_transaction_indexsector.t @@ -18,12 +18,14 @@ use_ok( 'DBM::Deep' ); file => $filename, locking => 1, autoflush => 1, + num_txns => 16, ); my $db2 = DBM::Deep->new( file => $filename, locking => 1, autoflush => 1, + num_txns => 16, ); $db1->{x} = 'y'; @@ -56,12 +58,14 @@ use_ok( 'DBM::Deep' ); file => $filename, locking => 1, autoflush => 1, + num_txns => 16, ); my $db2 = DBM::Deep->new( file => $filename, locking => 1, autoflush => 1, + num_txns => 16, ); $db1->{x} = 'y';