[Bps-public-commit] r11736 - in Prophet/trunk: . lib/Prophet/Replica

jesse at bestpractical.com jesse at bestpractical.com
Tue Apr 15 17:15:24 EDT 2008


Author: jesse
Date: Tue Apr 15 17:15:24 2008
New Revision: 11736

Removed:
   Prophet/trunk/lib/Prophet/Replica/FS.pm
Modified:
   Prophet/trunk/   (props changed)
   Prophet/trunk/lib/Prophet/Replica.pm
   Prophet/trunk/lib/Prophet/Replica/Native.pm
   Prophet/trunk/lib/Prophet/Replica/SVN.pm

Log:
 r29747 at 31b:  jesse | 2008-04-15 12:31:41 -0400
 * Replica cleanup, working toward a proper 'native fs' replica type
 


Modified: Prophet/trunk/lib/Prophet/Replica.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Replica.pm	(original)
+++ Prophet/trunk/lib/Prophet/Replica.pm	Tue Apr 15 17:15:24 2008
@@ -435,27 +435,6 @@
     return \@results;
 }
 
-sub traverse_changesets {
-    my $self = shift;
-    my %args = validate(
-        @_,
-        {   after    => 1,
-            callback => 1,
-        }
-    );
-
-    my $first_rev = ( $args{'after'} + 1 ) || 1;
-    my $last_rev = $self->latest_sequence_no();
-
-
-    die "you must implement latest_sequence_no in " . ref($self) . ", or override traverse_changesets"
-        unless defined $last_rev;
-
-    for my $rev ( $first_rev .. $self->latest_sequence_no ) {
-        $args{callback}->( $self->fetch_changeset($rev) );
-    }
-}
-
 =head2 export_to { path => $PATH } 
 
 This routine will export a copy of this prophet database replica to a flat file on disk suitable for 
@@ -498,14 +477,16 @@
 
 sub latest_sequence_no {return undef }
 
-=head2 fetch_changeset SEQUENCE_NO
+=head2 traverse_changesets { after => SEQUENCE_NO, callback => sub {} }
+
+Walk through each changeset in the replica after SEQUENCE_NO, calling the C<callback> for each one in turn.
 
-Returns a Prophet::ChangeSet object for changeset # C<SEQUENCE_NO>
 
 =cut
 
-sub fetch_changeset {} 
+sub traverse_changesets {
 
+}
 
 
 

Modified: Prophet/trunk/lib/Prophet/Replica/Native.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Replica/Native.pm	(original)
+++ Prophet/trunk/lib/Prophet/Replica/Native.pm	Tue Apr 15 17:15:24 2008
@@ -13,7 +13,7 @@
 use Prophet::Conflict;
 
 __PACKAGE__->mk_accessors(qw/url db_uuid _uuid/);
-__PACKAGE__->mk_accessors( qw(fs_root target_replica cas_root record_cas_dir changeset_cas_dir record_dir));
+__PACKAGE__->mk_accessors(qw(fs_root target_replica cas_root record_cas_dir changeset_cas_dir record_dir));
 
 use constant scheme => 'prophet';
 
@@ -38,36 +38,35 @@
     }
 }
 
