Skip to content

Commit c0992bf

Browse files
committed
Comments on code
1 parent 26d54a1 commit c0992bf

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

lib/DBIx/Class/Storage/DBI.pm

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ __PACKAGE__->mk_group_accessors('inherited' => qw/
2828
_unsatisfied_deferred_constraints_autorollback
2929
/);
3030

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
3134
# see with_deferred_fk_checks
3235
__PACKAGE__->_unsatisfied_deferred_constraints_autorollback(0);
3336

@@ -863,6 +866,9 @@ in MySQL's case disabled entirely.
863866
sub with_deferred_fk_checks {
864867
my ($self, $sub) = @_;
865868

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.
866872
if ($self->can('_set_constraints_deferred') &&
867873
$self->can('_set_constraints_immediate')) {
868874

@@ -871,6 +877,7 @@ sub with_deferred_fk_checks {
871877
return try {
872878
my $guard = $self->txn_scope_guard;
873879
$self->_set_constraints_deferred;
880+
# why { $sub->() } and not just $sub ?
874881
preserve_context { $sub->() } after => sub {
875882
my $e;
876883
eval {
@@ -879,10 +886,22 @@ sub with_deferred_fk_checks {
879886
if ($@) {
880887
if ($self->_unsatisfied_deferred_constraints_autorollback) {
881888
$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
882895
$self->{transaction_depth}--;
883896
}
884897
$e = $@;
885898
}
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
886905
eval {
887906
$tried_to_reset_constraints = 1;
888907
$self->_set_constraints_immediate;
@@ -900,6 +919,8 @@ sub with_deferred_fk_checks {
900919
}
901920
catch {
902921
my $e = $_;
922+
923+
# same commend as on the eval above
903924
if (not $tried_to_reset_constraints) {
904925
eval {
905926
$self->_set_constraints_immediate;

lib/DBIx/Class/Storage/DBI/Informix.pm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,21 @@ sub _set_constraints_immediate {
5050
# fix it up here by doing a manual $dbh->do("COMMIT WORK"), propagating the
5151
# exception, and resetting the $dbh->{AutoCommit} attribute.
5252

53+
# this crap is now exeuted on *every* commit, be it deferred constraints or not
54+
# moreover there is no DBD version check - the workaround will remain here
55+
# forever and ever until someone decides to profile it
56+
# so far the general way of doing this was to use the current CPAN available
57+
# version, and keep bumping it as DBDs are released with the bug outstanding.
58+
# of course having an explicit test for this helps - we do not have one
5359
sub _exec_txn_commit {
5460
my $self = shift;
5561

5662
my $tried_resetting_autocommit = 0;
5763

5864
try {
65+
# what the fuck?! what's wrong with $dbh->commit for the *general* case?
66+
# where is the detailed comment explaining why the violation of DBI
67+
# internals? (the 2 lines above o not count as sufficient explanation)
5968
$self->_dbh->do('COMMIT WORK');
6069
if ($self->_dbh_autocommit && $self->transaction_depth == 1) {
6170
eval {

lib/DBIx/Class/Storage/DBI/Pg.pm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ sub _set_constraints_deferred {
3434
# transaction" so that they can be checked.
3535

3636
sub _set_constraints_immediate {
37+
# the semantic is not clear what happens when an autorollback happens in the
38+
# midst of a nested savepoint (txn_depth is set all the same). Moar tests
3739
$_[0]->_do_query('SET CONSTRAINTS ALL IMMEDIATE') if $_[0]->transaction_depth;
3840
}
3941

lib/DBIx/Class/Storage/DBI/mysql.pm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ __PACKAGE__->_use_multicolumn_in (1);
1717
# We turn FOREIGN_KEY_CHECKS off, do a transaction, then turn them back on right
1818
# before the COMMIT so that they can be checked during the COMMIT.
1919

20+
# nothing tests this hypothesis, why?
21+
2022
sub with_deferred_fk_checks {
2123
my ($self, $sub) = @_;
2224

0 commit comments

Comments
 (0)