ClickHouse/Storage/TxnScopeGuard.pm

filter: Statementstmt 100% 30 / 30 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 93.3% 42 / 45 CC 5 SCAR 10.5
CC
5
Cov
92%
DESTROY
5.1
BEGIN
1.0
BEGIN
1.0
CRAP 2.9
« ClickHouse/DDL/Emit.pm ↑ Summary ClickHouse/Diff/Index.pm »
1 package DBIO::ClickHouse::Storage::TxnScopeGuard;
2 # ABSTRACT: Scope guard for a storage that has nothing to roll back
3  
4 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 16 our $VERSION = '0.900007';
8  
9 16 ▶use base 'DBIO::Storage::TxnScopeGuard';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 16 ▶use DBIO::Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 16 ▶use DBIO::Util qw(is_windows);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 16 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 24 ▶sub DESTROY {
Subroutine DESTROY: called CC=5 SCAR=16.3
17 24 my $self = shift;
18  
19 24 ▶ return if $self->{inactivated};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"inactivated"} 11 13 24
20 13 $self->{inactivated} = 1;
21  
22 # Same fork check core performs. When it fires it resets transaction_depth
23 # itself, which is why the early return below may skip the unwind.
24 13 ▶ $self->{storage}->_verify_pid unless is_windows;
Branch: 1 branch
BranchTrueFalseTotal
unless &is_windows() 13 0 13
25 13 ▶ return unless $self->{dbh};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"dbh"} 0 13 13
26  
27 # Unwind core's depth bookkeeping by hand. txn_rollback does this too, but
28 # it throws afterwards; a guard leaving scope is not a caller claiming work
29 # was undone. Left alone the depth would stick, and every later statement
30 # would believe it runs inside a transaction.
31 13 my $depth = $self->{storage}->transaction_depth;
32 13 ▶ $self->{storage}->transaction_depth($depth - 1) if $depth;
Branch: 1 branch
BranchTrueFalseTotal
if $depth 13 0 13
33  
34 # local() restores $@ when this scope exits, so an exception unwinding
35 # through here reaches its handler exactly as it was thrown -- including the
36 # case where carp() itself runs an eval.
37 13 local $@;
38  
39 13 carp(
40 'A transaction scope guard left scope without an explicit commit and '
41 . 'NOTHING WAS ROLLED BACK: ClickHouse has no transactions, so every '
42 . 'statement completed inside that scope is permanent. Check your data for '
43 . 'consistency'
44 );
45  
46 13 return;
47 }
48  
49  
50 16 1;
51  
52 __END__
« ClickHouse/DDL/Emit.pm ↑ Summary ClickHouse/Diff/Index.pm »