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

clkao at bestpractical.com clkao at bestpractical.com
Wed Apr 15 06:33:54 EDT 2009


The branch, master has been updated
       via  eeeea47cffa69a8524f0c4ec0a03110d2f95bf00 (commit)
       via  9e05474308358e49a58c1d51285854e6744edd06 (commit)
       via  b15fd7c1a2561043a0180c8e06ab608ef56a18b7 (commit)
       via  52b3ddbd4600d9c47e42b39eae11a8e9a1fc3592 (commit)
      from  de1eab022a1a740376c1f36ce4f6ae66b7c423d0 (commit)

Summary of changes:
 lib/Prophet/ContentAddressedStore.pm |   42 ++++++++++++++++++++
 lib/Prophet/FilesystemReplica.pm     |   14 +++++++
 lib/Prophet/Replica/cached.pm        |   36 +++++++++++++++++
 lib/Prophet/Replica/prophet.pm       |   72 +++++++++++++++------------------
 lib/Prophet/Util.pm                  |    9 ++++-
 5 files changed, 133 insertions(+), 40 deletions(-)
 create mode 100644 lib/Prophet/ContentAddressedStore.pm
 create mode 100644 lib/Prophet/FilesystemReplica.pm
 create mode 100644 lib/Prophet/Replica/cached.pm

- Log -----------------------------------------------------------------
commit 52b3ddbd4600d9c47e42b39eae11a8e9a1fc3592
Author: Chia-liang Kao <clkao at clkao.org>
Date:   Wed Apr 15 17:29:20 2009 +0800

    Make slurp error more verbose

