Permalink
Browse files

More things than just UR::DataSource::RDBMS should be doing preparati…

…on prior to fork, so break this out into something generic.
  • Loading branch information...
Ben Oberkfell
Ben Oberkfell committed Feb 4, 2012
1 parent 279dd6e commit a6e36885a2ad459297cf75d2bf947e838c1db64a
Showing with 32 additions and 1 deletion.
  1. +5 −1 lib/UR/Context/Process.pm
  2. +19 −0 lib/UR/DataSource.pm
  3. +8 −0 lib/UR/DataSource/RDBMS.pm
@@ -443,7 +443,7 @@ sub fork
my @ds = values %data_source_for_class;
for (grep {defined $_} @ds) {
- $_->set_all_dbh_to_inactive_destroy if ($_->can('set_all_dbh_to_inactive_destroy'));
+ $_->prepare_for_fork if $_->can('prepare_for_fork');
}
my $pid = fork();
@@ -452,6 +452,10 @@ sub fork
$UR::Context::process = $class->_create_for_current_process
}
+ for (grep {defined $_} @ds) {
+ $_->finish_up_after_fork if $_->can('finish_up_after_fork');
+ }
+
return $pid;
}
View
@@ -749,4 +749,23 @@ sub ur_data_type_for_data_source_data_type {
}
+# This is a no-op in the base class. If the DataSource needs to do any
+# database handle disconnection or other housekeeping prior to a fork, this should be
+# the place to do it.
+sub prepare_for_fork {
+ my $self = shift;
+
+ die;
+ return 1;
+}
+
+# this is also a no-op here. If a DataSource needs to do any work after forking
+# this is the place for that. For example, a file based data source will need to
+# re-open the file and seek() to the location it was at before the fork happened.
+sub finish_up_after_fork {
+ my $self = shift;
+
+ return 1;
+}
+
1;
@@ -3191,6 +3191,14 @@ sub ur_data_type_for_data_source_data_type {
return $urtype;
}
+sub prepare_for_fork {
+ my $self = shift;
+
+ $self->set_all_dbh_to_inactive_destroy();
+
+ return 1;
+}
+
1;

0 comments on commit a6e3688

Please sign in to comment.