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

jesse jesse at bestpractical.com
Fri Apr 10 12:56:23 EDT 2009


The branch, master has been updated
       via  e3178fa380b2fab7e10ae12acdd7f9ac7c9932d0 (commit)
       via  54a8697969f4e0dffd16be3881f75de19860df42 (commit)
       via  29b2b6b50ad662a03ab7baffe69377c9530909af (commit)
      from  031008e5e1ab1874f9920efb133ec192dacd300e (commit)

Summary of changes:
 Makefile.PL                    |    2 +-
 lib/Prophet/Replica/prophet.pm |   54 +++++++++++++++++++++++++++++----------
 2 files changed, 41 insertions(+), 15 deletions(-)

- Log -----------------------------------------------------------------
commit 29b2b6b50ad662a03ab7baffe69377c9530909af
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Fri Apr 10 12:25:21 2009 -0400

    sometimes LWP gives us back a binary file marked as utf8 data. we can't have that

diff --git a/lib/Prophet/Replica/prophet.pm b/lib/Prophet/Replica/prophet.pm
index a1708ba..d18b440 100644
--- a/lib/Prophet/Replica/prophet.pm
+++ b/lib/Prophet/Replica/prophet.pm
@@ -505,6 +505,7 @@ sub _read_record_index {
 
     my $index = $self->_read_file($idx_filename);
     return undef unless $index;
+    utf8::decode($index) if utf8::is_utf8($index); # When we get data from LWP it sometimes ends up with a charset. that is wrong here
 
     # XXX TODO THIS CODE IS HACKY AND SHOULD BE SHOT;
     my $count = length($index) / RECORD_INDEX_SIZE;
@@ -685,6 +686,7 @@ sub _read_changeset_index {
     my $self = shift;
     $self->log_debug("Reading changeset index file");
     my $chgidx = $self->_read_file( $self->changeset_index );
+    utf8::decode($chgidx) if utf8::is_utf8($chgidx); # When we get data from LWP it sometimes ends up with a charset. that is wrong here
     return \$chgidx;
 }
 

commit 54a8697969f4e0dffd16be3881f75de19860df42
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Fri Apr 10 12:26:37 2009 -0400

    Minor refactoring of our pack/unpack code for record and changeset indexes

diff --git a/lib/Prophet/Replica/prophet.pm b/lib/Prophet/Replica/prophet.pm
index d18b440..2257aae 100644
--- a/lib/Prophet/Replica/prophet.pm
+++ b/lib/Prophet/Replica/prophet.pm
@@ -507,12 +507,11 @@ sub _read_record_index {
     return undef unless $index;
     utf8::decode($index) if utf8::is_utf8($index); # When we get data from LWP it sometimes ends up with a charset. that is wrong here
 
-    # XXX TODO THIS CODE IS HACKY AND SHOULD BE SHOT;
     my $count = length($index) / RECORD_INDEX_SIZE;
     my @entries;
-    for my $offset ( 0 .. ( $count - 1 ) ) {
+    for my $record ( 1 .. $count ) {
         my ( $seq, $key ) = unpack( 'NH40',
-            substr( $index, ($offset) * RECORD_INDEX_SIZE, RECORD_INDEX_SIZE )
+            substr( $index, ($record - 1) * RECORD_INDEX_SIZE, RECORD_INDEX_SIZE )
         );
         push @entries, [ $seq => $key ];
     }
@@ -597,29 +596,27 @@ sub _write_changeset {
         cas_dir => $self->changeset_cas_dir
     );
 
-    my $packed_cas_key = pack( 'H40', $cas_key );
-
-    my $changeset_index_line = pack( 'Na16Na20',
+    my $changeset_index_line = pack( 'Na16NH40',
         $seqno,
         Data::UUID->new->from_string( $changeset->original_source_uuid ),
         $changeset->original_sequence_no,
-        $packed_cas_key );
+        $cas_key );
+
     print $fh $changeset_index_line || die $!;
 
 }
 
+
 use constant CHG_RECORD_SIZE => ( 4 + 16 + 4 + 20 );
 
 sub _get_changeset_index_entry {
     my $self = shift;
     my %args = validate( @_, { sequence_no => 1, index_file => 1 } );
-
     my $chgidx = $args{index_file};
+
     my $rev    = $args{'sequence_no'};
-    my $index_record
-        = substr( $$chgidx, ( $rev - 1 ) * CHG_RECORD_SIZE, CHG_RECORD_SIZE );
-    my ( $seq, $orig_uuid, $orig_seq, $key )
-        = unpack( 'Na16NH40', $index_record );
+    my $index_record = substr( $$chgidx, ( $rev - 1 ) * CHG_RECORD_SIZE, CHG_RECORD_SIZE );
+    my ( $seq, $orig_uuid, $orig_seq, $key ) = unpack( 'Na16NH40', $index_record );
 
     $self->log_debug( join( ",", ( $seq, $orig_uuid, $orig_seq, $key ) ) );
     $orig_uuid = Data::UUID->new->to_string($orig_uuid);

commit e3178fa380b2fab7e10ae12acdd7f9ac7c9932d0
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Fri Apr 10 12:55:54 2009 -0400

    Switch from LWP::Simple to LWP so we can have a connection cache for great perf improvement

diff --git a/Makefile.PL b/Makefile.PL
index 563bf74..351366b 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -9,7 +9,7 @@ requires('Params::Validate');
 requires('IPC::Run3');
 requires('Data::UUID');
 requires('Digest::SHA');
-requires('LWP::Simple');     # Part of lib-www-perl
+requires('LWP::UserAgent');     #  LWP::ConnCache too
 requires('URI');
 requires('HTTP::Date');
 requires( 'JSON' => '2.00' );
diff --git a/lib/Prophet/Replica/prophet.pm b/lib/Prophet/Replica/prophet.pm
index 2257aae..6459090 100644
--- a/lib/Prophet/Replica/prophet.pm
+++ b/lib/Prophet/Replica/prophet.pm
@@ -2,7 +2,8 @@ package Prophet::Replica::prophet;
 use Any::Moose;
 extends 'Prophet::Replica';
 use Params::Validate qw(:all);
-use LWP::Simple ();
+use LWP::UserAgent;
+use LWP::ConnCache;
 use File::Spec  ();
 use File::Path;
 use Cwd ();
@@ -70,6 +71,19 @@ has '+resolution_db_handle' => (
     },
 );
 
+has lwp_useragent => (
+    isa => 'LWP::UserAgent',
+    is => 'ro',
+    lazy => 1,
+    default => sub {
+        my $ua = LWP::UserAgent->new;
+        $ua->timeout(10);
+        $ua->conn_cache(LWP::ConnCache->new());
+        return $ua;
+    }
+    );
+
+
 use constant scheme   => 'prophet';
 use constant cas_root => 'cas';
 use constant record_cas_dir =>
@@ -828,7 +842,7 @@ sub _read_file {
                 File::Spec->catfile( $self->fs_root => $file ) );
         };
     } else {    # http replica
-        return LWP::Simple::get( $self->url . "/" . $file );
+        return $self->lwp_get( $self->url . "/" . $file );
     }
 
 }
@@ -1094,6 +1108,19 @@ sub write_userdata {
     );
 }
 
+sub lwp_get {
+    my $self     = shift;
+    my $url      = shift;
+    my $response = $self->lwp_useragent->get($url);
+    if ( $response->is_success ) {
+        return $response->decoded_content;
+    } else {
+        warn "Request FAILED ". $url . " ". $response->status_line;
+        return undef;
+    }
+
+}
+
 __PACKAGE__->meta->make_immutable();
 no Any::Moose;
 

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



More information about the Bps-public-commit mailing list