-
 sub initialize {
     my $self = shift;
-    my %args = validate(@_, { db_uuid => 0});
+    my %args = validate( @_, { db_uuid => 0 } );
 
     $self->cas_root( dir( $self->fs_root => 'cas' ) );
     $self->record_cas_dir( dir( $self->cas_root => 'records' ) );
     $self->changeset_cas_dir( dir( $self->cas_root => 'changesets' ) );
     $self->record_dir( dir( $self->fs_root => 'records' ) );
 
-    _mkdir($_) for (  $self->fs_root, $self->record_dir, $self->cas_root );
+    _mkdir($_) for ( $self->fs_root, $self->record_dir, $self->cas_root );
     make_tiered_dirs( $self->record_cas_dir );
     make_tiered_dirs( $self->changeset_cas_dir );
 
     $self->set_latest_sequence_no("1");
-    $self->set_replica_uuid(Data::UUID->new->create_str);
-    $self->_output_oneliner_file( path => file( $self->fs_root, 'replica-version' ), content => '1' );
+    $self->set_replica_uuid( Data::UUID->new->create_str );
+    $self->_write_file( path => file( $self->fs_root, 'replica-version' ), content => '1' );
 }
 
 sub set_replica_uuid {
-    my $self  = shift;
+    my $self = shift;
     my $uuid = shift;
-    $self->_output_oneliner_file( path    => file( $self->fs_root, 'replica-uuid' ), content => $uuid);
+    $self->_write_file( path => file( $self->fs_root, 'replica-uuid' ), content => $uuid );
 
 }
 
 sub set_latest_sequence_no {
     my $self = shift;
-    my $id = shift;
-    $self->_output_oneliner_file( path    => file( $self->fs_root, 'latest-sequence-no' ), content => scalar($id));
+    my $id   = shift;
+    $self->_write_file( path => file( $self->fs_root, 'latest-sequence-no' ), content => scalar($id) );
 }
 
 =head2 uuid
@@ -79,17 +78,13 @@
 sub uuid {
     my $self = shift;
 
-    $self->_uuid( LWP::Simple::get( $self->url . '/replica-uuid' ) ) unless $self->_uuid;
+    $self->_uuid( $self->_read_file('/replica-uuid') ) unless $self->_uuid;
     return $self->_uuid;
 }
 
 sub _write_record {
     my $self = shift;
-    my %args = validate(
-        @_,
-        {   record     => { isa => 'Prophet::Record' },
-        }
-    );
+    my %args = validate( @_, { record => { isa => 'Prophet::Record' }, } );
 
     my $record_dir = dir( $self->fs_root, 'records', $args{'record'}->type );
     make_tiered_dirs($record_dir) unless -d $record_dir;
@@ -99,7 +94,8 @@
         cas_dir     => $self->record_cas_dir
     );
 
-    my $idx_filename = file( $record_dir,
+    my $idx_filename = file(
+        $record_dir,
         substr( $args{record}->uuid, 0, 1 ),
         substr( $args{record}->uuid, 1, 1 ),
         $args{record}->uuid
@@ -144,11 +140,9 @@
 
 }
 
-=head2 fetch_changesets { after => SEQUENCE_NO } 
-
-Fetch all changesets from the source. 
+=head2 traverse_changesets { after => SEQUENCE_NO, callback => sub { } } 
 
-Returns a reference to an array of L<Prophet::ChangeSet/> objects.
+Walks through all changesets after $after, calling $callback on each.
 
 
 =cut
@@ -167,9 +161,9 @@
         }
     );
 
-    my $first_rev = ( $args{'after'} + 1 ) || 1;
+    my $first_rev = ( $args{'after'}+1) || 1;
     my $latest    = $self->latest_sequence_no();
-    my $chgidx    = LWP::Simple::get( $self->url . '/changesets.idx' );
+    my $chgidx    = $self->_read_file('/changesets.idx');
 
     for my $rev ( $first_rev .. $latest ) {
         my ( $seq, $orig_uuid, $orig_seq, $key )
@@ -177,9 +171,9 @@
         $orig_uuid = Data::UUID->new->to_string($orig_uuid);
 
         # XXX: deserialize the changeset content from the cas with $key
-        my $casfile = $self->url . '/cas/changesets/' . substr( $key, 0, 1 ) . '/' . substr( $key, 1, 1 ) . '/' . $key;
+        my $casfile = '/cas/changesets/' . substr( $key, 0, 1 ) . '/' . substr( $key, 1, 1 ) . '/' . $key;
         my $changeset = $self->_deserialize_changeset(
-            content              => LWP::Simple::get($casfile),
+            content              => $self->_read_file($casfile),
             original_source_uuid => $orig_uuid,
             original_sequence_no => $orig_seq,
             sequence_no          => $seq
@@ -188,9 +182,12 @@
     }
 }
 
