Changeset 174 for trunk

Show
Ignore:
Timestamp:
06/29/10 22:20:01 (4 years ago)
Author:
depesz
Message:

First stage of refactoring

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/omnipitr/doc/changes.pod

    r173 r174  
    11=head1 OmniPITR 
     2 
     3=head2 2010-06-30 
     4 
     5=over 
     6 
     7=item * First part of refactoring the code 
     8 
     9=back 
    210 
    311=head2 2010-06-28 
  • trunk/omnipitr/lib/OmniPITR/Program.pm

    r131 r174  
    22use strict; 
    33use warnings; 
     4use English qw( -no_match_vars ); 
     5 
    46use OmniPITR::Log; 
    5 use English qw( -no_match_vars ); 
    67use OmniPITR::Pidfile; 
     8use File::Basename; 
     9use File::Path qw( mkpath ); 
     10use File::Spec; 
    711use Carp; 
    812 
     
    8488sub log { return shift->{ 'log' }; } 
    8589 
     90=head1 prepare_temp_directory() 
     91 
     92Helper function, which builds path for temp directory, and creates it. 
     93 
     94Path is generated by using given temp-dir and 'omnipitr-backup-master' named. 
     95 
     96For example, for temp-dir '/tmp' used temp directory would be /tmp/omnipitr-backup-master. 
     97 
     98If any arguments are passed - they are treated as subdirectories. For example, in above example, if ("xxx", "yyy") was passed, generated directory would be /tmp/omnipitr-backup-master/xxx/yyy. 
     99=cut 
     100 
     101sub prepare_temp_directory { 
     102    my $self = shift; 
     103    return if $self->{ 'temp-dir-prepared' }; 
     104    my @sub_elements = @_; 
     105    my $full_temp_dir = File::Spec->catfile( $self->{ 'temp-dir' }, basename( $PROGRAM_NAME ), @sub_elements ); 
     106    mkpath( $full_temp_dir ); 
     107    $self->{ 'temp-dir' }          = $full_temp_dir; 
     108    $self->{ 'temp-dir-prepared' } = $full_temp_dir; 
     109    return; 
     110} 
     111 
     112=head1 get_list_of_all_necessary_compressions() 
     113 
     114Scans list of destinations, and gathers list of all compressions that have to be made. 
     115 
     116This is to be able to compress file only once even when having multiple destinations that require compressed format. 
     117 
     118This function is used by all programs that need to compress "stuff" - L<omnipitr-archive>, L<omnipitr-backup-master> and L<omnipitr-backup-slave>. 
     119 
     120=cut 
     121 
     122sub get_list_of_all_necessary_compressions { 
     123    my $self = shift; 
     124 
     125    croak 'get_list_of_all_necessary_compressions() method called, but there are no destinations?!' unless $self->{ 'destination' }; 
     126 
     127    my %compression = (); 
     128 
     129    for my $dst_type ( qw( local remote ) ) { 
     130        next unless my $dsts = $self->{ 'destination' }->{ $dst_type }; 
     131        for my $destination ( @{ $dsts } ) { 
     132            $compression{ $destination->{ 'compression' } } = 1; 
     133        } 
     134    } 
     135 
     136    $self->{ 'compressions' } = [ keys %compression ]; 
     137 
     138    return; 
     139} 
     140 
    861411; 
    87142 
  • trunk/omnipitr/lib/OmniPITR/Program/Archive.pm

    r129 r174  
    2828    my $self = shift; 
    2929    $self->read_state(); 
    30     $self->prepare_temp_directory(); 
     30    $self->prepare_temp_directory( basename( $self->{ 'segment' } ) ); 
    3131    $self->make_all_necessary_compressions(); 
    3232    $self->send_to_destinations(); 
     
    121121} 
    122122 
    123 =head1 get_list_of_all_necessary_compressions() 
    124  
    125 Scans list of destinations, and gathers list of all compressions that have to be made. 
    126  
    127 This is to be able to compress file only once even when having multiple destinations that require compressed format. 
    128  
    129 =cut 
    130  
    131 sub get_list_of_all_necessary_compressions { 
    132     my $self = shift; 
    133  
    134     my %compression = (); 
    135  
    136     for my $dst_type ( qw( local remote ) ) { 
    137         next unless my $dsts = $self->{ 'destination' }->{ $dst_type }; 
    138         for my $destination ( @{ $dsts } ) { 
    139             $compression{ $destination->{ 'compression' } } = 1; 
    140         } 
    141     } 
    142     $self->{ 'compressions' } = [ grep { $_ ne 'none' } keys %compression ]; 
    143     return; 
    144 } 
    145  
    146123=head1 make_all_necessary_compressions() 
    147124 
     
    159136 
    160137    for my $compression ( @{ $self->{ 'compressions' } } ) { 
     138        next if 'none' eq $compression; 
    161139        next if $self->segment_already_compressed( $compression ); 
     140 
    162141        my $compressed_filename = $self->get_temp_filename_for( $compression ); 
    163142 
     
    220199 
    221200    return File::Spec->catfile( $self->{ 'temp-dir' }, basename( $self->{ 'segment' } ) . ext_for_compression( $type ) ); 
    222 } 
    223  
    224 =head1 prepare_temp_directory() 
    225  
    226 Helper function, which builds path for temp directory, and creates it. 
    227  
    228 Path is generated by using given temp-dir, 'omnipitr-archive' name, and filename of segment. 
    229  
    230 For example, for temp-dir '/tmp' and segment being pg_xlog/000000010000000000000003, actual, used temp directory would be /tmp/omnipitr-archive/000000010000000000000003/. 
    231  
    232 =cut 
    233  
    234 sub prepare_temp_directory { 
    235     my $self = shift; 
    236     my $full_temp_dir = File::Spec->catfile( $self->{ 'temp-dir' }, basename( $PROGRAM_NAME ), basename( $self->{ 'segment' } ) ); 
    237     mkpath( $full_temp_dir ); 
    238     $self->{ 'temp-dir' } = $full_temp_dir; 
    239     return; 
    240201} 
    241202 
  • trunk/omnipitr/lib/OmniPITR/Program/Backup/Master.pm

    r173 r174  
    531531    return unless $self->{ 'temp-dir-prepared' }; 
    532532    rmtree( [ $self->{ 'temp-dir-prepared' } ], 0 ); 
    533     return; 
    534 } 
    535  
    536 =head1 prepare_temp_directory() 
    537  
    538 Helper function, which builds path for temp directory, and creates it. 
    539  
    540 Path is generated by using given temp-dir and 'omnipitr-backup-master' named. 
    541  
    542 For example, for temp-dir '/tmp' used temp directory would be /tmp/omnipitr-backup-master. 
    543  
    544 =cut 
    545  
    546 sub prepare_temp_directory { 
    547     my $self = shift; 
    548     return if $self->{ 'temp-dir-prepared' }; 
    549     my $full_temp_dir = File::Spec->catfile( $self->{ 'temp-dir' }, basename( $PROGRAM_NAME ) ); 
    550     mkpath( $full_temp_dir ); 
    551     $self->{ 'temp-dir' }          = $full_temp_dir; 
    552     $self->{ 'temp-dir-prepared' } = $full_temp_dir; 
    553     return; 
    554 } 
    555  
    556 =head1 get_list_of_all_necessary_compressions() 
    557  
    558 Scans list of destinations, and gathers list of all compressions that have to be made. 
    559  
    560 This is to be able to compress file only once even when having multiple destinations that require compressed format. 
    561  
    562 =cut 
    563  
    564 sub get_list_of_all_necessary_compressions { 
    565     my $self = shift; 
    566  
    567     my %compression = (); 
    568  
    569     for my $dst_type ( qw( local remote ) ) { 
    570         next unless my $dsts = $self->{ 'destination' }->{ $dst_type }; 
    571         for my $destination ( @{ $dsts } ) { 
    572             $compression{ $destination->{ 'compression' } } = 1; 
    573         } 
    574     } 
    575     $self->{ 'compressions' } = [ keys %compression ]; 
    576533    return; 
    577534} 
  • trunk/omnipitr/lib/OmniPITR/Program/Backup/Slave.pm

    r173 r174  
    539539} 
    540540 
    541 =head1 prepare_temp_directory() 
    542  
    543 Helper function, which builds path for temp directory, and creates it. 
    544  
    545 Path is generated by using given temp-dir and 'omnipitr-backup-master' named. 
    546  
    547 For example, for temp-dir '/tmp' used temp directory would be /tmp/omnipitr-backup-master. 
    548  
    549 =cut 
    550  
    551 sub prepare_temp_directory { 
    552     my $self = shift; 
    553     return if $self->{ 'temp-dir-prepared' }; 
    554     my $full_temp_dir = File::Spec->catfile( $self->{ 'temp-dir' }, basename( $PROGRAM_NAME ) ); 
    555     mkpath( $full_temp_dir ); 
    556     $self->{ 'temp-dir' }          = $full_temp_dir; 
    557     $self->{ 'temp-dir-prepared' } = $full_temp_dir; 
    558     return; 
    559 } 
    560  
    561541=head1 choose_base_local_destinations() 
    562542 
     
    591571    } 
    592572 
    593     return; 
    594 } 
    595  
    596 =head1 get_list_of_all_necessary_compressions() 
    597  
    598 Scans list of destinations, and gathers list of all compressions that have to be made. 
    599  
    600 This is to be able to compress file only once even when having multiple destinations that require compressed format. 
    601  
    602 =cut 
    603  
    604 sub get_list_of_all_necessary_compressions { 
    605     my $self = shift; 
    606  
    607     my %compression = (); 
    608  
    609     for my $dst_type ( qw( local remote ) ) { 
    610         next unless my $dsts = $self->{ 'destination' }->{ $dst_type }; 
    611         for my $destination ( @{ $dsts } ) { 
    612             $compression{ $destination->{ 'compression' } } = 1; 
    613         } 
    614     } 
    615     $self->{ 'compressions' } = [ keys %compression ]; 
    616573    return; 
    617574} 
  • trunk/omnipitr/lib/OmniPITR/Program/Restore.pm

    r127 r174  
    88use OmniPITR::Tools qw( :all ); 
    99use English qw( -no_match_vars ); 
    10 use File::Basename; 
    1110use File::Spec; 
    1211use File::Path qw( mkpath rmtree ); 
     
    427426 
    428427    exit( $code ); 
    429 } 
    430  
    431 =head1 prepare_temp_directory() 
    432  
    433 Helper function, which builds path for temp directory, and creates it. 
    434  
    435 Path is generated by using given temp-dir and 'omnipitr-restore' name. 
    436  
    437 For example, for temp-dir '/tmp', actual, used temp directory would be /tmp/omnipitr-restore/. 
    438  
    439 =cut 
    440  
    441 sub prepare_temp_directory { 
    442     my $self = shift; 
    443     return if $self->{ 'temp-dir-prepared' }; 
    444     my $full_temp_dir = File::Spec->catfile( $self->{ 'temp-dir' }, basename( $PROGRAM_NAME ) ); 
    445     mkpath( $full_temp_dir ); 
    446     $self->{ 'temp-dir' }          = $full_temp_dir; 
    447     $self->{ 'temp-dir-prepared' } = 1; 
    448     return; 
    449428} 
    450429