- Timestamp:
- 2011-09-28T13:18:27+13:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gs2-extensions/parallel-building/trunk/src/perllib/dbutil/gdbmserver.pm
r24674 r24681 42 42 my $debug = 0; 43 43 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) 46 my %created_server_lockfile_paths; 47 # Keep track of the lockfiles for server we have added ourselves as listeners 48 # to. 49 my %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. 52 my %registered_listeners; 53 45 54 sub _spawnClient 46 55 { … … 95 104 } 96 105 # record this for later 97 $ server_lockfile_paths{$server_lockfile_path} = $infodb_file_path;106 $created_server_lockfile_paths{$server_lockfile_path} = 1; 98 107 } 99 108 flock(TMPFH, LOCK_UN); 100 109 close($tmp_lockfile_path); 101 110 unlink($tmp_lockfile_path); 111 # record this for later 112 $listener_server_lockfile_paths{$server_lockfile_path} = $infodb_file_path; 102 113 return GDBMClient->new($server_lockfile_path); 103 114 } … … 107 118 # we ask the server to shutdown, but only the 'creator' thread will actually 108 119 # 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}; 112 123 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 } 114 135 $gdbm_client_handle->query('!stop:' . $$); 115 136 } 116 # we should now wait until all of theserver_lockfiles have actually been137 # we should now wait until all of our server_lockfiles have actually been 117 138 # removed (otherwise people could mistakenly run import/build again 118 139 # 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)) 120 141 { 121 142 # While the file exists, we should wait … … 147 168 # Register this client on the server if necessary 148 169 $gdbm_client_handle->addListener('w'); 170 $registered_listeners{'w'} = 1; 149 171 # and pass the handle to client around 150 172 return $gdbm_client_handle; … … 156 178 { 157 179 my $gdbm_client_handle = shift(@_); 158 # we deregister as a listener159 $gdbm_client_handle->removeListener('w');160 180 } 161 181 # /** close_infodb_write_handle($infodb_handle) **/ … … 169 189 my $collection_name = shift(@_); 170 190 my $infodb_directory_path = shift(@_); 191 my $create_server = shift(@_); 171 192 172 193 my $infodb_file_extension = ".gdb"; 173 194 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; 175 208 } 176 209 … … 181 214 my $gdbm_client_handle = &_spawnClient($infodb_file_path); 182 215 $gdbm_client_handle->addListener('r'); 216 $registered_listeners{'r'} = 1; 183 217 # retrieves all the keys in the form: 184 218 # [key1]\n[key2]\n[key3]\n...[keyn] … … 196 230 } 197 231 } 198 # remove our listener199 $gdbm_client_handle->removeListener('r');200 232 } 201 233 … … 208 240 # register ourself as listener 209 241 $gdbm_client_handle->addListener('k'); 242 $registered_listeners{'k'} = 1; 210 243 # retrieves all the keys in the form: 211 244 # [key1]\n[key2]\n[key3]\n...[keyn] … … 219 252 } 220 253 } 221 # remove our listener222 $gdbm_client_handle->removeListener('k');223 254 } 224 255 … … 270 301 my $gdbm_client_handle = &_spawnClient($infodb_file_path); 271 302 $gdbm_client_handle->addListener('s'); 303 $registered_listeners{'s'} = 1; 272 304 # Protect metadata values that go inside quotes for gdbmset 273 305 foreach my $k (keys %$infodb_map) … … 297 329 # Send command to server 298 330 $gdbm_client_handle->query($gdbm_command); 299 # remove our listener300 $gdbm_client_handle->removeListener('s');301 331 } 302 332
Note:
See TracChangeset
for help on using the changeset viewer.