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

jesse jesse at bestpractical.com
Thu Apr 16 01:26:27 EDT 2009


The branch, master has been updated
       via  2b39c79c80b84fc21d088ae0eec698f8c8481b44 (commit)
       via  ab6ab2a6b69305b4eaa7234f57f848a66674e447 (commit)
      from  970510438405fd6ab36f2b57af796a96e1c57b39 (commit)

Summary of changes:
 lib/Prophet/CLI/Command/Mirror.pm    |    4 ++--
 lib/Prophet/CLI/MirrorCommand.pm     |    4 ++--
 lib/Prophet/ChangeSet.pm             |    2 +-
 lib/Prophet/FilesystemReplica.pm     |   27 ++++++++++++++-------------
 lib/Prophet/Replica/prophet_cache.pm |    3 ++-
 5 files changed, 21 insertions(+), 19 deletions(-)

- Log -----------------------------------------------------------------
commit ab6ab2a6b69305b4eaa7234f57f848a66674e447
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Thu Apr 16 13:19:17 2009 +0800

    refactoring toward being able to autocache replicas we mirror

diff --git a/lib/Prophet/CLI/Command/Mirror.pm b/lib/Prophet/CLI/Command/Mirror.pm
index bfc7574..c954271 100644
--- a/lib/Prophet/CLI/Command/Mirror.pm
+++ b/lib/Prophet/CLI/Command/Mirror.pm
@@ -23,8 +23,8 @@ sub run {
         exit 1;
     }
 
-    my $target = $self->get_mirror_for_source($source);
-    $self->sync_mirror_from_source( target=> $target, source => $source);
+    my $target = $self->get_cache_for_source($source);
+    $self->sync_cache_from_source( target=> $target, source => $source);
     print "\nDone.\n";
 }
 
diff --git a/lib/Prophet/CLI/MirrorCommand.pm b/lib/Prophet/CLI/MirrorCommand.pm
index bce57af..7ae7289 100644
--- a/lib/Prophet/CLI/MirrorCommand.pm
+++ b/lib/Prophet/CLI/MirrorCommand.pm
@@ -5,7 +5,7 @@ use Params::Validate ':all';
 
 
 
-sub get_mirror_for_source {
+sub get_cache_for_source {
     my $self = shift;
     my ($source) = validate_pos(@_,{isa => 'Prophet::Replica'});
     my $target = Prophet::Replica->get_handle( url => 'prophet_cache:' . $source->uuid , app_handle => $self->app_handle );
@@ -18,7 +18,7 @@ sub get_mirror_for_source {
     return $target;
 }
 
-sub sync_mirror_from_source {
+sub sync_cache_from_source {
     my $self = shift;
     my %args = validate(@_, { target => { isa => 'Prophet::Replica::prophet_cache'}, source => { isa => 'Prophet::Replica'}});
 
diff --git a/lib/Prophet/FilesystemReplica.pm b/lib/Prophet/FilesystemReplica.pm
index 4e6d1f8..7fc72b8 100644
--- a/lib/Prophet/FilesystemReplica.pm
+++ b/lib/Prophet/FilesystemReplica.pm
@@ -12,7 +12,7 @@ has lwp_useragent => (
     lazy => 1,
     default => sub {
         my $ua = LWP::UserAgent->new;
-        $ua->timeout(10);
+        $ua->timeout(60);
         $ua->conn_cache(LWP::ConnCache->new());
         return $ua;
     }
@@ -267,16 +267,17 @@ sub _get_changeset_index_handle {
 }
 
 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;
+    my $self = shift;
+    my $url  = shift;
+    my $response;
+    for ( 1 .. 4 ) {
+        $response = $self->lwp_useragent->get($url);
+        if ( $response->is_success ) {
+            return $response->decoded_content;
+        }
     }
-
+    warn "Could not fetch" . $url . " - " . $response->status_line;
+    return undef;
 }
           
       
diff --git a/lib/Prophet/Replica/prophet_cache.pm b/lib/Prophet/Replica/prophet_cache.pm
index 455643f..1ef4120 100644
--- a/lib/Prophet/Replica/prophet_cache.pm
+++ b/lib/Prophet/Replica/prophet_cache.pm
@@ -233,6 +233,7 @@ sub mirror_from {
                     -f File::Spec->catdir( $self->fs_root,
                         $self->changeset_cas->filename($key) ) );
 
+                #warn "we don't have it at ".File::Spec->catdir( $self->fs_root, $self->changeset_cas->filename($key) );
                 my $content = $source->_read_file( $source->changeset_cas->filename($key) );
                 utf8::decode($content) if utf8::is_utf8($content);
                 my $newkey = $self->changeset_cas->write(
@@ -243,7 +244,7 @@ sub mirror_from {
                 my $existsp = File::Spec->catdir( $self->fs_root,
                     $self->changeset_cas->filename($key) );
                 if ( !-f $existsp ) {
-                    die "AAA couldn't find changeset $key at $existsp";
+                    die "The mirror @{[$self->url]} appears to be incomplete. Perhaps a sync operation was aborted?\nCouldn't find changeset $key\n";
 
                 }
                 }

commit 2b39c79c80b84fc21d088ae0eec698f8c8481b44
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Thu Apr 16 13:25:58 2009 +0800

    Actually generate changesets that should hash the same on every replica

diff --git a/lib/Prophet/ChangeSet.pm b/lib/Prophet/ChangeSet.pm
index c16dfb8..bd55550 100644
--- a/lib/Prophet/ChangeSet.pm
+++ b/lib/Prophet/ChangeSet.pm
@@ -23,7 +23,7 @@ has created => (
 
 has source_uuid => (
     is  => 'rw',
-    isa => 'Str',
+    isa => 'Str|Undef',
 );
 
 has sequence_no => (
diff --git a/lib/Prophet/FilesystemReplica.pm b/lib/Prophet/FilesystemReplica.pm
index 7fc72b8..a211932 100644
--- a/lib/Prophet/FilesystemReplica.pm
+++ b/lib/Prophet/FilesystemReplica.pm
@@ -117,11 +117,11 @@ sub _write_changeset {
 
     my $hash_changeset = $changeset->as_hash;
 
-# XXX TODO: we should not be calculating the changeset's sha1 with the 'replica_uuid' and 'sequence_no' inside it. that makes every replica have a different hash for what should be the samechangeset.
+# XXX TODO: we should not be calculating the changeset's sha1 with the 'source_uuid' and 'sequence_no' inside it. that makes every replica have a different hash for what should be the samechangeset.
 
-    # These ttwo things should never actually get stored
+    # These two things should never actually get stored
     my $seqno = delete $hash_changeset->{'sequence_no'};
-    my $uuid  = delete $hash_changeset->{'replica_uuid'};
+    my $uuid  = delete $hash_changeset->{'source_uuid'};
 
     my $cas_key = $self->changeset_cas->write( $hash_changeset );
 

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



More information about the Bps-public-commit mailing list