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

jesse jesse at bestpractical.com
Sun Aug 16 22:23:41 EDT 2009


The branch, master has been updated
       via  8c96104a84409ea11a4ff2bb9cf6e54c0328d30b (commit)
       via  a29b04e72fac4ade097bac9911cf7421f239db17 (commit)
       via  42db596824d37be34fc04b121159b7e31add9b0f (commit)
       via  8fa4b3355cd5bce7a2a40b9bee8b5d581ec764de (commit)
       via  25798e59ef4ed5be89a9380e090fdba42bfd0cdb (commit)
       via  0a88a11a04dac77c7aa462f7bdae3a5a7d372e9e (commit)
       via  b3da6b85b3e3972060b0a55ae22a30a5c082b8c4 (commit)
      from  2bf88ebdfb5dfa39374af6c1cabf121b7a9a41fe (commit)

Summary of changes:
 lib/Prophet/FilesystemReplica.pm     |    3 +-
 lib/Prophet/Replica.pm               |   37 ++++++++
 lib/Prophet/Replica/prophet.pm       |   43 +++-------
 lib/Prophet/Replica/prophet_cache.pm |   52 ++++--------
 lib/Prophet/Replica/sqlite.pm        |  163 ++++++++++++++++------------------
 lib/Prophet/UUIDGenerator.pm         |   17 ++++
 6 files changed, 161 insertions(+), 154 deletions(-)

- Log -----------------------------------------------------------------
commit b3da6b85b3e3972060b0a55ae22a30a5c082b8c4
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Sun Aug 16 19:09:41 2009 -0400

    Added a helper method to tell us uuid versions

diff --git a/lib/Prophet/UUIDGenerator.pm b/lib/Prophet/UUIDGenerator.pm
index 4cf16eb..452558e 100644
--- a/lib/Prophet/UUIDGenerator.pm
+++ b/lib/Prophet/UUIDGenerator.pm
@@ -59,6 +59,12 @@ sub to_safe_b64 {
     return urlsafe_b64encode($self->from_string($uuid));
 }
 
+sub version {
+	my $self = shift;
+	my $uuid = shift;
+	return version_of_UUID($uuid);
+}
+
 
 =head1 NAME
 

commit 0a88a11a04dac77c7aa462f7bdae3a5a7d372e9e
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Sun Aug 16 19:58:22 2009 -0400

    FilesytemReplica is now a baseclass, rather than a role

diff --git a/lib/Prophet/FilesystemReplica.pm b/lib/Prophet/FilesystemReplica.pm
index 9890125..362e39a 100644
--- a/lib/Prophet/FilesystemReplica.pm
+++ b/lib/Prophet/FilesystemReplica.pm
@@ -1,5 +1,6 @@
 package Prophet::FilesystemReplica;
-use Any::Moose 'Role';
+use Any::Moose;
+extends 'Prophet::Replica';
 use File::Spec;use Params::Validate qw(:all);
 use LWP::UserAgent;
 use JSON;
diff --git a/lib/Prophet/Replica/prophet.pm b/lib/Prophet/Replica/prophet.pm
index 140354e..c3dcf82 100644
--- a/lib/Prophet/Replica/prophet.pm
+++ b/lib/Prophet/Replica/prophet.pm
@@ -1,7 +1,6 @@
 package Prophet::Replica::prophet;
 use Any::Moose;
-extends 'Prophet::Replica';
-with 'Prophet::FilesystemReplica';
+extends 'Prophet::FilesystemReplica';
 
 use Params::Validate qw(:all);
 use LWP::UserAgent;
diff --git a/lib/Prophet/Replica/prophet_cache.pm b/lib/Prophet/Replica/prophet_cache.pm
index 5a31037..50827ea 100644
--- a/lib/Prophet/Replica/prophet_cache.pm
+++ b/lib/Prophet/Replica/prophet_cache.pm
@@ -1,8 +1,7 @@
 package Prophet::Replica::prophet_cache;
 use Any::Moose;
 
