[Bps-public-commit] Prophet branch, master, updated. 5e9729174cd6244454b448cbc7eaac8e09959cc4

clkao at bestpractical.com clkao at bestpractical.com
Wed Apr 15 10:28:08 EDT 2009


The branch, master has been updated
       via  5e9729174cd6244454b448cbc7eaac8e09959cc4 (commit)
      from  d41d6f1ca237b23d5c494b9cf4b6c125ca4a85a0 (commit)

Summary of changes:
 lib/Prophet/Replica/prophet.pm |   37 +++++++++++++++++++++++++++++--------
 1 files changed, 29 insertions(+), 8 deletions(-)

- Log -----------------------------------------------------------------
commit 5e9729174cd6244454b448cbc7eaac8e09959cc4
Author: Chia-liang Kao <clkao at clkao.org>
Date:   Wed Apr 15 22:27:34 2009 +0800

    Make _last_record_index_entry use _read_file_range that works with
    non-file replica.

diff --git a/lib/Prophet/Replica/prophet.pm b/lib/Prophet/Replica/prophet.pm
index 1a75081..039a87f 100644
--- a/lib/Prophet/Replica/prophet.pm
+++ b/lib/Prophet/Replica/prophet.pm
@@ -514,21 +514,42 @@ sub _write_record_index_entry {
     close $record_index;
 }
 
+sub _read_file_range {
+    my $self = shift;
+    my %args = validate( @_, { path => 1, position => 1, whence => 1, length => 1 } );
+
+    if ($self->fs_root) {
+        my $f = File::Spec->catfile( $self->fs_root => $args{path} );
+        open( my $index, "<:bytes", $f) || return undef;
+        seek($index, $args{position}, $args{whence}) || return undef;
+        my $record;
+        read( $index, $record, $args{length}) || return undef;
+        return $record;
+    }
+    else {
+        # XXX: do range get if possible
+        my $content = $self->lwp_get( $self->url . "/" . $args{path} );
+        if ($args{whence} == 2) {
+            return substr($content, $args{position}, $args{length});
+        }
+        else {
+            die "unsupprted";
+        }
+    }
+}
+
 sub _last_record_index_entry {
     my $self = shift;
     my %args = ( type => undef, uuid => undef, @_);
 
-    my $idx_filename = File::Spec->catfile(
-        $self->fs_root => $self->_record_index_filename( uuid => $args{uuid}, type => $args{type})
-    );
+    my $idx_filename;
+    my $record = $self->_read_file_range(
+        path => $self->_record_index_filename( uuid => $args{uuid}, type => $args{type}),
+        position => (0 - RECORD_INDEX_SIZE), whence => 2,
+        length => RECORD_INDEX_SIZE ) || return undef;
 
-    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 {

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list