Changeset 168

Show
Ignore:
Timestamp:
06/12/10 18:35:51 (4 years ago)
Author:
depesz
Message:

Fix one more ommission when dealing with pg < 8.4 - generally it is/was possible that last segment required for recovery wouldn't be in the backup.

Files:

Legend:

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

    r167 r168  
    11=head1 OmniPITR 
     2 
     3=head2 2010-06-12 
     4 
     5=over 
     6 
     7=item * Fix ommission in workaround for PostgreSQL 8.2 and 8.3 - regarding order 
     8of xlog segments. 
     9 
     10=back 
    211 
    312=head2 2010-06-10 
  • trunk/omnipitr/lib/OmniPITR/Program/Backup/Master.pm

    r167 r168  
    4747} 
    4848 
     49=head1 wait_for_file() 
     50 
     51Helper function which waits for file to appear. 
     52 
     53It will return only if the file appeared. 
     54 
     55Return value is name of file. 
     56 
     57=cut 
     58 
     59sub wait_for_file { 
     60    my $self = shift; 
     61    my ( $dir, $filename_regexp ) = @_; 
     62 
     63    my $max_wait = 3600;    # It's 1 hour. There is no technical need to wait longer. 
     64    for my $i ( 0 .. $max_wait ) { 
     65        $self->log->log( 'Waiting for file matching %s in directory %s', $filename_regexp, $dir ) if 10 == $i; 
     66 
     67        opendir( my $dh, $dir ) or $self->clean_and_die( 'Cannot open %s for scanning: %s', $dir, $OS_ERROR ); 
     68        my @matching = grep { $_ =~ $filename_regexp } readdir $dh; 
     69        closedir $dh; 
     70 
     71        if ( 0 == scalar @matching ) { 
     72            sleep 1; 
     73            next; 
     74        } 
     75 
     76        my $reply_filename = shift @matching; 
     77        $self->log->log( 'File %s arrived after %u seconds.', $reply_filename, $i ) if $self->verbose; 
     78        return $reply_filename; 
     79    } 
     80 
     81    $self->clean_and_die( 'Waited 1 hour for file matching %s, but it did not appear. Something is wrong. No sense in waiting longer.', $filename_regexp ); 
     82 
     83    return; 
     84} 
     85 
    4986=head1 wait_for_final_xlog_and_remove_dst_backup() 
    5087 
     
    5895    my $self = shift; 
    5996 
    60     my $search_in_dir = $self->{ 'xlogs' }
    61  
    62     my $re     = $self->{ 'stop_backup_filename_re' }
    63     my $waited = 0; 
    64     while ( 1 ) { 
    65         opendir( my $dir, $search_in_dir ) or $self->clean_and_die( 'Cannot open %s for scanning: %s', $search_in_dir, $OS_ERROR ); 
    66         my @matching = grep { $_ =~ $re } readdir $dir
    67         closedir $dir
    68         last if 0 < scalar @matching
    69         $waited++; 
    70         $self->clean_and_die( 'Waited 10 minutes for file matching %s, but it did not appear. Something is wrong. No sense in waiting longer.', $re ) if 600 < $waited
    71         sleep 1; 
    72     } 
    73  
    74     $self->log->log( '.backup file arrived after %u seconds.', $waited ) if $self->verbose
     97    my $backup_file = $self->wait_for_file( $self->{ 'xlogs' }, $self->{ 'stop_backup_filename_re' } )
     98 
     99    my $last_file = undef
     100 
     101    open my $fh, '<', File::Spec->catfile( $self->{ 'xlogs' }, $backup_file ) or $self->clean_and_die( 'Cannot open backup file %s for reading: %s', $backup_file, $OS_ERROR ); 
     102    while ( my $line = <$fh> ) { 
     103        next unless $line =~ m{\A STOP \s+ WAL \s+ LOCATION: .* file \s+ ( [0-9A-f]{24} ) }x
     104        $last_file = qr{\A$1\z}
     105        last
     106    } 
     107    close $fh
     108 
     109    $self->clean_and_die( '.backup file (%s) does not contain STOP WAL LOCATION line in recognizable format.', $backup_file ) unless $last_file; 
     110 
     111    $self->wait_for_file( $self->{ 'xlogs' }, $last_file )
    75112 
    76113    unlink( $self->{ 'xlogs' } );