+
+
+
 sub latest_sequence_no {
     my $self = shift;
-    return LWP::Simple::get( $self->url . '/latest-sequence-no' );
+    $self->_read_file('/latest-sequence-no');
 }
 
 sub _deserialize_changeset {
@@ -236,19 +233,66 @@
     my $fingerprint = sha1_hex($content);
     my $content_filename
         = file( $args{'cas_dir'}, substr( $fingerprint, 0, 1 ), substr( $fingerprint, 1, 1 ), $fingerprint );
-    open( my $output, ">", $content_filename ) || die "Could not open $content_filename";
-    print $output $content || die $!;
-    close $output;
+
+    $self->_write_file( path => $content_filename, content => $content );
     return $fingerprint;
 }
 
-sub _output_oneliner_file {
+sub _write_file {
     my $self = shift;
     my %args = validate( @_, { path => 1, content => 1 } );
-
     open( my $file, ">", $args{'path'} ) || die $!;
-    print $file $args{'content'} || die "Could not write to ".$args{'path'} . " " . $!;
+    print $file $args{'content'} || die "Could not write to " . $args{'path'} . " " . $!;
     close $file || die $!;
 }
 
+sub _read_file {
+    my $self = shift;
+    my ($file) = validate_pos( @_, 1 );
+    LWP::Simple::get( $self->url . $file );
+}
+
+sub state_handle { return shift }  #XXX TODO better way to handle this?
+sub record_changeset_integration {
+    my ($self, $changeset) = validate_pos( @_, 1, { isa => 'Prophet::ChangeSet' } );
+
+    $self->_set_original_source_metadata($changeset);
+    return $self->SUPER::record_changeset_integration($changeset);
+}
+sub begin_edit {
+}
+sub commit_edit {
+}
+sub create_record {
+    my %args = validate( @_, { uuid => 1, props => 1, type => 1 } );
+
+}
+sub delete_record {
+    my $self = shift;
+    my %args = validate( @_, { uuid => 1, type => 1 } );
+}
+sub set_record_props {
+    my $self = shift;
+    my %args = validate( @_, { uuid => 1, props => 1, type => 1 } );
+
+}
+sub get_record_props {
+    my $self = shift;
+    my %args = validate( @_, { uuid => 1, type => 1 } );
+}
+sub record_exists {
+    my $self = shift;
+    my %args = validate( @_, { uuid => 1, type => 1} );
+}
+sub list_records {
+    my $self = shift;
+    my %args = validate( @_ => { type => 1 } );
+}
+sub list_types {
+    my $self = shift;
+}
+sub type_exists {
+    my $self = shift;
+    my %args = validate( @_, { type => 1 } );
+}
 1;

Modified: Prophet/trunk/lib/Prophet/Replica/SVN.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Replica/SVN.pm	(original)
+++ Prophet/trunk/lib/Prophet/Replica/SVN.pm	Tue Apr 15 17:15:24 2008
@@ -96,7 +96,29 @@
     $self->ra->get_latest_revnum;
 }
 
-sub fetch_changeset {
+
+sub traverse_changesets {
+    my $self = shift;
+    my %args = validate( @_,
+        {   after    => 1,
+            callback => 1,
+        }
+    );
+
+    my $first_rev = ( $args{'after'} + 1 ) || 1;
+    my $last_rev = $self->latest_sequence_no();
+
+
+    die "you must implement latest_sequence_no in " . ref($self) . ", or override traverse_changesets"
+        unless defined $last_rev;
+
+    for my $rev ( $first_rev .. $self->latest_sequence_no ) {
+        $args{callback}->( $self->_fetch_changeset($rev) );
+    }
+}
+
+
+sub _fetch_changeset {
     my $self   = shift;
     my $rev    = shift;
     my $editor = Prophet::Replica::SVN::ReplayEditor->new( _debug => 0 );



More information about the Bps-public-commit mailing list