Changeset 24681

Show
Ignore:
Timestamp:
28.09.2011 13:18:27 (8 years ago)
Author:
jmt12
Message:

Made it so listeners are only removed when the object is deallocated (to ensure it sticks around for the entire import and build process assuming you have some top level script start the server/add the first listener). Extended get_infodb_file_path to do exactly that.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • gs2-extensions/parallel-building/trunk/src/perllib/dbutil/gdbmserver.pm

    r24674 r24681  
    4242my $debug = 0; 
    4343 
    44 my %server_lockfile_paths; 
     44# We have a global reference to all of the GDBM Server lockfiles that this 
     45# instance has created (as we'll be responsible for closing them) 
     46my %created_server_lockfile_paths; 
     47# Keep track of the lockfiles for server we have added ourselves as listeners 
     48# to. 
     49my %listener_server_lockfile_paths; 
     50# We also have a global of all of the listeners we have assigned as we'll 
     51# be responsible for removing them. 
     52my %registered_listeners; 
     53 
    4554sub _spawnClient 
    4655{ 
     
    95104    } 
    96105    # record this for later 
    97     $server_lockfile_paths{$server_lockfile_path} = $infodb_file_path; 
     106    $created_server_lockfile_paths{$server_lockfile_path} = 1; 
    98107  } 
    99108  flock(TMPFH, LOCK_UN); 
    100109  close($tmp_lockfile_path); 
    101110  unlink($tmp_lockfile_path); 
     111  # record this for later 
     112  $listener_server_lockfile_paths{$server_lockfile_path} = $infodb_file_path; 
    102113  return GDBMClient->new($server_lockfile_path); 
    103114} 
     
    107118  # we ask the server to shutdown, but only the 'creator' thread will actually 
    108119  # be able to, and only once all listeners have deregistered. 
    109   foreach my $server_lockfile_path (keys (%server_lockfile_paths)) 
    110   { 
    111     my $infodb_file_path = $server_lockfile_paths{$server_lockfile_path}; 
     120  foreach my $server_lockfile_path (keys (%listener_server_lockfile_paths)) 
     121  { 
     122    my $infodb_file_path = $listener_server_lockfile_paths{$server_lockfile_path}; 
    112123    my $gdbm_client_handle = GDBMClient->new($server_lockfile_path); 
    113     print "* Stopping GDBMServer for: " . $infodb_file_path . "\n"; 
     124    # Deregister all of our registered listeners 
     125    foreach my $listener_suffix (keys(%registered_listeners)) 
     126    { 
     127      $gdbm_client_handle->removeListener($listener_suffix); 
     128    } 
     129    # ask the servers we created to shut down (all other threads will have 
     130    # this request ignored) 
     131    if (defined $created_server_lockfile_paths{$infodb_file_path}) 
     132    { 
     133      print "* Attempting to stop GDBMServer for: " . $infodb_file_path . "\n"; 
     134    } 
    114135    $gdbm_client_handle->query('!stop:' . $$); 
    115136  } 
    116   # we should now wait until all of the server_lockfiles have actually been 
     137  # we should now wait until all of our server_lockfiles have actually been 
    117138  # removed (otherwise people could mistakenly run import/build again 
    118139  # immediately and things *might* go pearshaped). 
    119   foreach my $server_lockfile_path (keys (%server_lockfile_paths)) 
     140  foreach my $server_lockfile_path (keys (%created_server_lockfile_paths)) 
    120141  { 
    121142    # While the file exists, we should wait 
     
    147168  # Register this client on the server if necessary 
    148169  $gdbm_client_handle->addListener('w'); 
     170  $registered_listeners{'w'} = 1; 
    149171  # and pass the handle to client around 
    150172  return $gdbm_client_handle; 
     
    156178{ 
    157179  my $gdbm_client_handle = shift(@_); 
    158   # we deregister as a listener 
    159   $gdbm_client_handle->removeListener('w'); 
    160180} 
    161181# /** close_infodb_write_handle($infodb_handle) **/ 
     
    169189  my $collection_name = shift(@_); 
    170190  my $infodb_directory_path = shift(@_); 
     191  my $create_server = shift(@_); 
    171192 
    172193  my $infodb_file_extension = ".gdb"; 
    173194  my $infodb_file_name = &util::get_dirsep_tail($collection_name) . $infodb_file_extension; 
    174   return &util::filename_cat($infodb_directory_path, $infodb_file_name); 
     195  my $infodb_file_path = &util::filename_cat($infodb_directory_path, $infodb_file_name); 
     196 
     197  # Special Case for GDBMServer 
     198  if (defined $create_server && $create_server == 1) 
     199  { 
     200    my $gdbm_client_handle = &_spawnClient($infodb_file_path); 
     201    # Register this client on the server if necessary 
     202    $gdbm_client_handle->addListener('i'); 
     203    $registered_listeners{'i'} = 1; 
     204  } 
     205 
     206  # Resuming our regular programming 
     207  return $infodb_file_path; 
    175208} 
    176209 
     
    181214  my $gdbm_client_handle = &_spawnClient($infodb_file_path); 
    182215  $gdbm_client_handle->addListener('r'); 
     216  $registered_listeners{'r'} = 1; 
    183217  # retrieves all the keys in the form: 
    184218  # [key1]\n[key2]\n[key3]\n...[keyn] 
     
    196230    } 
    197231  } 
    198   # remove our listener 
    199   $gdbm_client_handle->removeListener('r'); 
    200232} 
    201233 
     
    208240  # register ourself as listener 
    209241  $gdbm_client_handle->addListener('k'); 
     242  $registered_listeners{'k'} = 1; 
    210243  # retrieves all the keys in the form: 
    211244  # [key1]\n[key2]\n[key3]\n...[keyn] 
     
    219252    } 
    220253  } 
    221   # remove our listener 
    222   $gdbm_client_handle->removeListener('k'); 
    223254} 
    224255 
     
    270301  my $gdbm_client_handle = &_spawnClient($infodb_file_path); 
    271302  $gdbm_client_handle->addListener('s'); 
     303  $registered_listeners{'s'} = 1; 
    272304  # Protect metadata values that go inside quotes for gdbmset 
    273305  foreach my $k (keys %$infodb_map) 
     
    297329  # Send command to server 
    298330  $gdbm_client_handle->query($gdbm_command); 
    299   # remove our listener 
    300   $gdbm_client_handle->removeListener('s'); 
    301331} 
    302332