Parameterized the size of the signature + staleness counter so that incrementing...
rkinyon [Wed, 27 Dec 2006 04:18:44 +0000 (04:18 +0000)]
lib/DBM/Deep/Engine3.pm

index 7bddf2d..e052868 100644 (file)
@@ -816,16 +816,20 @@ sub engine { $_[0]{engine} }
 sub offset { $_[0]{offset} }
 sub type   { $_[0]{type} }
 
+sub base_size { 1 + 1 } # Size of sig + staleness counter
+
 sub free {
     my $self = shift;
 
-    $self->engine->storage->print_at( $self->offset, $self->engine->SIG_FREE );
+    my $e = $self->engine;
+
+    $e->storage->print_at( $self->offset, $e->SIG_FREE );
     # Skip staleness counter
-    $self->engine->storage->print_at( $self->offset + 1 + 1,
-        chr(0) x ($self->size - 2),
+    $e->storage->print_at( $self->offset + $self->base_size,
+        chr(0) x ($self->size - $self->base_size),
     );
 
-    $self->engine->_add_free_sector(
+    $e->_add_free_sector(
         $self->offset, $self->size,
     );
 
@@ -873,7 +877,7 @@ sub _init {
     my $engine = $self->engine;
 
     unless ( $self->offset ) {
-        my $data_section = $self->size - 3 - 1 * $engine->byte_size;
+        my $data_section = $self->size - $self->base_size - 1 * $engine->byte_size - 1;
 
         $self->{offset} = $engine->_request_sector( $self->size );
 
@@ -923,7 +927,7 @@ sub data_length {
     my $self = shift;
 
     my $buffer = $self->engine->storage->read_at(
-        $self->offset + 2 + $self->engine->byte_size, 1
+        $self->offset + $self->base_size + $self->engine->byte_size, 1
     );
 
     return unpack( $StP{1}, $buffer );
@@ -932,7 +936,7 @@ sub data_length {
 sub chain_loc {
     my $self = shift;
     my $chain_loc = $self->engine->storage->read_at(
-        $self->offset + 2, $self->engine->byte_size,
+        $self->offset + $self->base_size, $self->engine->byte_size,
     );
     return unpack( $StP{$self->engine->byte_size}, $chain_loc );
 }
@@ -945,7 +949,7 @@ sub data {
         my $chain_loc = $self->chain_loc;
 
         $data .= $self->engine->storage->read_at(
-            $self->offset + 2 + $self->engine->byte_size + 1, $self->data_length,
+            $self->offset + $self->base_size + $self->engine->byte_size + 1, $self->data_length,
         );
 
         last unless $chain_loc;
@@ -970,12 +974,12 @@ sub _init {
     my $engine = $self->engine;
 
     unless ( $self->offset ) {
-        my $leftover = $self->size - 3 - 1 * $engine->byte_size;
+        my $leftover = $self->size - $self->base_size - 1 * $engine->byte_size - 1;
 
         $self->{offset} = $engine->_request_sector( $self->size );
         $engine->storage->print_at( $self->offset, $self->type ); # Sector type
         # Skip staleness counter
-        $engine->storage->print_at( $self->offset + 1 + 1,
+        $engine->storage->print_at( $self->offset + $self->base_size,
             pack( $StP{$engine->byte_size}, 0 ),  # Chain loc
             pack( $StP{1}, $self->data_length ),  # Data length
             chr(0) x $leftover,                   # Zero-fill the rest
@@ -996,7 +1000,7 @@ sub _init {
 
     unless ( $self->offset ) {
         my $classname = Scalar::Util::blessed( delete $self->{data} );
-        my $leftover = $self->size - 2 - 2 * $engine->byte_size;
+        my $leftover = $self->size - $self->base_size - 2 * $engine->byte_size;
 
         my $class_offset = 0;
         if ( defined $classname ) {
@@ -1010,7 +1014,7 @@ sub _init {
         $self->{offset} = $engine->_request_sector( $self->size );
         $engine->storage->print_at( $self->offset, $self->type ); # Sector type
         # Skip staleness counter
-        $engine->storage->print_at( $self->offset + 1 + 1,
+        $engine->storage->print_at( $self->offset + $self->base_size,
             pack( $StP{$engine->byte_size}, 0 ),             # Index/BList loc
             pack( $StP{$engine->byte_size}, $class_offset ), # Classname loc
             chr(0) x $leftover,                              # Zero-fill the rest
@@ -1161,7 +1165,7 @@ sub get_blist_loc {
     my $self = shift;
 
     my $e = $self->engine;
-    my $blist_loc = $e->storage->read_at( $self->offset + 2, $e->byte_size );
+    my $blist_loc = $e->storage->read_at( $self->offset + $self->base_size, $e->byte_size );
     return unpack( $StP{$e->byte_size}, $blist_loc );
 }
 
@@ -1185,7 +1189,7 @@ sub get_bucket_list {
             key_md5 => $args->{key_md5},
         });
 
-        $engine->storage->print_at( $self->offset + 2,
+        $engine->storage->print_at( $self->offset + $self->base_size,
             pack( $StP{$engine->byte_size}, $blist->offset ),
         );
 
@@ -1203,7 +1207,7 @@ sub get_classname {
     my $self = shift;
 
     my $class_offset = $self->engine->storage->read_at(
-        $self->offset + 2 + 1 * $self->engine->byte_size, $self->engine->byte_size,
+        $self->offset + $self->base_size + 1 * $self->engine->byte_size, $self->engine->byte_size,
     );
     $class_offset = unpack ( $StP{$self->engine->byte_size}, $class_offset );
 
@@ -1248,7 +1252,7 @@ sub _init {
         $self->{offset} = $engine->_request_sector( $self->size );
         $engine->storage->print_at( $self->offset, $engine->SIG_BLIST ); # Sector type
         # Skip staleness counter
-        $engine->storage->print_at( $self->offset + 1 + 1,
+        $engine->storage->print_at( $self->offset + $self->base_size,
             chr(0) x $leftover, # Zero-fill the data
         );
     }
@@ -1260,8 +1264,6 @@ sub _init {
     return $self;
 }
 
-sub base_size { 1 + 1 } # Sig + recycled counter
-
 sub size {
     my $self = shift;
     unless ( $self->{size} ) {
@@ -1504,7 +1506,7 @@ sub _init {
         $self->{offset} = $engine->_request_sector( $self->size );
         $engine->storage->print_at( $self->offset, $engine->SIG_BLIST ); # Sector type
         # Skip staleness counter
-        $engine->storage->print_at( $self->offset + 1 + 1,
+        $engine->storage->print_at( $self->offset + $self->base_size,
             chr(0) x $leftover, # Zero-fill the data
         );
     }
@@ -1516,8 +1518,6 @@ sub _init {
     return $self;
 }
 
-sub base_size { 1 + 1 } # Sig + recycled counter
-
 sub size {
     my $self = shift;
     unless ( $self->{size} ) {
@@ -1527,16 +1527,5 @@ sub size {
     return $self->{size};
 }
 
-sub bucket_size {
-    my $self = shift;
-    unless ( $self->{bucket_size} ) {
-        my $e = $self->engine;
-        # Key + head (location) + transactions (location + staleness-counter)
-        my $location_size = $e->byte_size + $e->num_txns * ( $e->byte_size + 4 );
-        $self->{bucket_size} = $e->hash_size + $location_size;
-    }
-    return $self->{bucket_size};
-}
-
 1;
 __END__