Changeset 25455

Show
Ignore:
Timestamp:
23.04.2012 11:00:25 (7 years ago)
Author:
jmt12
Message:

David suggested I try an explicit close on the underlying TDBCLI to ensure the harness can terminate properly

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • gs2-extensions/tdb-edit/trunk/src/bin/script/TDBServer.pl

    r25454 r25455  
    7777# Globally available - but once set these are read-only - so locking isn't 
    7878# an issue 
    79 my $use_harness = 0; 
     79my $use_harness = 1; 
    8080my $tdbexe = 'tdbcli'; 
    8181my $parent_pid = 0; 
     
    430430      my $record = '[' . $key . ']' . $action . $payload; 
    431431      # Open harness to TDBCLI 
     432      &debugPrint($the_count, $tid, 'TDBCLI', 'Opening harness'); 
    432433      my @tdb_command = ($tdbexe, $tdb_path, '-mid ' . $the_count); 
    433434      my $buffer_to_tdb = ''; 
     
    441442      # - write the data to the TDBCLI 
    442443      $buffer_to_tdb = $record . "\n"; 
    443       my $write_msg = '#' . $the_count . ' writing: |' . $record . '| => '; 
    444444      while (length($buffer_to_tdb)) 
    445445      { 
    446         $write_msg .='.'; 
    447446        pump($tdb_harness); 
    448447      } 
    449       print STDERR $write_msg . "\n"; 
    450448      # - read any response from TDBCLI 
    451       my $read_msg = '#' . $the_count . ' reading: '; 
     449      &debugPrint($the_count, $tid, 'TDBCLI', 'Reading'); 
    452450      while ($buffer_from_tdb !~ /-{70}/) 
    453451      { 
    454         $read_msg .= '.'; 
    455452        pump($tdb_harness); 
    456453      } 
    457       print STDERR $read_msg . ' => |' . $buffer_from_tdb . "|\n"; 
     454      # - explicitly tell the pipe to quit (empty key) 
     455      &debugPrint($the_count, $tid, 'TDBCLI', 'Closing'); 
     456      $buffer_to_tdb = "[]\n"; 
     457      while (length($buffer_to_tdb)) 
     458      { 
     459        pump($tdb_harness); 
     460      } 
    458461      # - not that this result doesn't include the [Server] prefix as it 
    459462      #   may be parsed for data by the client 
     
    461464      chomp($result); 
    462465      # Finished with harness 
     466      &debugPrint($the_count, $tid, 'TDBCLI', 'Finishing harness'); 
    463467      finish($tdb_harness); 
     468      &debugPrint($the_count, $tid, 'TDBCLI', 'Complete'); 
    464469    } 
    465470    # Use different TDB tools depending on arguments 
     
    467472    elsif ($action eq '?') 
    468473    { 
    469       my $command = 'tdbget "' . $tdb_path . '" "' . $key . '"'; 
    470       &debugPrint($the_count, $tid, 'TDBGET', 'Command: ' . $command); 
    471       my $result = `$command`; 
     474      my $command1 = 'tdbget "' . $tdb_path . '" "' . $key . '"'; 
     475      &debugPrint($the_count, $tid, 'TDBGET', 'Command: ' . $command1); 
     476      my $result = `$command1`; 
    472477      &debugPrint($the_count, $tid, 'TDBGET', 'Result: ' . $result); 
    473478      if ($result =~ /-{70}/) 
     
    479484    elsif ($action eq '+' || $action eq '-') 
    480485    { 
    481       my $command = 'txt2tdb "' . $tdb_path . '" -append'; 
    482       &debugPrint($the_count, $tid, 'TXT2TDB', 'Command: ' . $command); 
    483       open(my $infodb_handle, '| ' . $command) or die("Error! Failed to open pipe to TXT2TDB\n"); 
     486      my $command2 = 'txt2tdb "' . $tdb_path . '" -append'; 
     487      &debugPrint($the_count, $tid, 'TXT2TDB', 'Command: ' . $command2); 
     488      open(my $infodb_handle, '| ' . $command2) or die("Error! Failed to open pipe to TXT2TDB\n"); 
    484489      print $infodb_handle '[' . $key . ']'; 
    485490      if ($action eq '-')