@@ -28,6 +28,9 @@ __PACKAGE__->mk_group_accessors('inherited' => qw/
28
28
_unsatisfied_deferred_constraints_autorollback
29
29
/ );
30
30
31
+ # I would change this to something that makes sense, like
32
+ # _autorollback_on_deferred_constraint_violation
33
+ # also setting it to an explicit 0 is silly
31
34
# see with_deferred_fk_checks
32
35
__PACKAGE__ -> _unsatisfied_deferred_constraints_autorollback(0);
33
36
@@ -863,6 +866,9 @@ in MySQL's case disabled entirely.
863
866
sub with_deferred_fk_checks {
864
867
my ($self , $sub ) = @_ ;
865
868
869
+ # now this has a lot of logic built in, including an unconditional
870
+ # try/catch block on top. If code ends up nesting with_deferred_fk_checks
871
+ # blocks - lots of crap will go wrong. We need a test for nesting too.
866
872
if ($self -> can(' _set_constraints_deferred' ) &&
867
873
$self -> can(' _set_constraints_immediate' )) {
868
874
@@ -871,6 +877,7 @@ sub with_deferred_fk_checks {
871
877
return try {
872
878
my $guard = $self -> txn_scope_guard;
873
879
$self -> _set_constraints_deferred;
880
+ # why { $sub->() } and not just $sub ?
874
881
preserve_context { $sub -> () } after => sub {
875
882
my $e ;
876
883
eval {
@@ -879,10 +886,22 @@ sub with_deferred_fk_checks {
879
886
if ($@ ) {
880
887
if ($self -> _unsatisfied_deferred_constraints_autorollback) {
881
888
$guard -> {inactivated } = 1; # DO NOT ROLLBACK
889
+
890
+ # *POSSIBLY* a code smell
891
+ # perhaps this shouldn't be here at all, ::Storage::txn_commit
892
+ # (which is called on all commits, including guards) should know to
893
+ # check for "am I in a deferred state" and "do I auto-rollback"
894
+ # and then do all the reductions on its own
882
895
$self -> {transaction_depth }--;
883
896
}
884
897
$e = $@ ;
885
898
}
899
+
900
+ # some engines (e.g. Pg) auto-unset deferred txns on rollback
901
+ # there should be an extra storage flag, and a provision to
902
+ # avoid this entire eval invoking a noop
903
+ # also the semantic is not clear what happens when an autorollback
904
+ # happens in the midst of a nested savepoint. Need more tests
886
905
eval {
887
906
$tried_to_reset_constraints = 1;
888
907
$self -> _set_constraints_immediate;
@@ -900,6 +919,8 @@ sub with_deferred_fk_checks {
900
919
}
901
920
catch {
902
921
my $e = $_ ;
922
+
923
+ # same commend as on the eval above
903
924
if (not $tried_to_reset_constraints ) {
904
925
eval {
905
926
$self -> _set_constraints_immediate;
0 commit comments