-extends 'Prophet::Replica';
-with 'Prophet::FilesystemReplica';
+extends 'Prophet::FilesystemReplica';
 use Params::Validate ':all';
 use File::Path qw/mkpath/;
 

commit 25798e59ef4ed5be89a9380e090fdba42bfd0cdb
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Sun Aug 16 20:02:26 2009 -0400

    perltidy

diff --git a/lib/Prophet/Replica/prophet.pm b/lib/Prophet/Replica/prophet.pm
index c3dcf82..d7e8812 100644
--- a/lib/Prophet/Replica/prophet.pm
+++ b/lib/Prophet/Replica/prophet.pm
@@ -303,9 +303,7 @@ sub initialize {
     if ( !$self->fs_root_parent ) {
 
         if ( $self->can_write_changesets ) {
-            die
-                "We can only create local prophet replicas. It looks like you're trying to create "
-                . $self->url;
+            die "We can only create local prophet replicas. It looks like you're trying to create " . $self->url;
         } else {
             die "Prophet couldn't find a replica at \""
                 . $self->url
@@ -317,18 +315,13 @@ sub initialize {
 
     return if $self->replica_exists;
 
-    for (
-        $self->record_dir,     $self->cas_root,
-        $self->record_cas_dir, $self->changeset_cas_dir,
-        $self->userdata_dir
-        )
-    {
+    for ( $self->record_dir, $self->cas_root, $self->record_cas_dir, $self->changeset_cas_dir, $self->userdata_dir ) {
         mkpath( [ File::Spec->catdir( $self->fs_root => $_ ) ] );
     }
 
     $self->set_db_uuid( $args{'db_uuid'} || $self->uuid_generator->create_str );
     $self->set_latest_sequence_no("0");
-    $self->set_replica_uuid(  $self->uuid_generator->create_str );
+    $self->set_replica_uuid( $self->uuid_generator->create_str );
 
     $self->set_replica_version(1);
 
diff --git a/lib/Prophet/Replica/prophet_cache.pm b/lib/Prophet/Replica/prophet_cache.pm
index 50827ea..abda350 100644
--- a/lib/Prophet/Replica/prophet_cache.pm
+++ b/lib/Prophet/Replica/prophet_cache.pm
@@ -147,18 +147,15 @@ sub initialize {
     my $self = shift;
     my %args = validate(
         @_,
-        {
-            db_uuid    => 1,
-            replica_uuid => 1,
-            resdb_uuid    => 0,
+        {   db_uuid            => 1,
+            replica_uuid       => 1,
+            resdb_uuid         => 0,
             resdb_replica_uuid => 0,
         }
     );
     if ( !$self->fs_root_parent ) {
         if ( $self->can_write_changesets ) {
-            die
-                "We can only create local prophet replicas. It looks like you're trying to create "
-                . $self->url;
+            die "We can only create local prophet replicas. It looks like you're trying to create " . $self->url;
         } else {
             die "Prophet couldn't find a replica at \""
                 . $self->fs_root_parent
@@ -169,21 +166,19 @@ sub initialize {
     }
 
     return if $self->replica_exists;
-    for (
-        $self->cas_root,
-        $self->changeset_cas_dir,
-        $self->replica_dir,
-        File::Spec->catdir($self->replica_dir, $args{'replica_uuid'}),
-        $self->userdata_dir
-        )
+    for ( $self->cas_root, $self->changeset_cas_dir, $self->replica_dir,
+        File::Spec->catdir( $self->replica_dir, $args{'replica_uuid'} ),
+        $self->userdata_dir )
     {
         mkpath( [ File::Spec->catdir( $self->fs_root => $_ ) ] );
     }
 
-    $self->set_db_uuid( $args{db_uuid});
-    $self->set_resdb_replica_uuid($args{resdb_replica_uuid}) unless ($self->is_resdb);
-    $self->resolution_db_handle->initialize(db_uuid => $args{resdb_uuid}, replica_uuid => $args{resdb_replica_uuid})  unless ($self->is_resdb);
-    $self->after_initialize->($self);
+    $self->set_db_uuid( $args{db_uuid} );
+    $self->set_resdb_replica_uuid( $args{resdb_replica_uuid} ) unless ( $self->is_resdb );
+    $self->resolution_db_handle->initialize( db_uuid => $args{resdb_uuid}, replica_uuid => $args{resdb_replica_uuid} )
+        unless ( $self->is_resdb );
+
+	$self->after_initialize->($self);
 }
 
 sub set_resdb_replica_uuid {

commit 8fa4b3355cd5bce7a2a40b9bee8b5d581ec764de
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Sun Aug 16 20:06:16 2009 -0400

    Move the schema for sqlite out to its own sub

diff --git a/lib/Prophet/Replica/sqlite.pm b/lib/Prophet/Replica/sqlite.pm
index f626e05..2245f67 100644
--- a/lib/Prophet/Replica/sqlite.pm
+++ b/lib/Prophet/Replica/sqlite.pm
@@ -284,68 +284,7 @@ sub initialize {
     mkpath( [ $self->fs_root ] );
 
     #$self->dbh->begin_work;
-    for (
-
-        q{
-CREATE TABLE records (
-    luid INTEGER PRIMARY KEY AUTOINCREMENT,
-    uuid text,
-    type text
-)
-},
-        q{
-CREATE TABLE record_props (
-    uuid text,
-    prop text,
-    value text 
-)
-
-}, q{
-CREATE TABLE changesets (
-    sequence_no INTEGER PRIMARY KEY AUTOINCREMENT,
-    creator text,
-    created text,
-    is_nullification boolean,
-    is_resolution boolean,
-
-    original_source_uuid text,
-    original_sequence_no INTEGER,
-    sha1 TEXT
-)
-}, q{
-CREATE TABLE changes (
-    id INTEGER PRIMARY KEY AUTOINCREMENT,
-    record text,
-    changeset integer, 
-    change_type text,
-    record_type text
-)
-}, q{
-CREATE TABLE prop_changes (
-    change integer,
-    name text,
-    old_value text,
-    new_value text
-)
-}, q{
-CREATE TABLE local_metadata (
-    key text,
-    value text
-
-)
-}, q{
-CREATE TABLE userdata (
-    key text,
-    value text
-)
-},
-
-        q{create index uuid_idx on record_props(uuid)},
-        q{create index typeuuuid on records(type, uuid)},
-        q{create index keyidx on userdata(key)}
-
-      )
-    {
+    for (@$self->schema) {
         $self->dbh->do($_) || warn $self->dbh->errstr;
     }
 
@@ -959,6 +898,73 @@ sub find_uuid_by_luid {
     return $sth->fetchrow_array;
 }
 
+
+sub schema {
+	my $self = shift;
+	return (
+
+        q{
+CREATE TABLE records (
+    luid INTEGER PRIMARY KEY AUTOINCREMENT,
+    uuid text,
+    type text
+)
+},
+        q{
+CREATE TABLE record_props (
+    uuid text,
+    prop text,
+    value text
+)
+
+}, q{
+CREATE TABLE changesets (
+    sequence_no INTEGER PRIMARY KEY AUTOINCREMENT,
+    creator text,
+    created text,
+    is_nullification boolean,
+    is_resolution boolean,
+
+    original_source_uuid text,
+    original_sequence_no INTEGER,
+    sha1 TEXT
+)
+}, q{
+CREATE TABLE changes (
+    id INTEGER PRIMARY KEY AUTOINCREMENT,
+    record text,
+    changeset integer,
+    change_type text,
+    record_type text
+)
+}, q{
+CREATE TABLE prop_changes (
+    change integer,
+    name text,
+    old_value text,
+    new_value text
+)
+}, q{
+CREATE TABLE local_metadata (
+    key text,
+    value text
+
+)
+}, q{
+CREATE TABLE userdata (
+    key text,
+    value text
+)
+},
+
+        q{create index uuid_idx on record_props(uuid)},
+        q{create index typeuuuid on records(type, uuid)},
+        q{create index keyidx on userdata(key)}
+
+      );
+}
+
+
 sub _upgrade_replica_to_v2 {
     my $self = shift;
 

commit 42db596824d37be34fc04b121159b7e31add9b0f
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Sun Aug 16 20:22:31 2009 -0400

    extract out some common pre-initialize code

diff --git a/lib/Prophet/Replica.pm b/lib/Prophet/Replica.pm
index 9f632de..34b2d0e 100644
--- a/lib/Prophet/Replica.pm
+++ b/lib/Prophet/Replica.pm
@@ -98,6 +98,35 @@ sub get_handle {
 }
 
 
+sub before_initialize {
+    my $self = shift;
+    my %args = validate(
+        @_,
+        {   db_uuid    => 0,
+            resdb_uuid => 0,
+        }
+    );
+
+    if ( !$self->fs_root_parent ) {
+
+        if ( $self->can_write_changesets ) {
+            die "We can only create local prophet replicas. It looks like you're trying to create " . $self->url;
+        } else {
+            die "Prophet couldn't find a replica at \""
+                . $self->url
+                . "\"\n\n"
+                . "Please check the URL and try again.\n";
+
+        }
+    }
+
+    return undef if $self->replica_exists;
+	return 1;
+
+}
+
+
+
 =head2 store_local_metadata KEY => VALUE
 
 Takes a key and a value.
diff --git a/lib/Prophet/Replica/prophet.pm b/lib/Prophet/Replica/prophet.pm
index d7e8812..932227d 100644
--- a/lib/Prophet/Replica/prophet.pm
+++ b/lib/Prophet/Replica/prophet.pm
@@ -300,20 +300,8 @@ sub initialize {
         }
     );
 
-    if ( !$self->fs_root_parent ) {
 
-        if ( $self->can_write_changesets ) {
-            die "We can only create local prophet replicas. It looks like you're trying to create " . $self->url;
-        } else {
-            die "Prophet couldn't find a replica at \""
-                . $self->url
-                . "\"\n\n"
-                . "Please check the URL and try again.\n";
-
-        }
-    }
-
-    return if $self->replica_exists;
+	$self->before_initialize(%args)  || return undef;
 
     for ( $self->record_dir, $self->cas_root, $self->record_cas_dir, $self->changeset_cas_dir, $self->userdata_dir ) {
         mkpath( [ File::Spec->catdir( $self->fs_root => $_ ) ] );
diff --git a/lib/Prophet/Replica/prophet_cache.pm b/lib/Prophet/Replica/prophet_cache.pm
index abda350..46a4289 100644
--- a/lib/Prophet/Replica/prophet_cache.pm
+++ b/lib/Prophet/Replica/prophet_cache.pm
@@ -153,20 +153,11 @@ sub initialize {
             resdb_replica_uuid => 0,
         }
     );
-    if ( !$self->fs_root_parent ) {
-        if ( $self->can_write_changesets ) {
-            die "We can only create local prophet replicas. It looks like you're trying to create " . $self->url;
-        } else {
-            die "Prophet couldn't find a replica at \""
-                . $self->fs_root_parent
-                . "\"\n\n"
-                . "Please check the URL and try again.\n";
 
-        }
-    }
 
-    return if $self->replica_exists;
-    for ( $self->cas_root, $self->changeset_cas_dir, $self->replica_dir,
+	$self->before_initialize(%args)  || return undef;
+
+	for ( $self->cas_root, $self->changeset_cas_dir, $self->replica_dir,
         File::Spec->catdir( $self->replica_dir, $args{'replica_uuid'} ),
         $self->userdata_dir )
     {
diff --git a/lib/Prophet/Replica/sqlite.pm b/lib/Prophet/Replica/sqlite.pm
index 2245f67..19b6cfd 100644
--- a/lib/Prophet/Replica/sqlite.pm
+++ b/lib/Prophet/Replica/sqlite.pm
@@ -265,26 +265,12 @@ sub initialize {
         }
     );
 
-    if ( !$self->fs_root_parent ) {
+	$self->before_initialize(%args) || return undef;
 
-        if ( $self->can_write_changesets ) {
-            die "We can only create local prophet replicas. It looks like you're trying to create "
-              . $self->url;
-        }
-        else {
-            die "Prophet couldn't find a replica at \""
-              . $self->url
-              . "\"\n\n"
-              . "Please check the URL and try again.\n";
-
-        }
-    }
-
-    return if $self->replica_exists;
     mkpath( [ $self->fs_root ] );
 
     #$self->dbh->begin_work;
-    for (@$self->schema) {
+    for ($self->schema) {
         $self->dbh->do($_) || warn $self->dbh->errstr;
     }
 

commit a29b04e72fac4ade097bac9911cf7421f239db17
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Sun Aug 16 21:29:45 2009 -0400

    Further refactoring of initialization

diff --git a/lib/Prophet/Replica.pm b/lib/Prophet/Replica.pm
index 34b2d0e..53c3f19 100644
--- a/lib/Prophet/Replica.pm
+++ b/lib/Prophet/Replica.pm
@@ -2,6 +2,7 @@ package Prophet::Replica;
 use Any::Moose;
 use Params::Validate qw(:all);
 use File::Spec ();
+use File::Path qw/mkpath/;
 
 use constant state_db_uuid => 'state';
 
@@ -98,12 +99,14 @@ sub get_handle {
 }
 
 
-sub before_initialize {
+sub initialize {
     my $self = shift;
     my %args = validate(
         @_,
-        {   db_uuid    => 0,
-            resdb_uuid => 0,
+        {   db_uuid            => 0,
+            replica_uuid       => 0,
+            resdb_uuid         => 0,
+            resdb_replica_uuid => 0,
         }
     );
 
@@ -121,8 +124,13 @@ sub before_initialize {
     }
 
     return undef if $self->replica_exists;
-	return 1;
 
+    for ( $self->_on_initialize_create_paths ) {
+        mkpath( [ File::Spec->catdir( $self->fs_root => $_ ) ] );
+    }
+
+	$self->initialize_backend(%args);
+	$self->after_initialize->($self);
 }
 
 
diff --git a/lib/Prophet/Replica/prophet.pm b/lib/Prophet/Replica/prophet.pm
index 932227d..db427fb 100644
--- a/lib/Prophet/Replica/prophet.pm
+++ b/lib/Prophet/Replica/prophet.pm
@@ -291,7 +291,15 @@ use constant can_read_changesets => 1;
 sub can_write_changesets { return ( shift->fs_root ? 1 : 0 ) }
 sub can_write_records    { return ( shift->fs_root ? 1 : 0 ) }
 
-sub initialize {
+
+sub _on_initialize_create_paths {
+		my $self = shift;
+		return ( $self->record_dir, $self->cas_root, $self->record_cas_dir,
+			$self->changeset_cas_dir, $self->userdata_dir );
+
+}
+
+sub initialize_backend {
     my $self = shift;
     my %args = validate(
         @_,
@@ -300,13 +308,6 @@ sub initialize {
         }
     );
 
-
-	$self->before_initialize(%args)  || return undef;
-
-    for ( $self->record_dir, $self->cas_root, $self->record_cas_dir, $self->changeset_cas_dir, $self->userdata_dir ) {
-        mkpath( [ File::Spec->catdir( $self->fs_root => $_ ) ] );
-    }
-
     $self->set_db_uuid( $args{'db_uuid'} || $self->uuid_generator->create_str );
     $self->set_latest_sequence_no("0");
     $self->set_replica_uuid( $self->uuid_generator->create_str );
@@ -315,8 +316,6 @@ sub initialize {
 
     $self->resolution_db_handle->initialize( db_uuid => $args{resdb_uuid} )
         if !$self->is_resdb;
-
-    $self->after_initialize->($self);
 }
 
 sub latest_sequence_no {
diff --git a/lib/Prophet/Replica/prophet_cache.pm b/lib/Prophet/Replica/prophet_cache.pm
index 46a4289..ef569dc 100644
--- a/lib/Prophet/Replica/prophet_cache.pm
+++ b/lib/Prophet/Replica/prophet_cache.pm
@@ -3,7 +3,6 @@ use Any::Moose;
 
 extends 'Prophet::FilesystemReplica';
 use Params::Validate ':all';
-use File::Path qw/mkpath/;
 
 has '+db_uuid' => (
     lazy    => 1,
@@ -143,7 +142,14 @@ sub initialize_from_source {
     $self->initialize(%init_args);    # XXX only do this when we need to
 }
 
-sub initialize {
+sub _on_initialize_create_paths {
+	my $self = shift;
+	return ( $self->cas_root, $self->changeset_cas_dir, $self->replica_dir,
+        File::Spec->catdir( $self->replica_dir, $args{'replica_uuid'} ),
+        $self->userdata_dir );
+}
+
+sub initialize_backend {
     my $self = shift;
     my %args = validate(
         @_,
@@ -154,22 +160,11 @@ sub initialize {
         }
     );
 
-
-	$self->before_initialize(%args)  || return undef;
-
-	for ( $self->cas_root, $self->changeset_cas_dir, $self->replica_dir,
-        File::Spec->catdir( $self->replica_dir, $args{'replica_uuid'} ),
-        $self->userdata_dir )
-    {
-        mkpath( [ File::Spec->catdir( $self->fs_root => $_ ) ] );
-    }
-
     $self->set_db_uuid( $args{db_uuid} );
     $self->set_resdb_replica_uuid( $args{resdb_replica_uuid} ) unless ( $self->is_resdb );
+
     $self->resolution_db_handle->initialize( db_uuid => $args{resdb_uuid}, replica_uuid => $args{resdb_replica_uuid} )
         unless ( $self->is_resdb );
-
-	$self->after_initialize->($self);
 }
 
 sub set_resdb_replica_uuid {
diff --git a/lib/Prophet/Replica/sqlite.pm b/lib/Prophet/Replica/sqlite.pm
index 19b6cfd..4b12cd3 100644
--- a/lib/Prophet/Replica/sqlite.pm
+++ b/lib/Prophet/Replica/sqlite.pm
@@ -255,21 +255,23 @@ use constant can_read_changesets => 1;
 sub can_write_changesets {1}
 sub can_write_records    {1}
 
-sub initialize {
+
+sub _on_initialize_create_paths {
+		my $self = shift;
+		# We initialize the root, so we just insert '' here
+		return ('');
+	}
+
+
+sub initialize_backend {
     my $self = shift;
     my %args = validate(
         @_,
-        {
-            db_uuid    => 0,
+        {   db_uuid    => 0,
             resdb_uuid => 0,
         }
     );
 
-	$self->before_initialize(%args) || return undef;
-
-    mkpath( [ $self->fs_root ] );
-
-    #$self->dbh->begin_work;
     for ($self->schema) {
         $self->dbh->do($_) || warn $self->dbh->errstr;
     }
@@ -279,7 +281,6 @@ sub initialize {
     $self->set_replica_version(3);
     $self->resolution_db_handle->initialize( db_uuid => $args{resdb_uuid} )
       if !$self->is_resdb;
-    $self->after_initialize->($self);
 }
 
 sub latest_sequence_no {

commit 8c96104a84409ea11a4ff2bb9cf6e54c0328d30b
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Sun Aug 16 22:11:10 2009 -0400

    Added a method to set the uuid scheme based on a sample uuid

diff --git a/lib/Prophet/UUIDGenerator.pm b/lib/Prophet/UUIDGenerator.pm
index 452558e..3658d12 100644
--- a/lib/Prophet/UUIDGenerator.pm
+++ b/lib/Prophet/UUIDGenerator.pm
@@ -65,6 +65,17 @@ sub version {
 	return version_of_UUID($uuid);
 }
 
+sub set_uuid_scheme {
+	my $self = shift;
+	my $uuid = shift;
+
+		if ($self->version($uuid) <= 3) {
+			$self->uuid_scheme(1);
+		} else {
+			$self->uuid_scheme(2);
+		}
+
+	}
 
 =head1 NAME
 

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



More information about the Bps-public-commit mailing list