[Bps-public-commit] r11795 - in Prophet/trunk: . t
jesse at bestpractical.com
jesse at bestpractical.com
Sat Apr 19 20:39:02 EDT 2008
Author: jesse
Date: Sat Apr 19 20:38:58 2008
New Revision: 11795
Modified:
Prophet/trunk/ (props changed)
Prophet/trunk/lib/Prophet/Replica/Native.pm
Prophet/trunk/t/export.t
Log:
r29927 at 31b: jesse | 2008-04-20 02:37:39 +0200
* Get a separate state handle so we can have merge tickets in isolated transactions. This turns up all sorts of other problems.
Modified: Prophet/trunk/lib/Prophet/Replica/Native.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Replica/Native.pm (original)
+++ Prophet/trunk/lib/Prophet/Replica/Native.pm Sat Apr 19 20:38:58 2008
@@ -20,8 +20,8 @@
use constant scheme => 'prophet';
use constant cas_root => 'cas';
-use constant record_cas_dir => dir( cas_root => 'records' );
-use constant changeset_cas_dir => dir( cas_root => 'changesets' );
+use constant record_cas_dir => dir( __PACKAGE__->cas_root => 'records' );
+use constant changeset_cas_dir => dir( __PACKAGE__->cas_root => 'changesets' );
use constant record_dir => 'records';
use constant changeset_index => 'changesets.idx';
@@ -33,7 +33,6 @@
sub setup {
my $self = shift;
-
$self->{url}
=~ s/^prophet://; # url-based constructor in ::replica should do better
$self->{url} =~ s{/$}{};
@@ -42,12 +41,19 @@
$self->_probe_or_create_db();
+ $self->state_handle( Prophet::Replica->new( { url => "prophet:".$self->{url}, is_state_handle =>1 } ) ) unless ( $self->is_state_handle || $self->state_handle);
$self->resolution_db_handle( Prophet::Replica->new( { url => "prophet:".$self->{url}.'/resolutions', is_resdb => 1 } ) )
- unless ( $self->is_resdb );
+ unless ( $self->is_resdb || $self->is_state_handle);
+
+# warn "I AM ".$ENV{'PROPHET_USER'};
+# warn $self->uuid;
+# warn $self->state_handle->uuid unless ($self->is_state_handle);
}
+#sub state_handle { return shift; }
+
sub _probe_or_create_db {
my $self = shift;
@@ -75,7 +81,6 @@
sub initialize {
my $self = shift;
my %args = validate( @_, { db_uuid => 0 } );
-
dir( $self->fs_root, $_ )->mkpath
for ($self->record_dir, $self->cas_root, $self->record_cas_dir, $self->changeset_cas_dir );
@@ -87,8 +92,8 @@
content => '1'
);
for(1..2) { # XXXX HORRIBLE HACK TO WORK AROUND THE FACT THAT SVN RECORDS EMPTY CHANGESETS
- $self->begin_edit;
- $self->commit_edit;
+ # $self->begin_edit;
+ # $self->commit_edit;
}
}
@@ -142,7 +147,6 @@
sub db_uuid {
my $self = shift;
$self->_db_uuid( $self->_read_file('database-uuid') ) unless $self->_db_uuid;
- debug($self->_db_uuid);
return $self->_db_uuid;
}
@@ -276,6 +280,11 @@
my $hash_changeset = $changeset->as_hash;
+
+ # Don't need to do this, since we clobber them below
+ delete $hash_changeset->{'sequence_no'};
+ delete $hash_changeset->{'source_uuid'};
+
my $content = YAML::Syck::Dump($hash_changeset);
my $cas_key = $self->_write_to_cas(
content_ref => \$content,
@@ -325,7 +334,9 @@
my $index_record = substr( $chgidx, ( $rev - 1 ) * CHG_RECORD_SIZE, CHG_RECORD_SIZE );
my ( $seq, $orig_uuid, $orig_seq, $key ) = unpack( 'Na16NH40', $index_record);
+
$orig_uuid = Data::UUID->new->to_string($orig_uuid);
+ debug("REV: $rev - seq $seq - original uuid $orig_uuid, original seq $orig_seq - data key $key");
# XXX: deserialize the changeset content from the cas with $key
my $casfile = file( $self->changeset_cas_dir, substr( $key, 0, 1 ), substr( $key, 1, 1 ), $key);
@@ -354,9 +365,6 @@
my $content_struct = YAML::Syck::Load( $args{content} );
my $changeset = Prophet::ChangeSet->new_from_hashref($content_struct);
- # Don't need to do this, since we clobber them below
- #delete $hash_changeset->{'sequence_no'};
- #delete $hash_changeset->{'source_uuid'};
$changeset->source_uuid( $self->uuid );
$changeset->sequence_no( $args{'sequence_no'} );
$changeset->original_source_uuid( $args{'original_source_uuid'} );
@@ -436,7 +444,6 @@
}
}
-sub state_handle { return shift } #XXX TODO better way to handle this?
sub begin_edit {
my $self = shift;
@@ -459,9 +466,14 @@
$self->current_edit->original_sequence_no($sequence) unless ($self->current_edit->original_sequence_no);
$self->current_edit->original_source_uuid($self->uuid) unless ($self->current_edit->original_source_uuid);
$self->current_edit->sequence_no($sequence);
+ $self->_write_changeset_to_index($self->current_edit);
+}
+sub _write_changeset_to_index {
+ my $self = shift;
+ my $changeset = shift;
my $handle = $self->_get_changeset_index_handle;
- $self->_write_changeset( index_handle => $handle, changeset => $self->current_edit );
+ $self->_write_changeset( index_handle => $handle, changeset => $changeset);
close($handle) || die "Failed to close changeset handle: ".$handle;
$self->current_edit(undef);
}
@@ -621,6 +633,6 @@
sub debug {
- warn shift if $ENV{'PROPHET_DEBUG'};
+ warn $ENV{'PROPHET_USER'}. " ". shift if $ENV{'PROPHET_DEBUG'};
}
1;
Modified: Prophet/trunk/t/export.t
==============================================================================
--- Prophet/trunk/t/export.t (original)
+++ Prophet/trunk/t/export.t Sat Apr 19 20:38:58 2008
@@ -42,7 +42,7 @@
'content is correct'
);
- my $path = Path::Class::dir->new( tempdir( CLEANUP => $ENV{TEST_VERBOSE} ) );
+ my $path = Path::Class::dir->new( tempdir( CLEANUP => ! $ENV{TEST_VERBOSE} ) );
run_ok( 'prophet', [ 'export', '--path', $path ] );
my $cli = Prophet::CLI->new;
@@ -57,6 +57,7 @@
my $latest = $path->file('latest-sequence-no')->slurp;
is( $latest, 5 );
use_ok('Prophet::Replica::Native');
+ diag("Checking changesets in $path");
my $changesets = Prophet::Replica->new( { url => 'prophet:file://' . $path } )->fetch_changesets( after => 0 );
is( $#{$changesets}, 4, "We found a total of 5 changesets" );
@@ -64,6 +65,5 @@
is( lc( $changesets->[-1]->{source_uuid} ), lc( $changesets->[-1]->{original_source_uuid} ) );
-
};
More information about the Bps-public-commit
mailing list