[Bps-public-commit] r17054 - Prophet/trunk/lib/Prophet/Replica

jesse at bestpractical.com jesse at bestpractical.com
Sat Nov 29 16:55:40 EST 2008


Author: jesse
Date: Sat Nov 29 16:55:40 2008
New Revision: 17054

Modified:
   Prophet/trunk/lib/Prophet/Replica/prophet.pm

Log:
* don't slurp entire record history to get the latest version

Modified: Prophet/trunk/lib/Prophet/Replica/prophet.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Replica/prophet.pm	(original)
+++ Prophet/trunk/lib/Prophet/Replica/prophet.pm	Sat Nov 29 16:55:40 2008
@@ -452,15 +452,23 @@
     my $self = shift;
     my %args = validate( @_, { type => 1, uuid => 1 } );
 
-    # XXX TODO - we shouldn't compute all entries just to get the last
-    my @entries = $self->_read_record_index(
-        type => $args{type},
-        uuid => $args{uuid}
+    my $idx_filename = File::Spec->catfile(
+        $self->fs_root => $self->_record_index_filename( uuid => $args{uuid}, type => $args{type})
     );
-    return @{ $entries[-1] || [] };
+
+    open( my $index, "<:bytes", $idx_filename) || return undef;
+    seek($index, (0 - RECORD_INDEX_SIZE), 2) || return undef;
+    my $record;
+    read( $index, $record, RECORD_INDEX_SIZE) || return undef;
+    my ( $seq, $key ) = unpack( "NH40", $record ) ;
+    return ( $seq, $key );
 
 }
 
+
+
+
+
 sub _read_record_index {
     my $self = shift;
     my %args = validate( @_, { type => 1, uuid => 1 } );



More information about the Bps-public-commit mailing list