diff --git a/lib/Prophet/Util.pm b/lib/Prophet/Util.pm
index 272fcdb..fb7c00a 100644
--- a/lib/Prophet/Util.pm
+++ b/lib/Prophet/Util.pm
@@ -30,7 +30,7 @@ depending on the context.
 sub slurp {
     my $self = shift;
     my $abspath = shift;
-    open (my $fh, "<", "$abspath") || die $!;
+    open (my $fh, "<", "$abspath") || die "$abspath: $!";
 
     my @lines = <$fh>;
     close $fh;

commit b15fd7c1a2561043a0180c8e06ab608ef56a18b7
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Wed Apr 15 17:46:02 2009 +0800

    checkpoint for switch from subethaedit to gitjour

diff --git a/lib/Prophet/ContentAddressedStore.pm b/lib/Prophet/ContentAddressedStore.pm
new file mode 100644
index 0000000..4b661b6
--- /dev/null
+++ b/lib/Prophet/ContentAddressedStore.pm
@@ -0,0 +1,28 @@
+package Prophet::ContentAddressedStore;
+
+use Any::Moose;
+
+has root => (
+    isa => 'Str',
+);
+
+
+sub write {
+    my ($self, $content) = @_;
+    $content = $$content if ref($content) eq 'SCALAR';
+    $content = to_json( $content,
+            { canonical => 1, pretty => 0, utf8 => 1 } )
+        if ref($content);
+    my $fingerprint      = sha1_hex($content);
+    my $content_filename = File::Spec->catfile(
+        $self->root => $self->_hashed_dir_name($fingerprint) );
+
+    Prophet::Util->write_file( file => $content_filename, content => $content);
+
+    return $fingerprint;
+}
+
+
+__PACKAGE__->meta->make_immutable();
+no Any::Moose;
+1;
diff --git a/lib/Prophet/FilesystemReplica.pm b/lib/Prophet/FilesystemReplica.pm
new file mode 100644
index 0000000..15191a8
--- /dev/null
+++ b/lib/Prophet/FilesystemReplica.pm
@@ -0,0 +1,14 @@
+package Prophet::FilesystemReplica;
+use Any::Moose 'Role';
+use File::Spec;use Params::Validate qw(:all);
+use LWP::UserAgent;
+use LWP::ConnCache;
+use Prophet::Util;
+      
+      
+
+          
+      
+      
+
+1;
\ No newline at end of file
diff --git a/lib/Prophet/Replica/cached.pm b/lib/Prophet/Replica/cached.pm
new file mode 100644
index 0000000..872ae25
--- /dev/null
+++ b/lib/Prophet/Replica/cached.pm
@@ -0,0 +1,36 @@
+package Prophet::Replica::cached;
+use Any::Moose;
+
+extends 'Prophet::Replica';
+
+use constant scheme   => 'prophet-cache';
+use constant cas_root => 'cas';
+use constant changeset_cas_dir =>
+    File::Spec->catdir( __PACKAGE__->cas_root => 'changesets' );
+
+
+has fs_root => (
+    is      => 'rw',
+    lazy    => 1,
+    default => sub {
+        my $self = shift;
+        return $self->app_handle->handle->url =~ m{^file://(.*)$} ? $1.'/remote-replica-cache' : undef;
+    },
+);
+
+    
+has changeset_index => (
+    is => 'rw',
+    lazy => 1,
+    default => sub {
+        my $self = shift;
+    File::Spec->catdir( $self->fs_root, 'replica', $self->replica_uuid, 'changesets.idx');
+        
+    }
+
+);    
+
+
+
+
+1;
\ No newline at end of file
diff --git a/lib/Prophet/Replica/prophet.pm b/lib/Prophet/Replica/prophet.pm
index d4f35d3..b5d2129 100644
--- a/lib/Prophet/Replica/prophet.pm
+++ b/lib/Prophet/Replica/prophet.pm
@@ -48,6 +48,26 @@ has fs_root => (
     },
 );
 
+has record_cas => (
+    is  => 'rw',
+    isa => 'Prophet::ContentAddressedStore',
+    lazy => 1,
+    default => sub {
+        my $self = shift;
+        Prophet::ContentAddressedStore->new( { root => File::Spec->catfile( $self->fs_root => $self->record_cas_dir ) } );
+    },
+);
+
+has changeset_cas => (
+    is  => 'rw',
+    isa => 'Prophet::ContentAddressedStore',
+    lazy => 1,
+    default => sub {
+        my $self = shift;
+        Prophet::ContentAddressedStore->new( { root => File::Spec->catfile( $self->fs_root => $self->changeset_cas_dir ) } );
+    },
+);
+    
 has current_edit => ( is => 'rw', );
 
 has current_edit_records => (
@@ -383,6 +403,7 @@ Return the replica SVN repository's UUID
 sub uuid {
     my $self = shift;
     $self->_uuid( $self->_read_file('replica-uuid') ) unless $self->_uuid;
+#    die $@ if $@;
     return $self->_uuid;
 }
 
@@ -430,6 +451,7 @@ sub _write_serialized_record {
         delete $args{'props'}->{$_}
             if ( !defined $args{'props'}->{$_} || $args{'props'}->{$_} eq '' );
     }
+    # my $cas_key = $self->record_cas->write( $args{props} );
     my ($cas_key) = $self->_write_to_cas(
         data    => $args{props},
         cas_dir => $self->record_cas_dir
@@ -605,6 +627,7 @@ sub _write_changeset {
     my $seqno = delete $hash_changeset->{'sequence_no'};
     my $uuid  = delete $hash_changeset->{'replica_uuid'};
 
+    # my $cas_key = $self->changeset_cas->write( $hash_changeset );
     my $cas_key = $self->_write_to_cas(
         data    => $hash_changeset,
         cas_dir => $self->changeset_cas_dir

commit 9e05474308358e49a58c1d51285854e6744edd06
Author: Chia-liang Kao <clkao at clkao.org>
Date:   Wed Apr 15 18:05:30 2009 +0800

    Enable Prophe::ContentAddressedStore for writing in replica::prophet.

diff --git a/lib/Prophet/ContentAddressedStore.pm b/lib/Prophet/ContentAddressedStore.pm
index 4b661b6..e50d9ad 100644
--- a/lib/Prophet/ContentAddressedStore.pm
+++ b/lib/Prophet/ContentAddressedStore.pm
@@ -1,12 +1,14 @@
 package Prophet::ContentAddressedStore;
-
 use Any::Moose;
 
+use JSON;
+use Digest::SHA qw(sha1_hex);
+
 has root => (
     isa => 'Str',
+    is  => 'rw',
 );
 
-
 sub write {
     my ($self, $content) = @_;
     $content = $$content if ref($content) eq 'SCALAR';
@@ -15,14 +17,13 @@ sub write {
         if ref($content);
     my $fingerprint      = sha1_hex($content);
     my $content_filename = File::Spec->catfile(
-        $self->root => $self->_hashed_dir_name($fingerprint) );
+        $self->root => Prophet::Util::hashed_dir_name($fingerprint) );
 
     Prophet::Util->write_file( file => $content_filename, content => $content);
 
     return $fingerprint;
 }
 
-
 __PACKAGE__->meta->make_immutable();
 no Any::Moose;
 1;
diff --git a/lib/Prophet/Replica/prophet.pm b/lib/Prophet/Replica/prophet.pm
index b5d2129..96d2e75 100644
--- a/lib/Prophet/Replica/prophet.pm
+++ b/lib/Prophet/Replica/prophet.pm
@@ -7,14 +7,15 @@ use LWP::ConnCache;
 use File::Spec  ();
 use File::Path;
 use Cwd ();
-use Digest::SHA qw(sha1_hex);
 use File::Find;
 use Data::UUID;
 use Prophet::Util;
-use JSON;
 use POSIX qw();
 use Memoize;
+use Prophet::ContentAddressedStore;
 
+use JSON;
+use Digest::SHA qw(sha1_hex);
 
 has '+db_uuid' => (
     lazy    => 1,
@@ -451,11 +452,7 @@ sub _write_serialized_record {
         delete $args{'props'}->{$_}
             if ( !defined $args{'props'}->{$_} || $args{'props'}->{$_} eq '' );
     }
-    # my $cas_key = $self->record_cas->write( $args{props} );
-    my ($cas_key) = $self->_write_to_cas(
-        data    => $args{props},
-        cas_dir => $self->record_cas_dir
-    );
+    my $cas_key = $self->record_cas->write( $args{props} );
 
     my $record = {
         uuid    => $args{uuid},
@@ -582,14 +579,7 @@ memoize '_record_index_filename';
 sub _record_index_filename {
     my $self = shift;
     my %args = validate( @_, { uuid => 1, type => 1 } );
-    return File::Spec->catfile( $self->_record_type_dir( $args{'type'} ), $self->_hashed_dir_name( $args{uuid} ));
-}
-
-sub _hashed_dir_name {
-    my $self = shift;
-    my $hash = shift;
-
-    return ( substr( $hash, 0, 1 ), substr( $hash, 1, 1 ), $hash );
+    return File::Spec->catfile( $self->_record_type_dir( $args{'type'} ), Prophet::Util::hashed_dir_name( $args{uuid} ));
 }
 
 sub _record_cas_filename {
@@ -602,7 +592,7 @@ sub _record_cas_filename {
     );
 
     return undef unless ( $key and ( $key ne '0' x 40 ) );
-    return File::Spec->catfile( $self->record_cas_dir, $self->_hashed_dir_name($key) );
+    return File::Spec->catfile( $self->record_cas_dir, Prophet::Util::hashed_dir_name($key) );
 }
 
 sub _record_type_dir {
@@ -627,11 +617,7 @@ sub _write_changeset {
     my $seqno = delete $hash_changeset->{'sequence_no'};
     my $uuid  = delete $hash_changeset->{'replica_uuid'};
 
-    # my $cas_key = $self->changeset_cas->write( $hash_changeset );
-    my $cas_key = $self->_write_to_cas(
-        data    => $hash_changeset,
-        cas_dir => $self->changeset_cas_dir
-    );
+    my $cas_key = $self->changeset_cas->write( $hash_changeset );
 
     my $changeset_index_line = pack( 'Na16NH40',
         $seqno,
@@ -663,7 +649,7 @@ sub _get_changeset_index_entry {
 
     # XXX: deserialize the changeset content from the cas with $key
     my $casfile = File::Spec->catfile(
-        $self->changeset_cas_dir => $self->_hashed_dir_name($key) );
+        $self->changeset_cas_dir => Prophet::Util::hashed_dir_name($key) );
 
     my $changeset = $self->_deserialize_changeset(
         content              => $self->_read_file($casfile),
@@ -793,24 +779,6 @@ sub _get_changeset_index_handle {
     return $cs_file;
 }
 
-sub _write_to_cas {
-    my $self = shift;
-    my %args = validate( @_, { content_ref => 0, cas_dir => 1, data => 0 } );
-    my $content;
-    if ( $args{'content_ref'} ) {
-        $content = ${ $args{'content_ref'} };
-    } elsif ( $args{'data'} ) {
-        $content = to_json( $args{'data'},
-            { canonical => 1, pretty => 0, utf8 => 1 } );
-    }
-    my $fingerprint      = sha1_hex($content);
-    my $content_filename = File::Spec->catfile(
-        $args{'cas_dir'} => $self->_hashed_dir_name($fingerprint) );
-
-    $self->_write_file( path => $content_filename, content => $content );
-    return $fingerprint;
-}
-
 sub _write_file {
     my $self = shift;
     my %args = validate( @_, { path => 1, content => 1 } );
diff --git a/lib/Prophet/Util.pm b/lib/Prophet/Util.pm
index fb7c00a..88f2f3f 100644
--- a/lib/Prophet/Util.pm
+++ b/lib/Prophet/Util.pm
@@ -98,4 +98,11 @@ sub write_file {
         ; # can't do "||" as we die if we print 0" || die "Could not write to " . $args{'path'} . " " . $!;
     close $fh || die $!;
 }
+
+sub hashed_dir_name {
+    my $hash = shift;
+
+    return ( substr( $hash, 0, 1 ), substr( $hash, 1, 1 ), $hash );
+}
+
 1;

commit eeeea47cffa69a8524f0c4ec0a03110d2f95bf00
Author: Chia-liang Kao <clkao at clkao.org>
Date:   Wed Apr 15 18:25:45 2009 +0800

    Provide filename helper from Prophet::ContentAddressStore.

diff --git a/lib/Prophet/ContentAddressedStore.pm b/lib/Prophet/ContentAddressedStore.pm
index e50d9ad..e38a23d 100644
--- a/lib/Prophet/ContentAddressedStore.pm
+++ b/lib/Prophet/ContentAddressedStore.pm
@@ -4,6 +4,11 @@ use Any::Moose;
 use JSON;
 use Digest::SHA qw(sha1_hex);
 
+has fs_root => (
+    isa => 'Str',
+    is  => 'rw',
+);
+
 has root => (
     isa => 'Str',
     is  => 'rw',
@@ -11,19 +16,27 @@ has root => (
 
 sub write {
     my ($self, $content) = @_;
-    $content = $$content if ref($content) eq 'SCALAR';
+
+    $content = $$content
+        if ref($content) eq 'SCALAR';
+
     $content = to_json( $content,
-            { canonical => 1, pretty => 0, utf8 => 1 } )
+                        { canonical => 1, pretty => 0, utf8 => 1 } )
         if ref($content);
-    my $fingerprint      = sha1_hex($content);
-    my $content_filename = File::Spec->catfile(
-        $self->root => Prophet::Util::hashed_dir_name($fingerprint) );
-
-    Prophet::Util->write_file( file => $content_filename, content => $content);
+    my $fingerprint = sha1_hex($content);
+    Prophet::Util->write_file( file => $self->filename($fingerprint, 1),
+                               content => $content );
 
     return $fingerprint;
 }
 
+sub filename {
+    my ($self, $key, $full) = @_;
+    File::Spec->catfile( $full ? $self->fs_root : (),
+                         $self->root =>
+                         Prophet::Util::hashed_dir_name($key) );
+}
+
 __PACKAGE__->meta->make_immutable();
 no Any::Moose;
 1;
diff --git a/lib/Prophet/Replica/prophet.pm b/lib/Prophet/Replica/prophet.pm
index 96d2e75..1a75081 100644
--- a/lib/Prophet/Replica/prophet.pm
+++ b/lib/Prophet/Replica/prophet.pm
@@ -55,7 +55,9 @@ has record_cas => (
     lazy => 1,
     default => sub {
         my $self = shift;
-        Prophet::ContentAddressedStore->new( { root => File::Spec->catfile( $self->fs_root => $self->record_cas_dir ) } );
+        Prophet::ContentAddressedStore->new(
+            { fs_root => $self->fs_root,
+              root    => $self->record_cas_dir } );
     },
 );
 
@@ -65,10 +67,12 @@ has changeset_cas => (
     lazy => 1,
     default => sub {
         my $self = shift;
-        Prophet::ContentAddressedStore->new( { root => File::Spec->catfile( $self->fs_root => $self->changeset_cas_dir ) } );
+        Prophet::ContentAddressedStore->new(
+            { fs_root => $self->fs_root,
+              root    => $self->changeset_cas_dir } );
     },
 );
-    
+
 has current_edit => ( is => 'rw', );
 
 has current_edit_records => (
@@ -592,7 +596,7 @@ sub _record_cas_filename {
     );
 
     return undef unless ( $key and ( $key ne '0' x 40 ) );
-    return File::Spec->catfile( $self->record_cas_dir, Prophet::Util::hashed_dir_name($key) );
+    return $self->record_cas->filename($key)
 }
 
 sub _record_type_dir {
@@ -648,8 +652,7 @@ sub _get_changeset_index_entry {
             . " data key $key" );
 
     # XXX: deserialize the changeset content from the cas with $key
-    my $casfile = File::Spec->catfile(
-        $self->changeset_cas_dir => Prophet::Util::hashed_dir_name($key) );
+    my $casfile = $self->changeset_cas->filename($key);
 
     my $changeset = $self->_deserialize_changeset(
         content              => $self->_read_file($casfile),

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



More information about the Bps-public-commit mailing list