Changeset 24429


Ignore:
Timestamp:
08/19/11 13:07:27 (10 years ago)
Author:
jmt12
Message:

Added code to support persistence of TDB connections in a pool, and some debug comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/tdb-edit/trunk/src/perllib/dbutil/tdb.pm

    r24069 r24429  
    3232
    3333# Libraries/Modules
     34use Cwd;
    3435use dbutil::gdbmtxtgz;
    3536
     
    3839# -----------------------------------------------------------------------------
    3940
     41our %handle_pool;
     42
     43END {
     44  # Close any handles left open in the pool
     45  foreach my $pool_key (keys %handle_pool)
     46  {
     47    my $infodb_file_handle = $handle_pool{$pool_key};
     48    close_infodb_write_handle($infodb_file_handle, 1);
     49  }
     50}
     51
    4052# /**
    4153#  */
     
    4456  my $program = shift(@_);
    4557  my $program_exe = &util::filename_cat($program . &util::get_os_exe());
    46   if (!-x $program_exe)
    47   {
    48     die('Fatal Error! File doesn\'t exist or isn\'t executable: ' . $program_exe);
    49   }
     58  #if (!-x $program_exe)
     59  #{
     60  #  die('Fatal Error! File doesn\'t exist or isn\'t executable: ' . $program_exe);
     61  #}
    5062  return $program_exe;
    5163}
    5264# /** get_tdb_executable() **/
    5365
     66
     67
    5468# /**
    5569#  */
     
    6175  my $txt2tdb_exe = &dbutil::tdb::get_tdb_executable('txt2tdb');
    6276
     77  my $pool_key = $infodb_file_path;
     78  #my $cmd = "taskset -c 5 \"$txt2tdb_exe\"";
    6379  my $cmd = "\"$txt2tdb_exe\"";
    6480  if ((defined $opt_append) && ($opt_append eq "append"))
    6581  {
    6682    $cmd .= " -append";
     83    $pool_key .= '-append';
    6784  }
    6885  $cmd .= " \"$infodb_file_path\"";
     86  #$cmd .= " -debug"; # Uncomment to enable debug timing
    6987
    7088  # we're going to pipe the key value pairs, in the appropriate format, from
    7189  # within the buildproc, so we create a piped handle here
    7290  my $infodb_file_handle = undef;
    73   if(!open($infodb_file_handle, "| $cmd"))
    74   {
    75     print STDERR "Error: Failed to open pipe to $cmd\n";
    76     print STDERR "       $!\n";
    77     return undef;
    78   }
    79 
    80   binmode($infodb_file_handle,":utf8");
    81 
     91  if (defined $handle_pool{$pool_key})
     92  {
     93    $infodb_file_handle = $handle_pool{$pool_key};
     94  }
     95  else
     96  {
     97    print STDERR "tdb::open_infodb_write_handle()\n";
     98    if(!open($infodb_file_handle, "| $cmd"))
     99    {
     100      print STDERR "Error: Failed to open pipe to $cmd\n";
     101      print STDERR "       $!\n";
     102      return undef;
     103    }
     104    binmode($infodb_file_handle,":utf8");
     105    $handle_pool{$pool_key} = $infodb_file_handle;
     106  }
    82107  return $infodb_file_handle;
    83108}
     
    89114{
    90115  my $infodb_handle = shift(@_);
    91   close($infodb_handle);
     116  my ($empty_pool) = @_;
     117  if (defined $empty_pool && $empty_pool == 1)
     118  {
     119    print STDERR "tdb::close_infodb_write_handle()\n";
     120    close($infodb_handle);
     121  }
    92122}
    93123# /** close_infodb_write_handle() **/
Note: See TracChangeset for help on using the changeset viewer.