Changeset 24679


Ignore:
Timestamp:
2011-09-28T13:15:12+13:00 (13 years ago)
Author:
jmt12
Message:

Added code to determine the open file handles and persist them through the daemon fork (previously hardcoded - which failed to work when parallel importing) and extended debug information with timing and thread identifiers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/parallel-building/trunk/src/bin/script/GDBMServer.pl

    r24666 r24679  
    168168  #       after your desired function call (like start() below) and the
    169169  #       difference in hc_fd gives your new file descriptors in use! [jmt12]
    170 my $openmax = POSIX::sysconf( &POSIX::_SC_OPEN_MAX );
    171 $openmax = ( ! defined( $openmax ) || $openmax < 0 ) ? ( shift || 64 ) : $openmax;
    172 my $hc_fd = 2;
    173 foreach ( 3 .. $openmax )
    174 {
    175   $hc_fd = $_ if POSIX::close( $_ );
    176 }
    177 print "[debug] After start fd count = " . $hc_fd . "\n";
    178 exit(0);
     170  #my $openmax = POSIX::sysconf( &POSIX::_SC_OPEN_MAX );
     171  #$openmax = ( ! defined( $openmax ) || $openmax < 0 ) ? ( shift || 64 ) : $openmax;
     172  #my $hc_fd = 2;
     173  #foreach ( 3 .. $openmax )
     174  #{
     175  #  $hc_fd = $_ if POSIX::close( $_ );
     176  #}
     177  #print "[debug] After start fd count = " . $hc_fd . "\n";
     178  #exit(0);
    179179
    180180  # @note As mentioned above, I couldn't get the file handles produced by open2
     
    225225  #       these are fd 3, 4, 5, and 6.
    226226  $gdbm = start \@cmd, \$gdbm_writer, \$gdbm_reader;
     227  # - start opens four handles!
    227228
    228229  # Daemonize
     
    230231  if (!$no_daemon)
    231232  {
     233    # Determine the anonymous array of file descriptors *not* to close
     234    my $dont_close_fd = [];
     235    # Building upon the "POSIX::Close()" test above, we need to explicitly
     236    # determine the new file descriptors opened by the start command.
     237    my $openmax = POSIX::sysconf( &POSIX::_SC_OPEN_MAX );
     238    $openmax = ( ! defined( $openmax ) || $openmax < 0 ) ? ( shift || 64 ) : $openmax;
     239    # - then figure out the file descriptors currently open. We do this
     240    #   by attempting to 'copy' each file descriptor.
     241    for (my $fd = 3; $fd <= $openmax; $fd++)
     242    {
     243      #rint "Checking file descriptor: $fd -> ";
     244      my $tmpfh;
     245      if (open $tmpfh, ">&$fd")
     246      {
     247        #rint "writable!\n";
     248        push(@{$dont_close_fd}, $fd);
     249        close($tmpfh);
     250      }
     251      elsif (open $tmpfh, "<&$fd")
     252      {
     253        #rint "readable!\n";
     254        push(@{$dont_close_fd}, $fd);
     255        close($tmpfh);
     256      }
     257      #else
     258      #{
     259      #  print "not open\n";
     260      #}
     261    }
     262    print " * When forking don't close these filehandles: [" . join(",", @{$dont_close_fd}) . "]\n";
     263
    232264    print " * Spawning Daemon...\n" unless (!$debug);
    233265    my $daemon_out_path = &util::filename_cat($ENV{'GEXTPARALLELBUILDING'},'logs', 'gdbmserver-' . $infodb_file . '.out');
     
    238270  # @note as mentioned above, start creates four file descriptors that we need
    239271  #       to keep open even through the separation of the daemon process.
    240                                  dont_close_fd => [3,4,5,6]
     272                                 dont_close_fd => $dont_close_fd,
    241273                               } );
    242274  }
     
    330362{
    331363  my $data = shift @_;
     364  my $ip = shift @_;
     365  my $tid = shift @_;
    332366  my $value = "#ERROR#";
    333367  # Synchronized debug log writing
     
    336370    lock($debug_log);
    337371    $|++;
    338     print " << " . $data . "\n";
     372    print "[" . time() . "|" . $tid . "|RECV] " . $data . "\n";
    339373    $|--;
    340374  }
     
    437471    lock($debug_log);
    438472    $|++;
    439     print " >> " . $value . "\n\n";
     473    print "[" . time() . "|" . $tid . "|SEND] " . $value . "\n\n";
    440474    $|--;
    441475  }
Note: See TracChangeset for help on using the changeset viewer.