lib/Genezzo/Contrib/Clustered.pm

filter: Statementstmt 11.5% 66 / 573 Branchbran 0.0% 0 / 222 Conditioncond 0.0% 0 / 87 MC/DCmcdc 0.0% 0 / 48 Subroutinesub 30.2% 13 / 43 Podpod 17.8% 5 / 28 totaltotal 8.3% 84 / 1001 CC 141 SCAR 46.3
CC
141
Cov
7%
BufCaElt_DirtyBlock
272.0
_init
272.0
DirtyBlock
240.0
CRAP 103.0
↑ Summary lib/Genezzo/Contrib/Clustered/GLock/GLock.pm »
1 #
2 # copyright (c) 2005, Eric Rollins, all rights reserved, worldwide
3 #
4 #
5  
6 package Genezzo::Contrib::Clustered;
7  
8 #use 5.008004;
9 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use Genezzo::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 9 ▶use Genezzo::Block::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 9 ▶use Genezzo::Contrib::Clustered::GLock::GTXLock;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 9 ▶use Genezzo::Contrib::Clustered::GLock::GLock;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 9 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 9 ▶use FreezeThaw;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 9 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 9 ▶use Genezzo::Block::RDBlock;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 9 ▶use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 9 ▶use Carp qw(:DEFAULT cluck);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 9 our $VERSION = '0.34';
23  
24 9 our $ReadBlock_Hook;
25 9 our $DirtyBlock_Hook;
26 9 our $Commit_Hook;
27 9 our $Rollback_Hook;
28 9 our $Execute_Hook;
29  
30 # Constant blocks.
31 9 our $COMMITTED_BUFF;
32 9 our $ROLLEDBACK_BUFF;
33 9 our $PENDING_BUFF;
34 9 our $CLEAR_BUFF;
35  
36 9 our $COMMITTED_CODE;
37 9 our $ROLLEDBACK_CODE;
38 9 our $PENDING_CODE;
39 9 our $CLEAR_CODE;
40  
41 9 our $UNDO_BLOCKSIZE;
42  
43 # Can be set externally for testing.
44 9 our $starting_pid;
45 # If true pad out undo blocks to only fit two rows per block.
46 9 our $pad_undo;
47  
48 ####################################################################
49 # Called by BufCa::BCFile::_filewriteblock.
50 # Sets proc_num in block.
51 sub _init_filewriteblock
52 0 ▶{
Subroutine _init_filewriteblock: not called CC=8 SCAR=42.8
53 0 my $self = shift;
54 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
55  
56 0 my $cl_ctx = $self->{cl_ctx};
57 0 my ($wrapped_self, $fname, $fnum, $fh, $bnum, $refbuf, $hdrsize,
58 $bce) = @_;
59  
60 0 ▶ if(!defined($self->{init_done}) || !$self->{init_done}){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"init_done"} and $self->{"init_done"}) 0 0 0
Condition0%0/3
defined $self->{"init_done"} and $self->{"init_done"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"init_done"} and $self->{"init_done"}
defined $self->{"init_done"} $self->{"init_done"}
Truth table0%0/3
A and B
A= defined $self->{"init_done"}B= $self->{"init_done"}
ABresult
0X0
100
111
61 0 $self->_init();
62 }
63  
64 0 ▶ return 1
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bce 0 0 0
65 unless (defined($bce));
66  
67 0 my $bceInfo = $bce->GetInfo();
68  
69 0 ▶ return 1
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bceInfo 0 0 0
70 unless (defined($bceInfo));
71  
72 0 ▶ if (exists($bceInfo->{mailbox})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $bceInfo->{"mailbox"} and exists $bceInfo->{"mailbox"}{"Genezzo::Block::RDBlock"}) 0 0 0
Condition0%0/3
exists $bceInfo->{"mailbox"} and exists $bceInfo->{"mailbox"}{"Genezzo::Block::RDBlock"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $bceInfo->{"mailbox"} and exists $bceInfo->{"mailbox"}{"Genezzo::Block::RDBlock"}
exists $bceInfo->{"mailbox"} exists $bceInfo->{"mailbox"}{"Genezzo::Block::RDBlock"}
Truth table0%0/3
A and B
A= exists $bceInfo->{"mailbox"}B= exists $bceInfo->{"mailbox"}{"Genezzo::Block::RDBlock"}
ABresult
0X0
100
111
73 && exists($bceInfo->{mailbox}->{'Genezzo::Block::RDBlock'}))
74 {
75 0 my $rdblock = $bceInfo->{mailbox}->{'Genezzo::Block::RDBlock'};
76 0 $rdblock->_set_meta_row("PID", [$cl_ctx->{proc_num}]);
77 }
78  
79 0 return 1;
80 }
81  
82 ####################################################################
83 # Replaces Genezzo::BufCa::BCFile::_filereadblock.
84 sub ReadBlock
85 0 ▶{
Subroutine ReadBlock: not called CC=9 SCAR=45.0
Pod documented
86 0 my $self = shift;
87 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
88 0 my ($wrapped_self, $fname, $fnum, $fh, $bnum, $refbuf_in, $hdrsize) = @_;
89  
90 0 whisper "Genezzo::Contrib::Clustered::ReadBlock(filenum => $fnum, blocknum => $bnum)\n";
91 #print STDERR "Genezzo::Contrib::Clustered::ReadBlock(filenum => $fnum, blocknum => $bnum)\n";
92  
93 0 ▶ if(!defined($self->{init_done}) || !$self->{init_done}){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"init_done"} and $self->{"init_done"}) 0 0 0
Condition0%0/3
defined $self->{"init_done"} and $self->{"init_done"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"init_done"} and $self->{"init_done"}
defined $self->{"init_done"} $self->{"init_done"}
Truth table0%0/3
A and B
A= defined $self->{"init_done"}B= $self->{"init_done"}
ABresult
0X0
100
111
94 0 $self->_init();
95 }
96  
97 0 my $gtxLock = $self->{cl_ctx}->{gtxLock};
98 # Add in fnum later...
99 0 $gtxLock->lock(lock => $bnum, shared => 1);
100
101 # Avoid processing DirtyBlock during read.
102 0 $self->{inReadBlock} = 1;
103  
104 0 my ($block_pid, $refbuf, $blocksize) =
105 $self->GetBlockWithPID($fnum, $bnum);
106  
107 0 ▶ if(($block_pid != 0) && ($block_pid != $self->{cl_ctx}->{proc_num})){
Branch: 1 branch
BranchTrueFalseTotal
if ($block_pid != 0 and $block_pid != $self->{"cl_ctx"}{"proc_num"}) 0 0 0
Condition0%0/3
$block_pid != 0 and $block_pid != $self->{"cl_ctx"}{"proc_num"}
!ll&&!rl&&r
000
MC/DC0%0/2
$block_pid != 0 and $block_pid != $self->{"cl_ctx"}{"proc_num"}
$block_pid != 0 $block_pid != $self->{"cl_ctx"}{"proc_num"}
Truth table0%0/3
A and B
A= $block_pid != 0B= $block_pid != $self->{"cl_ctx"}{"proc_num"}
ABresult
0X0
100
111
108 # Need to rollback or commit the block.
109 # Promote lock to EX.
110 0 $gtxLock->lock(lock => $bnum, shared => 0);
111  
112 0 my $block_tx_state = $ROLLEDBACK_CODE;
113  
114 0 ▶ if($block_pid != -1){
Branch: 1 branch
BranchTrueFalseTotal
if ($block_pid != -1) 0 0 0
115 # We can read state unlocked, since if tx was in progress
116 # block would be locked (&& it is a single-char read).
117 0 my $block_tx_state = $self->ReadTransactionState($block_pid);
118 }
119
120 0 ▶ if(($block_tx_state eq $COMMITTED_CODE)||
Branch: 1 branch
BranchTrueFalseTotal
if ($block_tx_state eq $Genezzo::Contrib::Clustered::COMMITTED_CODE or $block_tx_state eq $Genezzo::Contrib::Clustered::CLEAR_CODE) { } 0 0 0
Condition0%0/3
$block_tx_state eq $Genezzo::Contrib::Clustered::COMMITTED_CODE or $block_tx_state eq $Genezzo::Contrib::Clustered::CLEAR_CODE
l!l&&r!l&&!r
000
MC/DC0%0/2
$block_tx_state eq $Genezzo::Contrib::Clustered::COMMITTED_CODE or $block_tx_state eq $Genezzo::Contrib::Clustered::CLEAR_CODE
$block_tx_state eq $Genezzo::Contrib::Clustered::COMMITTED_CODE $block_tx_state eq $Genezzo::Contrib::Clustered::CLEAR_CODE
Truth table0%0/3
A or B
A= $block_tx_state eq $Genezzo::Contrib::Clustered::COMMITTED_CODEB= $block_tx_state eq $Genezzo::Contrib::Clustered::CLEAR_CODE
ABresult
1X1
011
000
121 ($block_tx_state eq $CLEAR_CODE)) # shouldn't have PID!
122 {
123 0 $self->ClearPID($fnum, $bnum, $refbuf, $blocksize);
124 0 $self->ReadOrWriteBlock($fnum, $bnum, "WRITE_TAIL", $refbuf);
125 0 $self->ReadOrWriteBlock($fnum, $bnum, "WRITE", $refbuf);
126 }else{
127 # ROLLEDBACK_CODE || PENDING_CODE
128 0 $refbuf = $self->CopyBlockToOrFromTail($fnum,$bnum,"FROM");
129 }
130 }
131  
132 0 my $ret = 1;
133 # $ret = &$ReadBlock_Hook(@_);
134 # For now we don't read (above) directly into $refbuf_in, as
135 # I'm not sure if buf can be tied to RDBlock multiple times
136 # (in GetBlockWithPID).
137 0 $$refbuf_in = $$refbuf;
138  
139 0 $self->{inReadBlock} = 0;
140  
141 0 return $ret;
142 }
143  
144 ####################################################################
145 # Wraps Genezzo::BufCa::DirtyScalar::STORE.
146 sub DirtyBlock
147 0 ▶{
Subroutine DirtyBlock: not called CC=15 SCAR=54.8
Pod documented
148 0 my $self = shift;
149 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
150 0 my $cl_ctx = $self->{cl_ctx};
151  
152 0 my $h;
153 my $dirty;
154  
155 0 ▶ if($_[0]->{bce}){
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{"bce"}) 0 0 0
156 0 $h = $_[0]->{bce}->GetInfo();
157 # Can't rely on dirty to make decisions, since it is cleared
158 # whenever block is written out of buffer cache
159 # (on cache full, sync, etc.).
160 0 $dirty = $_[0]->{bce}->_dirty();
161 }
162  
163 0 ▶ if(!defined($self->{init_done}) || !$self->{init_done}){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"init_done"} and $self->{"init_done"}) 0 0 0
Condition0%0/3
defined $self->{"init_done"} and $self->{"init_done"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"init_done"} and $self->{"init_done"}
defined $self->{"init_done"} $self->{"init_done"}
Truth table0%0/3
A and B
A= defined $self->{"init_done"}B= $self->{"init_done"}
ABresult
0X0
100
111
164 0 $self->_init();
165 }
166
167 0 ▶ if(!$self->{inReadBlock} &&
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"inReadBlock"} and defined $h and not defined $h->{"filenum"} && defined $h->{"blocknum"}) 0 0 0
Condition0%0/9
not $self->{"inReadBlock"} and defined $h and not defined $h->{"filenum"} && defined $h->{"blocknum"}
!ll&&!rl&&r
000
not $self->{"inReadBlock"} and defined $h
!ll&&!rl&&r
000
defined $h->{'filenum'} && defined $h->{'blocknum'}
!ll&&!rl&&r
000
MC/DC0%0/4
not $self->{"inReadBlock"} and defined $h and not defined $h->{"filenum"} && defined $h->{"blocknum"}
not $self->{"inReadBlock"} defined $h defined $h->{'filenum'} defined $h->{'blocknum'}
Truth table0%0/5
not(A) and B and not(C && D)
A= not $self->{"inReadBlock"}B= defined $hC= defined $h->{'filenum'}D= defined $h->{'blocknum'}
ABCDresult
0XXX0
10XX0
11110
110X1
11101
168 defined($h) &&
169 ((!(defined($h->{filenum}))) || (!(defined($h->{blocknum})))))
170 {
171 # One cause is in-memory index initialization.
172 # Dict::_loadDictMemStructs=>Index::btHash::STORE...
173 #whisper
174 # "G:C:C::DirtyBlock bad undefined ($self->{inReadBlock})\n";
175 #cluck "bad undefined";
176 }
177  
178 0 ▶ if(!$self->{inReadBlock} &&
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"inReadBlock"} and defined $h and defined $h->{"filenum"} and defined $h->{"blocknum"}) 0 0 0
Condition0%0/9
not $self->{"inReadBlock"} and defined $h and defined $h->{"filenum"} and defined $h->{"blocknum"}
!ll&&!rl&&r
000
not $self->{"inReadBlock"} and defined $h and defined $h->{"filenum"}
!ll&&!rl&&r
000
not $self->{"inReadBlock"} and defined $h
!ll&&!rl&&r
000
MC/DC0%0/4
not $self->{"inReadBlock"} and defined $h and defined $h->{"filenum"} and defined $h->{"blocknum"}
not $self->{"inReadBlock"} defined $h defined $h->{"filenum"} defined $h->{"blocknum"}
Truth table0%0/5
not(A) and B and C and D
A= not $self->{"inReadBlock"}B= defined $hC= defined $h->{"filenum"}D= defined $h->{"blocknum"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
179 defined($h) &&
180 defined($h->{filenum}) && defined($h->{blocknum}))
181 {
182 0 whisper "Genezzo::Contrib::Clustered::DirtyBlock(filenum => $h->{filenum}, blocknum => $h->{blocknum}, dirty => $dirty)\n";
183 #print STDERR "Genezzo::Contrib::Clustered::DirtyBlock(filenum => $h->{filenum}, blocknum => $h->{blocknum}, dirty => $dirty)\n";
184  
185 0 my $blockKey = $h->{filenum} . "_" . $h->{blocknum};
186  
187 0 ▶ if(!defined($cl_ctx->{dirty_blocks}->{$blockKey})){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $cl_ctx->{"dirty_blocks"}{$blockKey}) 0 0 0
188 0 ▶ if(!($cl_ctx->{have_begin_trans})){
Branch: 1 branch
BranchTrueFalseTotal
unless ($cl_ctx->{"have_begin_trans"}) 0 0 0
189 0 $self->BeginTransaction();
190 0 $cl_ctx->{have_begin_trans} = 1;
191 }
192  
193 0 whisper "adding blockKey $blockKey\n";
194 $cl_ctx->{dirty_blocks}->{$blockKey} = { f => $h->{filenum},
195 0 b => $h->{blocknum}};
196  
197 0 my $gtxLock = $cl_ctx->{gtxLock};
198 # add in fnum later...
199 0 $gtxLock->lock(lock => $h->{blocknum}, shared => 0);
200  
201 0 $self->CopyBlockToOrFromTail($h->{filenum}, $h->{blocknum}, "TO");
202 0 $self->AddAndWriteUndo($h->{filenum}, $h->{blocknum});
203 }
204 }
205  
206 0 return &$DirtyBlock_Hook(@_);
207 }
208  
209 ####################################################################
210 # DOES NOT WORK; NOT CURRENTLY USED
211 # Called by BufCa::BufCaElt::_dirty
212 sub BufCaElt_DirtyBlock
213 0 ▶{
Subroutine BufCaElt_DirtyBlock: not called CC=16 SCAR=56.1
Pod undocumented
214 0 my $self = shift;
215 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
216 0 my $cl_ctx = $self->{cl_ctx};
217  
218 0 my $h;
219 my $dirty;
220 0 my $bce = shift;
221  
222 0 ▶ if($bce){
Branch: 1 branch
BranchTrueFalseTotal
if ($bce) 0 0 0
223 0 $h = $bce->GetInfo();
224  
225 # Can't rely on dirty to make decisions, since it is cleared
226 # whenever block is written out of buffer cache
227 # (on cache full, sync, etc.).
228 0 $dirty = $bce->{dirty};
229  
230 0 ▶ if(!$dirty){
Branch: 1 branch
BranchTrueFalseTotal
unless ($dirty) 0 0 0
231 0 return;
232 }
233 }
234  
235 0 ▶ if(!defined($self->{init_done}) || !$self->{init_done}){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"init_done"} and $self->{"init_done"}) 0 0 0
Condition0%0/3
defined $self->{"init_done"} and $self->{"init_done"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"init_done"} and $self->{"init_done"}
defined $self->{"init_done"} $self->{"init_done"}
Truth table0%0/3
A and B
A= defined $self->{"init_done"}B= $self->{"init_done"}
ABresult
0X0
100
111
236 0 $self->_init();
237 }
238
239 0 ▶ if(!$self->{inReadBlock} &&
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"inReadBlock"} and defined $h and not defined $h->{"filenum"} && defined $h->{"blocknum"}) 0 0 0
Condition0%0/9
not $self->{"inReadBlock"} and defined $h and not defined $h->{"filenum"} && defined $h->{"blocknum"}
!ll&&!rl&&r
000
not $self->{"inReadBlock"} and defined $h
!ll&&!rl&&r
000
defined $h->{'filenum'} && defined $h->{'blocknum'}
!ll&&!rl&&r
000
MC/DC0%0/4
not $self->{"inReadBlock"} and defined $h and not defined $h->{"filenum"} && defined $h->{"blocknum"}
not $self->{"inReadBlock"} defined $h defined $h->{'filenum'} defined $h->{'blocknum'}
Truth table0%0/5
not(A) and B and not(C && D)
A= not $self->{"inReadBlock"}B= defined $hC= defined $h->{'filenum'}D= defined $h->{'blocknum'}
ABCDresult
0XXX0
10XX0
11110
110X1
11101
240 defined($h) &&
241 ((!(defined($h->{filenum}))) || (!(defined($h->{blocknum})))))
242 {
243 # One cause is in-memory index initialization.
244 # Dict::_loadDictMemStructs=>Index::btHash::STORE...
245 #whisper
246 # "G:C:C::DirtyBlock bad undefined ($self->{inReadBlock})\n";
247 #cluck "bad undefined";
248 }
249  
250 0 ▶ if(!$self->{inReadBlock} &&
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"inReadBlock"} and defined $h and defined $h->{"filenum"} and defined $h->{"blocknum"}) 0 0 0
Condition0%0/9
not $self->{"inReadBlock"} and defined $h and defined $h->{"filenum"} and defined $h->{"blocknum"}
!ll&&!rl&&r
000
not $self->{"inReadBlock"} and defined $h and defined $h->{"filenum"}
!ll&&!rl&&r
000
not $self->{"inReadBlock"} and defined $h
!ll&&!rl&&r
000
MC/DC0%0/4
not $self->{"inReadBlock"} and defined $h and defined $h->{"filenum"} and defined $h->{"blocknum"}
not $self->{"inReadBlock"} defined $h defined $h->{"filenum"} defined $h->{"blocknum"}
Truth table0%0/5
not(A) and B and C and D
A= not $self->{"inReadBlock"}B= defined $hC= defined $h->{"filenum"}D= defined $h->{"blocknum"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
251 defined($h) &&
252 defined($h->{filenum}) && defined($h->{blocknum}))
253 {
254 0 whisper "Genezzo::Contrib::Clustered::DirtyBlock(filenum => $h->{filenum}, blocknum => $h->{blocknum}, dirty => $dirty)\n";
255 #print STDERR "Genezzo::Contrib::Clustered::DirtyBlock(filenum => $h->{filenum}, blocknum => $h->{blocknum}, dirty => $dirty)\n";
256  
257 0 my $blockKey = $h->{filenum} . "_" . $h->{blocknum};
258  
259 0 ▶ if(!defined($cl_ctx->{dirty_blocks}->{$blockKey})){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $cl_ctx->{"dirty_blocks"}{$blockKey}) 0 0 0
260 0 ▶ if(!($cl_ctx->{have_begin_trans})){
Branch: 1 branch
BranchTrueFalseTotal
unless ($cl_ctx->{"have_begin_trans"}) 0 0 0
261 0 $self->BeginTransaction();
262 0 $cl_ctx->{have_begin_trans} = 1;
263 }
264  
265 0 whisper "adding blockKey $blockKey\n";
266 $cl_ctx->{dirty_blocks}->{$blockKey} = { f => $h->{filenum},
267 0 b => $h->{blocknum}};
268  
269 0 my $gtxLock = $cl_ctx->{gtxLock};
270 # add in fnum later...
271 0 $gtxLock->lock(lock => $h->{blocknum}, shared => 0);
272  
273 0 $self->CopyBlockToOrFromTail($h->{filenum}, $h->{blocknum}, "TO");
274 0 $self->AddAndWriteUndo($h->{filenum}, $h->{blocknum});
275 }
276 }
277 }
278  
279 ####################################################################
280 sub ClearPID
281 0 ▶{
Subroutine ClearPID: not called CC=3 SCAR=24.8
Pod undocumented
282 0 my ($self, $fnum, $bnum, $refbuf, $blocksize) = @_;
283 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
284  
285 0 ▶ if(!$self->VerifyChecksum($refbuf, $blocksize)){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->VerifyChecksum($refbuf, $blocksize)) 0 0 0
286 0 return; # Don't mess with corrupted block.
287 }
288  
289 0 my %tied_hash = ();
290 0 my $tie_val =
291 tie %tied_hash, 'Genezzo::Block::RDBlock', (refbufstr => $refbuf,
292 blocksize => $blocksize);
293 0 $tie_val->_set_meta_row("PID", [0]);
294 0 $self->UpdateChecksum($fnum, $bnum, $refbuf, $blocksize);
295 }
296  
297 ####################################################################
298 # Passed to ApplyFuncToUndo.
299 sub CommitFunc
300 0 ▶{
Subroutine CommitFunc: not called CC=4 SCAR=30.0
Pod undocumented
301 0 my ($self, $fileno, $blockno) = @_;
302 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
303 0 my $affected = 0;
304  
305 0 my $gtxLock = $self->{cl_ctx}->{gtxLock}; # Locks needed for startup case;
306 # otherwise redundant.
307 # Lock block SH.
308 0 $gtxLock->lock(lock => $blockno, shared => 1);
309  
310 0 my ($data_block_pid, $refbuf, $blocksize) =
311 $self->GetBlockWithPID($fileno, $blockno);
312  
313 0 ▶ if($data_block_pid == $self->{cl_ctx}->{proc_num})
Branch: 2 branches
BranchTrueFalseTotal
if ($data_block_pid == $self->{'cl_ctx'}{'proc_num'}) { } 0 0 0
elsif ($data_block_pid == -1) { } 0 0 0
314 {
315 # Only commit your own PID, as someone else (in crash case)
316 # may have already recovered and used block.
317 # Promote lock to EX.
318 0 $gtxLock->lock(lock => $blockno, shared => 0);
319 0 $self->ClearPID($fileno, $blockno, $refbuf, $blocksize);
320 0 $self->ReadOrWriteBlock($fileno, $blockno, "WRITE_TAIL", $refbuf);
321 0 $self->ReadOrWriteBlock($fileno, $blockno, "WRITE", $refbuf);
322 0 $affected = 1;
323 }elsif($data_block_pid == -1){
324 # Promote lock to EX.
325 0 $gtxLock->lock(lock => $blockno, shared => 0);
326 # before-image should contain desired data
327 0 $self->CopyBlockToOrFromTail($fileno,$blockno,"FROM");
328 0 $affected = 1;
329 }
330  
331 # At startup could release each lock here.
332 0 return $affected;
333 }
334  
335 ####################################################################
336 # Wraps Genezzo::GenDBI::Kgnz_Execute.
337 # Experimental; trying out catching deadlock error.
338 sub Execute
339 0 ▶{
Subroutine Execute: not called CC=4 SCAR=30.0
Pod documented
340 0 my $self = shift;
341 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
342 0 my $ret;
343  
344 0 eval {
345 0 $ret = &$Execute_Hook(@_);
346 };
347  
348 0 ▶ if($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
349 0 ▶ if($@ =~ /DEADLOCK/){
Branch: 1 branch
BranchTrueFalseTotal
if ($@ =~ /DEADLOCK/) { } 0 0 0
350 0 print STDERR "ERROR: Deadlock has occurred. Exiting...\n";
351 0 CORE::exit();
352 }else{
353 0 die $@;
354 }
355 }
356  
357 0 return $ret;
358 }
359  
360 ####################################################################
361 # Wraps Genezzo::GenDBI::Kgnz_Commit.
362 sub Commit
363 0 ▶{
Subroutine Commit: not called CC=4 SCAR=30.0
Pod documented
364 0 my $self = shift;
365 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
366 0 my $cl_ctx = $self->{cl_ctx};
367  
368 0 whisper "Genezzo::Contrib::Clustered::Commit()\n";
369  
370 0 my @tmpArgs = @_;
371 0 my $wrapped_self = shift @tmpArgs;
372  
373 0 ▶ if(!defined($self->{init_done}) || !$self->{init_done}){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"init_done"} and $self->{"init_done"}) 0 0 0
Condition0%0/3
defined $self->{"init_done"} and $self->{"init_done"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"init_done"} and $self->{"init_done"}
defined $self->{"init_done"} $self->{"init_done"}
Truth table0%0/3
A and B
A= defined $self->{"init_done"}B= $self->{"init_done"}
ABresult
0X0
100
111
374 0 $self->_init();
375 }
376  
377 # Assume this writes all blocks in buffer cache to disk.
378 0 my $ret = &$Commit_Hook(@_);
379  
380 0 $self->WriteTransactionState($COMMITTED_BUFF);
381  
382 # Could use $cl_ctx->{dirty_blocks} to find all affected blocks.
383 # For Now use undo from disk.
384 # Clear undo proc id in all blocks.
385 0 $self->ApplyFuncToUndo(\&CommitFunc);
386  
387 # TODO: Release all blocks in buffer cache (how?).
388  
389 0 my $gtxLock = $self->{cl_ctx}->{gtxLock};
390 # Current buffer cache doesn't release blocks on commit, so
391 # demote instead of release all locks.
392 # $gtxLock->unlockAll();
393 0 $gtxLock->demoteAll();
394 0 $cl_ctx->{dirty_blocks} = {};
395  
396 0 $self->ResetUndo();
397 0 $self->WriteTransactionState($CLEAR_BUFF);
398 0 $self->{cl_ctx}->{have_begin_trans} = 0;
399  
400 0 return $ret;
401 }
402  
403 ####################################################################
404 # Wraps Genezzo::GenDBI::Kgnz_Rollback.
405 sub Rollback
406 0 ▶{
Subroutine Rollback: not called CC=4 SCAR=30.0
Pod documented
407 0 my $self = shift;
408 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
409 0 my $cl_ctx = $self->{cl_ctx};
410  
411 0 whisper "Genezzo::Contrib::Clustered::Rollback()\n";
412  
413 0 my @tmpArgs = @_;
414 0 my $wrapped_self = shift @tmpArgs;
415  
416 0 ▶ if(!defined($self->{init_done}) || !$self->{init_done}){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"init_done"} and $self->{"init_done"}) 0 0 0
Condition0%0/3
defined $self->{"init_done"} and $self->{"init_done"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"init_done"} and $self->{"init_done"}
defined $self->{"init_done"} $self->{"init_done"}
Truth table0%0/3
A and B
A= defined $self->{"init_done"}B= $self->{"init_done"}
ABresult
0X0
100
111
417 0 $self->_init();
418 }
419  
420 0 $self->WriteTransactionState($ROLLEDBACK_BUFF);
421  
422 0 $self->Rollback_Internal();
423  
424 0 $self->ResetUndo();
425 0 $self->WriteTransactionState($CLEAR_BUFF);
426 0 $cl_ctx->{have_begin_trans} = 0;
427  
428 0 my $gtxLock = $self->{cl_ctx}->{gtxLock};
429 0 $gtxLock->unlockAll();
430 0 $cl_ctx->{dirty_blocks} = {};
431  
432 0 my $ret = &$Rollback_Hook(@_);
433  
434 # We shouldn't be generating bogus undo anymore.
435 # Leave this in just in case.
436 0 $self->ResetUndo();
437 0 $self->WriteTransactionState($CLEAR_BUFF);
438 0 $cl_ctx->{have_begin_trans} = 0;
439 0 $cl_ctx->{dirty_blocks} = {};
440 # We have accumulated more locks during the rollback.
441 # These proctect the dictionary tables which were reloaded.
442 # They also include block zero (directory & space management), etc.
443 # TODO: We can't free the locks, as the blocks would be unprotected.
444 #$gtxLock->unlockAll();
445 0 $gtxLock->demoteAll();
446  
447 0 return $ret;
448 }
449  
450 ####################################################################
451 # For each block in undo, for each row in block, apply func.
452 sub ApplyFuncToUndo
453 0 ▶{
Subroutine ApplyFuncToUndo: not called CC=9 SCAR=45.0
Pod undocumented
454 0 my ($self, $func) = @_;
455 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
456 # func takes args of form: my ($self, $fileno, $blockno) = @_;
457 0 my $affected = 0;
458 0 my $cl_ctx = $self->{cl_ctx};
459  
460 0 whisper "Genezzo::Contrib::Clustered::ApplyFuncToUndo()\n";
461 # For each block in undo, for each row in block, apply func.
462 0 my $undo_blockid;
463 my $tx_id;
464  
465 0 ▶ for($undo_blockid = 0;
Branch: 1 branch
BranchTrueFalseTotal
if ($undo_blockid < $cl_ctx->{"undoHeader"}{"blocks_per_proc"} / 2) 0 0 0
466 $undo_blockid < ($cl_ctx->{undoHeader}->{blocks_per_proc})/2;
467 $undo_blockid++)
468 {
469 # TODO: Read both of paired undo blocks and choose good one.
470 0 whisper
471 "G:C:C:ApplyFuncToUndo undo_blockid = $undo_blockid\n";
472 # utilize paired blocks later...
473 0 my $offset = $undo_blockid * 2;
474
475 0 my $blk = ($cl_ctx->{proc_undo_blocknum} + $offset)*$UNDO_BLOCKSIZE;
476 0 ▶ $self->{undo_file}->sysseek($blk, 0)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"undo_file"}->sysseek($blk, 0) or die "bad seek - file undo block ${blk}: $! \n" 0 0 0
477 or die "bad seek - file undo block $blk: $! \n";
478  
479 0 my $buff;
480  
481 0 ▶ Genezzo::Util::gnz_read ($self->{undo_file}, $buff, $UNDO_BLOCKSIZE)
Branch: 1 branch
BranchTrueFalseTotal
&Genezzo::Util::gnz_read($self->{"undo_file"}, \$buff, $Genezzo::Contrib::Clustered::UNDO_BLOCKSIZE) == $Genezzo::Contrib::Clustered::UNDO_BLOCKSIZE or die "bad read - file undo : block $blk : $! \n" 0 0 0
482 == $UNDO_BLOCKSIZE
483 or die
484 "bad read - file undo : block $blk : $! \n";
485
486 0 my %tied_hash = ();
487 0 my $tie_val =
488 tie %tied_hash, 'Genezzo::Block::RDBlock', (refbufstr => \$buff,
489 blocksize =>
490 $UNDO_BLOCKSIZE);
491  
492 0 my $frozen_row = $tied_hash{1};
493 0 my ( $row ) = FreezeThaw::thaw $frozen_row;
494
495 0 ▶ if($undo_blockid == 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($undo_blockid == 0) { } 0 0 0
496 0 $tx_id = $row->{tx};
497 }else{
498 0 ▶ if($tx_id != $row->{tx}){
Branch: 1 branch
BranchTrueFalseTotal
if ($tx_id != $row->{"tx"}) 0 0 0
499 0 last;
500 }
501 }
502  
503 0 my $rownum = 2;
504  
505 0 while(1){
506 0 $frozen_row = $tied_hash{$rownum};
507  
508 0 ▶ if(!defined($frozen_row)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $frozen_row) 0 0 0
509 0 last;
510 }
511  
512 0 ( $row ) = FreezeThaw::thaw $frozen_row;
513  
514 0 whisper
515 "G:C:C:ApplyFuncToUndo file ($row->{f}) block ($row->{b})\n";
516  
517 # Apply func.
518 0 $affected += &$func($self, $row->{f}, $row->{b});
519  
520 0 $rownum++;
521 }
522  
523 0 ▶ if($rownum == 2){
Branch: 1 branch
BranchTrueFalseTotal
if ($rownum == 2) 0 0 0
524 # block is empty, so don't go on to next
525 0 last;
526 }
527 }
528  
529 0 whisper "G:C:C:ApplyFuncToUndo() finished\n";
530 0 return $affected;
531 }
532  
533 ####################################################################
534 # Returns (PID, refbuf, datablocksize).
535 # PID is 0 for none found, -1 for checksum failure (after 3 tries).
536 sub GetBlockWithPID
537 0 ▶{
Subroutine GetBlockWithPID: not called CC=7 SCAR=40.3
Pod undocumented
538 0 my ($self, $fileno, $blockno) = @_;
539 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
540  
541 0 my $retry;
542 0 my $pass = 0;
543 0 my $refbuf;
544 my $datablocksize;
545  
546 0 ▶ for($retry = 0; $retry < 3; $retry++){
Branch: 1 branch
BranchTrueFalseTotal
if ($retry < 3) 0 0 0
547 # Check for pid in block before rolling back.
548 # pre-read block into temp rdblock to check if undo needed
549 0 ($refbuf, $datablocksize) =
550 $self->ReadOrWriteBlock($fileno, $blockno, "READ");
551  
552 0 $pass = $self->VerifyChecksum($refbuf, $datablocksize);
553  
554 0 ▶ if($pass){
Branch: 1 branch
BranchTrueFalseTotal
if ($pass) 0 0 0
555 0 last;
556 }
557  
558 0 ▶ if($retry == 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($retry == 1) 0 0 0
559 0 sleep(1);
560 }
561 }
562  
563 0 ▶ if(!$pass){
Branch: 1 branch
BranchTrueFalseTotal
unless ($pass) 0 0 0
564 0 print STDERR "GetBlockWithPID ($fileno,$blockno) failed checksum!\n";
565 0 return (-1, $refbuf, $datablocksize);
566 }
567  
568 0 my %data_tied_hash = ();
569 0 my $data_tie_val =
570 tie %data_tied_hash,
571 'Genezzo::Block::RDBlock', (refbufstr => $refbuf,
572 blocksize => $datablocksize);
573 0 my $data_pid_row = $data_tie_val->_get_meta_row("PID");
574 0 my $data_block_pid = 0;
575  
576 0 ▶ if(defined($data_pid_row)){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data_pid_row) 0 0 0
577 0 $data_block_pid = $data_pid_row->[0];
578 }
579  
580 0 whisper "G:C:C:GetBlockWithPID data block pid = $data_block_pid\n";
581 0 return ($data_block_pid, $refbuf, $datablocksize);
582 }
583  
584 ####################################################################
585 # Passed to ApplyFuncToUndo.
586 sub RollbackFunc
587 0 ▶{
Subroutine RollbackFunc: not called CC=4 SCAR=30.0
Pod undocumented
588 0 my ($self, $fileno, $blockno) = @_;
589 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
590 0 my $affected = 0;
591 0 my $cl_ctx = $self->{cl_ctx};
592  
593 0 my $gtxLock = $cl_ctx->{gtxLock}; # Locks needed for startup case;
594 # otherwise redundant.
595 # Lock block SH.
596 0 $gtxLock->lock(lock => $blockno, shared => 1);
597  
598 0 my ($data_block_pid) = $self->GetBlockWithPID($fileno, $blockno);
599  
600 0 ▶ if(($data_block_pid == $cl_ctx->{proc_num}) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($data_block_pid == $cl_ctx->{"proc_num"} or $data_block_pid == -1) 0 0 0
Condition0%0/3
$data_block_pid == $cl_ctx->{"proc_num"} or $data_block_pid == -1
l!l&&r!l&&!r
000
MC/DC0%0/2
$data_block_pid == $cl_ctx->{"proc_num"} or $data_block_pid == -1
$data_block_pid == $cl_ctx->{"proc_num"} $data_block_pid == -1
Truth table0%0/3
A or B
A= $data_block_pid == $cl_ctx->{"proc_num"}B= $data_block_pid == -1
ABresult
1X1
011
000
601 ($data_block_pid == -1))
602 {
603 # Only recover your own PID, as someone else (in crash case)
604 # may have already recovered and used block.
605 # Promote lock to EX.
606 0 $gtxLock->lock(lock => $blockno, shared => 0);
607 0 $self->CopyBlockToOrFromTail($fileno, $blockno, "FROM");
608 0 $affected = 1;
609 }
610  
611 # At startup could release each lock here.
612 0 return $affected;
613 }
614  
615 ####################################################################
616 sub Rollback_Internal
617 0 ▶{
Subroutine Rollback_Internal: not called CC=2 SCAR=17.9
Pod undocumented
618 0 my ($self) = @_;
619 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
620  
621 0 whisper "G:C:C:Rollback_Internal()\n";
622 # for each block in undo, for each row in block, replace disk contents
623  
624 0 my $affected = $self->ApplyFuncToUndo(\&RollbackFunc);
625  
626 0 whisper "G:C:C:Rollback_Internal() finished\n";
627 0 return $affected;
628 }
629  
630 ####################################################################
631 sub Sync
632 0 ▶{
Subroutine Sync: not called CC=2 SCAR=17.9
Pod undocumented
633 0 my ($self, $fh) = @_;
634  
635 0 ▶ if($Genezzo::Util::USE_FSYNC){
Branch: 1 branch
BranchTrueFalseTotal
if ($Genezzo::Util::USE_FSYNC) { } 0 0 0
636 0 $fh->sync;
637 }else{
638 # Otherwise assume autoflush(1) has been called.
639 }
640 }
641  
642 ####################################################################
643 # returns IO::File
644 sub OpenFile
645 0 ▶{
Subroutine OpenFile: not called CC=3 SCAR=24.8
Pod undocumented
646 0 my ($self, $full_filename) = @_;
647  
648 0 ▶ my $fh = new IO::File "+<$full_filename"
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::File"->new("+<$full_filename") or die "open $full_filename failed: $!\n" 0 0 0
649 or die "open $full_filename failed: $!\n";
650  
651 0 ▶ if(!$Genezzo::Util::USE_FSYNC){
Branch: 1 branch
BranchTrueFalseTotal
unless ($Genezzo::Util::USE_FSYNC) 0 0 0
652 # Yes, this is probably terrible perfomance.
653 # For now just want to pass CPAN Testers on non-Cygwin Win32.
654 0 $fh->autoflush(1);
655 }
656  
657 0 return $fh;
658 }
659  
660 ####################################################################
661 # Copies before image of block to end of file.
662 # direction TO: copy from body to tail
663 # FROM: copy from tail to body
664 # Optionally call xform_func with block contents before write (unused).
665 # returns $refbuf.
666 sub CopyBlockToOrFromTail
667 0 ▶{
Subroutine CopyBlockToOrFromTail: not called CC=10 SCAR=47.0
Pod undocumented
668 0 my ($self, $fileno, $blockno, $direction, $xform_func) = @_;
669 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
670 0 my $cl_ctx = $self->{cl_ctx};
671  
672 0 whisper "G:C:C:CopyBlockToOrFromTail $direction\n";
673  
674 0 my $fh = $cl_ctx->{open_files}->{$fileno};
675 my $full_filename =
676 0 $cl_ctx->{undoHeader}->{files}->{$fileno}->{full_filename};
677  
678 0 ▶ if(!defined($fh)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fh) 0 0 0
679 0 whisper "G:C:C:CopyBlockToOrFromTail opening $fileno\n";
680 0 $fh = $self->OpenFile($full_filename);
681 0 $cl_ctx->{open_files}->{$fileno} = $fh;
682 }
683  
684 my $file_blocksize =
685 0 $cl_ctx->{undoHeader}->{files}->{$fileno}->{blocksize};
686 my $file_numblocks =
687 0 $cl_ctx->{undoHeader}->{files}->{$fileno}->{numblocks};
688 0 my $file_hdrsize = $cl_ctx->{undoHeader}->{files}->{$fileno}->{hdrsize};
689  
690 0 my $src_offset;
691 my $dst_offset;
692  
693 0 ▶ if($direction eq "TO"){
Branch: 2 branches
BranchTrueFalseTotal
if ($direction eq 'TO') { } 0 0 0
elsif ($direction eq 'FROM') { } 0 0 0
694 0 $src_offset = $file_hdrsize + ($file_blocksize * $blockno);
695 # not clear if numblocks includes header; lets be safe
696 0 $dst_offset = $src_offset + ($file_numblocks * $file_blocksize);
697 }elsif($direction eq "FROM"){
698 0 $dst_offset = $file_hdrsize + ($file_blocksize * $blockno);
699 # not clear if numblocks includes header; lets be safe
700 0 $src_offset = $dst_offset + ($file_numblocks * $file_blocksize);
701 }else{
702 0 die "invalid direction $direction in CopyBlockToOrFromTail";
703 }
704  
705 0 ▶ $fh->sysseek ($src_offset, 0 )
Branch: 1 branch
BranchTrueFalseTotal
$fh->sysseek($src_offset, 0) or die "bad seek - file $full_filename : src $src_offset : $!" 0 0 0
706 or die "bad seek - file $full_filename : src $src_offset : $!";
707  
708 0 my $buf;
709  
710 0 ▶ Genezzo::Util::gnz_read ($fh, $buf, $file_blocksize)
Branch: 1 branch
BranchTrueFalseTotal
&Genezzo::Util::gnz_read($fh, \$buf, $file_blocksize) == $file_blocksize or die "bad read - file $full_filename : src $src_offset : $! \n" 0 0 0
711 == $file_blocksize
712 or die
713 "bad read - file $full_filename : src $src_offset : $! \n";
714  
715 0 ▶ if(defined($xform_func)){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $xform_func) 0 0 0
716 0 &$xform_func($self, $fileno, $blockno, \$buf, $file_blocksize);
717 }
718  
719 0 ▶ $fh->sysseek ($dst_offset, 0 )
Branch: 1 branch
BranchTrueFalseTotal
$fh->sysseek($dst_offset, 0) or die "bad seek - file $full_filename : dst $dst_offset : $!" 0 0 0
720 or die "bad seek - file $full_filename : dst $dst_offset : $!";
721  
722 0 ▶ Genezzo::Util::gnz_write ($fh, $buf, $file_blocksize)
Branch: 1 branch
BranchTrueFalseTotal
&Genezzo::Util::gnz_write($fh, $buf, $file_blocksize) == $file_blocksize or die "bad write - file $full_filename : dst $dst_offset : $! \n" 0 0 0
723 == $file_blocksize
724 or die
725 "bad write - file $full_filename : dst $dst_offset : $! \n";
726  
727 #if($direction eq "TO"){
728 0 $self->Sync($fh);
729 #}
730  
731 0 return \$buf;
732 }
733  
734 ####################################################################
735 # Reads block from file, or writes block to file.
736 # Direction READ: read block and return (refbuf, file_blocksize)
737 # WRITE: write writebuf to file
738 # WRITE_TAIL write writebuf to tail of file
739 sub ReadOrWriteBlock
740 0 ▶{
Subroutine ReadOrWriteBlock: not called CC=9 SCAR=45.0
Pod undocumented
741 0 my ($self, $fileno, $blockno, $direction, $refbuf) = @_;
742 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
743 0 my $cl_ctx = $self->{cl_ctx};
744  
745 0 whisper "G:C:C:ReadOrWriteBlock $direction\n";
746  
747 0 my $fh = $cl_ctx->{open_files}->{$fileno};
748 my $full_filename =
749 0 $cl_ctx->{undoHeader}->{files}->{$fileno}->{full_filename};
750  
751 0 ▶ if(!defined($fh)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fh) 0 0 0
752 0 whisper "G:C:C:ReadOrWriteBlock opening $fileno\n";
753 0 $fh = $self->OpenFile($full_filename);
754 0 $cl_ctx->{open_files}->{$fileno} = $fh;
755 }
756  
757 my $file_blocksize =
758 0 $cl_ctx->{undoHeader}->{files}->{$fileno}->{blocksize};
759 my $file_numblocks =
760 0 $cl_ctx->{undoHeader}->{files}->{$fileno}->{numblocks};
761 0 my $file_hdrsize = $cl_ctx->{undoHeader}->{files}->{$fileno}->{hdrsize};
762  
763 0 my $offset;
764  
765 0 $offset = $file_hdrsize + ($file_blocksize * $blockno);
766  
767 0 ▶ if($direction eq "WRITE_TAIL"){
Branch: 1 branch
BranchTrueFalseTotal
if ($direction eq "WRITE_TAIL") 0 0 0
768 0 $direction = "WRITE";
769 0 $offset += ($file_blocksize * $file_numblocks);
770 }
771  
772 0 ▶ $fh->sysseek ($offset, 0 )
Branch: 1 branch
BranchTrueFalseTotal
$fh->sysseek($offset, 0) or die "bad seek - file $full_filename : src $offset : $!" 0 0 0
773 or die "bad seek - file $full_filename : src $offset : $!";
774  
775 0 ▶ if($direction eq "READ"){
Branch: 2 branches
BranchTrueFalseTotal
if ($direction eq 'READ') { } 0 0 0
elsif ($direction eq 'WRITE') { } 0 0 0
776 0 my $buf;
777  
778 0 ▶ Genezzo::Util::gnz_read ($fh, $buf, $file_blocksize)
Branch: 1 branch
BranchTrueFalseTotal
&Genezzo::Util::gnz_read($fh, \$buf, $file_blocksize) == $file_blocksize or die "bad read - file $full_filename : $offset : $! \n" 0 0 0
779 == $file_blocksize
780 or die
781 "bad read - file $full_filename : $offset : $! \n";
782
783 0 return (\$buf, $file_blocksize);
784 }elsif($direction eq "WRITE"){
785 0 ▶ Genezzo::Util::gnz_write ($fh, $$refbuf, $file_blocksize)
Branch: 1 branch
BranchTrueFalseTotal
&Genezzo::Util::gnz_write($fh, $$refbuf, $file_blocksize) == $file_blocksize or die "bad write - file $full_filename : $offset : $! \n" 0 0 0
786 == $file_blocksize
787 or die
788 "bad write - file $full_filename : $offset : $! \n";
789
790 0 $self->Sync($fh);
791 }else{
792 0 die "invalid direction $direction in ReadOrWriteBlock";
793 }
794 }
795  
796 ####################################################################
797 sub WriteTransactionState
798 0 ▶{
Subroutine WriteTransactionState: not called CC=4 SCAR=30.0
Pod undocumented
799 0 my ($self, $state_buff) = @_;
800 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
801 0 my $undo_file = $self->{undo_file};
802  
803 0 my $blk = $self->{cl_ctx}->{proc_state_blocknum}*$UNDO_BLOCKSIZE;
804 0 ▶ $undo_file->sysseek($blk, 0)
Branch: 1 branch
BranchTrueFalseTotal
$undo_file->sysseek($blk, 0) or die "bad seek - file undo block ${blk}: $! \n" 0 0 0
805 or die "bad seek - file undo block $blk: $! \n";
806 0 ▶ Genezzo::Util::gnz_write($undo_file, $state_buff, $UNDO_BLOCKSIZE)
Branch: 1 branch
BranchTrueFalseTotal
&Genezzo::Util::gnz_write($undo_file, $state_buff, $Genezzo::Contrib::Clustered::UNDO_BLOCKSIZE) or die "bad write - file undo block ${blk}: $! \n" 0 0 0
807 or die "bad write - file undo block $blk: $! \n";
808 0 $self->Sync($undo_file);
809 }
810  
811 ####################################################################
812 # returns single character code
813 sub ReadTransactionState
814 0 ▶{
Subroutine ReadTransactionState: not called CC=9 SCAR=45.0
Pod undocumented
815 0 my ($self, $pid) = @_; # if undefined uses $cl_ctx->{proc_num}
816 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
817 0 my $undo_file = $self->{undo_file};
818 0 my $cl_ctx = $self->{cl_ctx};
819 0 my $buf;
820  
821 0 ▶ if(!defined($pid)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pid) 0 0 0
822 0 $pid = $cl_ctx->{proc_num};
823 }
824  
825 # Was $self->{cl_ctx}->{proc_state_blocknum}.
826 0 my $blk = ($pid +1)*$UNDO_BLOCKSIZE;
827 0 ▶ $undo_file->sysseek($blk, 0)
Branch: 1 branch
BranchTrueFalseTotal
$undo_file->sysseek($blk, 0) or die "bad seek - file undo block ${blk}: $! \n" 0 0 0
828 or die "bad seek - file undo block $blk: $! \n";
829 0 ▶ Genezzo::Util::gnz_read($undo_file, $buf, $UNDO_BLOCKSIZE)
Branch: 1 branch
BranchTrueFalseTotal
&Genezzo::Util::gnz_read($undo_file, \$buf, $Genezzo::Contrib::Clustered::UNDO_BLOCKSIZE) or die "bad write - file undo block ${blk}: $! \n" 0 0 0
830 or die "bad write - file undo block $blk: $! \n";
831  
832 0 my $ch = substr($buf,0,1);
833  
834 # Handle corruped byte case.
835 0 ▶ if(($ch ne $COMMITTED_CODE) && ($ch ne $CLEAR_CODE) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($ch ne $Genezzo::Contrib::Clustered::COMMITTED_CODE and $ch ne $Genezzo::Contrib::Clustered::CLEAR_CODE and $ch ne $Genezzo::Contrib::Clustered::ROLLEDBACK_CODE and $ch ne $Genezzo::Contrib::Clustered::PENDING_CODE) 0 0 0
Condition0%0/9
$ch ne $Genezzo::Contrib::Clustered::COMMITTED_CODE and $ch ne $Genezzo::Contrib::Clustered::CLEAR_CODE and $ch ne $Genezzo::Contrib::Clustered::ROLLEDBACK_CODE and $ch ne $Genezzo::Contrib::Clustered::PENDING_CODE
!ll&&!rl&&r
000
$ch ne $Genezzo::Contrib::Clustered::COMMITTED_CODE and $ch ne $Genezzo::Contrib::Clustered::CLEAR_CODE and $ch ne $Genezzo::Contrib::Clustered::ROLLEDBACK_CODE
!ll&&!rl&&r
000
$ch ne $Genezzo::Contrib::Clustered::COMMITTED_CODE and $ch ne $Genezzo::Contrib::Clustered::CLEAR_CODE
!ll&&!rl&&r
000
MC/DC0%0/4
$ch ne $Genezzo::Contrib::Clustered::COMMITTED_CODE and $ch ne $Genezzo::Contrib::Clustered::CLEAR_CODE and $ch ne $Genezzo::Contrib::Clustered::ROLLEDBACK_CODE and $ch ne $Genezzo::Contrib::Clustered::PENDING_CODE
$ch ne $Genezzo::Contrib::Clustered::COMMITTED_CODE $ch ne $Genezzo::Contrib::Clustered::CLEAR_CODE $ch ne $Genezzo::Contrib::Clustered::ROLLEDBACK_CODE $ch ne $Genezzo::Contrib::Clustered::PENDING_CODE
Truth table0%0/5
A and B and C and D
A= $ch ne $Genezzo::Contrib::Clustered::COMMITTED_CODEB= $ch ne $Genezzo::Contrib::Clustered::CLEAR_CODEC= $ch ne $Genezzo::Contrib::Clustered::ROLLEDBACK_CODED= $ch ne $Genezzo::Contrib::Clustered::PENDING_CODE
ABCDresult
0XXX0
10XX0
110X0
11100
11111
836 ($ch ne $ROLLEDBACK_CODE) && ($ch ne $PENDING_CODE))
837 {
838 0 $ch = $ROLLEDBACK_CODE;
839 }
840  
841 0 return $ch;
842 }
843  
844 ####################################################################
845 sub ResetUndo
846 0 ▶{
Subroutine ResetUndo: not called CC=2 SCAR=17.9
Pod undocumented
847 0 my ($self) = @_;
848 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
849 0 my $cl_ctx = $self->{cl_ctx};
850  
851 0 $cl_ctx->{tx_id} = $cl_ctx->{tx_id} + 1;
852  
853 0 $cl_ctx->{current_undo_blockid} = 0;
854  
855 # create empty undo block
856 0 $self->CreateUndoBlock();
857 # write it out
858 0 $self->WriteUndoBlock();
859 }
860  
861 ####################################################################
862 sub BeginTransaction
863 0 ▶{
Subroutine BeginTransaction: not called CC=2 SCAR=17.9
Pod undocumented
864 0 my ($self) = @_;
865 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
866 0 my $cl_ctx = $self->{cl_ctx};
867  
868 0 whisper "Genezzo::Contrib::Clustered::BeginTransaction\n";
869 # Increment transaction id.
870 0 $cl_ctx->{tx_id} = $cl_ctx->{tx_id} + 1;
871 # Mark transaction pending.
872 0 $self->WriteTransactionState($PENDING_BUFF);
873  
874 0 $cl_ctx->{current_undo_blockid} = 0;
875  
876 # Create empty undo block.
877 0 $self->CreateUndoBlock();
878 # Write it out.
879 0 $self->WriteUndoBlock();
880 }
881  
882 ####################################################################
883 sub CreateUndoBlock
884 0 ▶{
Subroutine CreateUndoBlock: not called CC=2 SCAR=17.9
Pod undocumented
885 0 my ($self) = @_;
886 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
887 0 my $cl_ctx = $self->{cl_ctx};
888  
889 0 my $buff = "\0" x $UNDO_BLOCKSIZE;
890 0 my %tied_hash = ();
891 0 my $tie_val =
892 tie %tied_hash, 'Genezzo::Block::RDBlock', (refbufstr => \$buff,
893 blocksize =>
894 $UNDO_BLOCKSIZE);
895 0 $cl_ctx->{current_undo_block} = $tie_val;
896 0 $cl_ctx->{current_undo_block_buf} = \$buff;
897 # Add tx id.
898 # This should be metadata; for now store it as 1st row.
899 0 my $row = { "tx" => $cl_ctx->{tx_id} };
900 0 my $frozen_row = FreezeThaw::freeze $row;
901 0 $cl_ctx->{current_undo_block}->HPush($frozen_row);
902 }
903  
904 ####################################################################
905 sub AddAndWriteUndo
906 0 ▶{
Subroutine AddAndWriteUndo: not called CC=6 SCAR=37.4
Pod undocumented
907 0 my ($self,$fileno, $blockno) = @_;
908 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
909 0 my $cl_ctx = $self->{cl_ctx};
910  
911 0 whisper "G:C:C:AddAndWriteUndo\n";
912  
913 0 my $row;
914  
915 0 ▶ if($pad_undo == 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($Genezzo::Contrib::Clustered::pad_undo == 0) { } 0 0 0
916 0 $row = { "f" => $fileno,
917 "b" => $blockno };
918 }else{
919 0 my $pad = "X" x ($UNDO_BLOCKSIZE/3);
920 0 $row = { "f" => $fileno,
921 "b" => $blockno,
922 "pad" => $pad };
923 }
924  
925 0 my $frozen_row = FreezeThaw::freeze $row;
926 0 my $newkey = $cl_ctx->{current_undo_block}->HPush($frozen_row);
927
928 0 ▶ if(defined($newkey)){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newkey) 0 0 0
929 0 $self->WriteUndoBlock();
930 0 return;
931 }
932  
933 # Current block is full (and already written).
934 # Create new block.
935  
936 0 $self->CreateUndoBlock();
937 # move to next block
938 0 $cl_ctx->{current_undo_blockid} += 1;
939  
940 0 ▶ if($pad_undo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Genezzo::Contrib::Clustered::pad_undo) 0 0 0
941 #print STDERR
942 # "Moving to next undo block ($cl_ctx->{current_undo_blockid})\n";
943 #cluck "Moving";
944 }
945  
946 0 my $offset = $cl_ctx->{current_undo_blockid}*2;
947  
948 0 ▶ if(($offset) >= ($cl_ctx->{undoHeader}->{blocks_per_proc}-1))
Branch: 1 branch
BranchTrueFalseTotal
if ($offset >= $cl_ctx->{"undoHeader"}{"blocks_per_proc"} - 1) 0 0 0
949 {
950 0 die("Undo Full: undo offset $offset >= block_per_proc $cl_ctx->{undoHeader}->{blocks_per_proc} - 1\n");
951 }
952  
953 0 $newkey = $cl_ctx->{current_undo_block}->HPush($frozen_row);
954 0 $self->WriteUndoBlock();
955 }
956  
957 ####################################################################
958 sub WriteUndoBlock
959 0 ▶{
Subroutine WriteUndoBlock: not called CC=6 SCAR=37.4
Pod undocumented
960 0 my ($self) = @_;
961 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
962 0 my $cl_ctx = $self->{cl_ctx};
963 0 my $undo_file = $self->{undo_file};
964  
965 0 whisper "G:C:C:WriteUndoBlock\n";
966 # note paired blocks means we multiply blockid by 2
967 0 my $offset = $cl_ctx->{current_undo_blockid} * 2;
968  
969 0 ▶ if($offset >= ($cl_ctx->{undoHeader}->{blocks_per_proc}-1)){
Branch: 1 branch
BranchTrueFalseTotal
if ($offset >= $cl_ctx->{"undoHeader"}{"blocks_per_proc"} - 1) 0 0 0
970 0 die("Undo Full: undo offset $offset >= block_per_proc $cl_ctx->{undoHeader}->{blocks_per_proc} - 1\n");
971 }
972
973 0 my $blk = ($cl_ctx->{proc_undo_blocknum} + $offset)*$UNDO_BLOCKSIZE;
974 0 ▶ $undo_file->sysseek($blk, 0)
Branch: 1 branch
BranchTrueFalseTotal
$undo_file->sysseek($blk, 0) or die "bad seek - file undo block ${blk}: $! \n" 0 0 0
975 or die "bad seek - file undo block $blk: $! \n";
976  
977 # TODO: Add a checksum so we can tell which block is good.
978 0 my $bp = $cl_ctx->{current_undo_block_buf};
979 0 ▶ Genezzo::Util::gnz_write($undo_file, $$bp, $UNDO_BLOCKSIZE)
Branch: 1 branch
BranchTrueFalseTotal
&Genezzo::Util::gnz_write($undo_file, $$bp, $Genezzo::Contrib::Clustered::UNDO_BLOCKSIZE) == $Genezzo::Contrib::Clustered::UNDO_BLOCKSIZE or die "bad write of undo to undo : $! \n" 0 0 0
980 == $UNDO_BLOCKSIZE
981 or die "bad write of undo to undo : $! \n";
982 # write it again to block+1 (paired writes)
983 0 ▶ Genezzo::Util::gnz_write($undo_file, $$bp, $UNDO_BLOCKSIZE)
Branch: 1 branch
BranchTrueFalseTotal
&Genezzo::Util::gnz_write($undo_file, $$bp, $Genezzo::Contrib::Clustered::UNDO_BLOCKSIZE) == $Genezzo::Contrib::Clustered::UNDO_BLOCKSIZE or die "bad write (2) of undo to undo : $! \n" 0 0 0
984 == $UNDO_BLOCKSIZE
985 or die "bad write (2) of undo to undo : $! \n";
986 0 $self->Sync($undo_file);
987 }
988  
989 ####################################################################
990 # Returns 1 for success, 0 for failure.
991 sub VerifyChecksum
992 0 ▶{
Subroutine VerifyChecksum: not called CC=4 SCAR=30.0
Pod undocumented
993 0 my ($self, $refbuf, $blocksize) = @_;
994 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
995
996 0 my @cksums = Genezzo::Block::Util::GetChecksums($refbuf, $blocksize);
997 # test if the calculated checksum matches the stored checksum
998 0 ▶ unless ((scalar(@cksums) == 2) &&
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @cksums == 2 and $cksums[0] == $cksums[1]) 0 0 0
Condition0%0/3
scalar @cksums == 2 and $cksums[0] == $cksums[1]
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @cksums == 2 and $cksums[0] == $cksums[1]
scalar @cksums == 2 $cksums[0] == $cksums[1]
Truth table0%0/3
A and B
A= scalar @cksums == 2B= $cksums[0] == $cksums[1]
ABresult
0X0
100
111
999 ($cksums[0] == $cksums[1]))
1000 {
1001 0 return 0;
1002 }
1003  
1004 0 return 1;
1005 }
1006  
1007 ####################################################################
1008 sub UpdateChecksum
1009 0 ▶{
Subroutine UpdateChecksum: not called CC=2 SCAR=17.9
Pod undocumented
1010 0 my ($self, $fnum, $bnum, $refbuf, $blocksize) = @_;
1011 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
1012  
1013 0 Genezzo::Block::Util::UpdateBlockFooter($refbuf, $blocksize);
1014 }
1015  
1016 ####################################################################
1017 # Not shareable as constant when they contain PID!
1018 sub InitConstBuff()
1019 0 ▶{
Subroutine InitConstBuff: not called CC=1 SCAR=6.9
Pod undocumented
1020 0 my ($self, $bufref, $code) = @_;
1021  
1022 0 my $buff = $code;
1023 0 $buff = $buff. ("-" x 9);
1024 # Can't store PID if shared between procs.
1025 0 my $procstr = sprintf("%10d", $self->{cl_ctx}->{proc_num});
1026 #my $procstr = sprintf("%10d", 0);
1027 0 $buff = $buff . $procstr;
1028 0 $buff = $buff . ( "=" x ($UNDO_BLOCKSIZE - 20) );
1029 0 $$bufref = $buff;
1030 }
1031  
1032 ####################################################################
1033 sub _init
1034 0 ▶{
Subroutine _init: not called CC=16 SCAR=56.1
1035 0 my $self = shift;
1036 0 ▶ if(!defined($self->{MARK})){cluck("missing MARK");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"MARK"}) 0 0 0
1037 0 my $cl_ctx = $self->{cl_ctx};
1038  
1039 0 ▶ if(defined($self->{init_done}) && $self->{init_done}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"init_done"} and $self->{"init_done"}) 0 0 0
Condition0%0/3
defined $self->{"init_done"} and $self->{"init_done"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"init_done"} and $self->{"init_done"}
defined $self->{"init_done"} $self->{"init_done"}
Truth table0%0/3
A and B
A= defined $self->{"init_done"}B= $self->{"init_done"}
ABresult
0X0
100
111
1040 0 return;
1041 }
1042  
1043 #cluck "_init";
1044  
1045 0 whisper "Genezzo::Contrib::Clustered::_init called\n";
1046  
1047 0 my $dict = $self->{dict};
1048 0 my $undo_filename = $dict->{fileheaderinfo}->{undo_filename};
1049  
1050 0 ▶ die unless(defined($undo_filename));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $undo_filename 0 0 0
1051  
1052 0 my $fhts; # gnz_home table space
1053  
1054 0 ▶ if(getUseRaw()){
Branch: 1 branch
BranchTrueFalseTotal
if (getUseRaw()) { } 0 0 0
1055 0 $fhts = $dict->{gnz_home};
1056 }else{
1057 0 $fhts = File::Spec->catdir($dict->{gnz_home}, "ts");
1058 }
1059  
1060 0 my $full_filename =
1061 File::Spec->rel2abs(
1062 File::Spec->catfile($fhts, $undo_filename));
1063  
1064 0 $self->{undo_file} = $self->OpenFile($full_filename);
1065  
1066 # Construct an empty byte buffer.
1067 0 my $buff;
1068  
1069 0 ▶ Genezzo::Util::gnz_read($self->{undo_file}, $buff, $UNDO_BLOCKSIZE)
Branch: 1 branch
BranchTrueFalseTotal
&Genezzo::Util::gnz_read($self->{"undo_file"}, \$buff, $Genezzo::Contrib::Clustered::UNDO_BLOCKSIZE) == $Genezzo::Contrib::Clustered::UNDO_BLOCKSIZE or die "bad read - file ${full_filename}: $!\n" 0 0 0
1070 == $UNDO_BLOCKSIZE
1071 or die "bad read - file $full_filename: $!\n";
1072
1073 0 my %tied_hash = ();
1074 0 my $tie_val =
1075 tie %tied_hash, 'Genezzo::Block::RDBlock', (refbufstr => \$buff,
1076 blocksize =>
1077 $UNDO_BLOCKSIZE);
1078
1079 0 my $frozen_undoHeader = $tied_hash{1};
1080 0 my ( $undoHeader ) = FreezeThaw::thaw $frozen_undoHeader;
1081 0 $cl_ctx->{undoHeader} = $undoHeader;
1082  
1083 0 my $try_proc_num = $starting_pid;
1084  
1085 0 my $pid_param;
1086 0 my $fhdefs = $dict->{fhdefs};
1087  
1088 0 ▶ if(defined($fhdefs)){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fhdefs) 0 0 0
1089 0 $pid_param = $fhdefs->{_pid};
1090 }
1091  
1092 0 ▶ if(defined($pid_param)){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pid_param) 0 0 0
1093 0 $try_proc_num = $pid_param;
1094 }
1095  
1096 # determine if this proc_num is free
1097 0 while(1){
1098 0 ▶ if($try_proc_num >= $cl_ctx->{undoHeader}->{procs}){
Branch: 1 branch
BranchTrueFalseTotal
if ($try_proc_num >= $cl_ctx->{"undoHeader"}{"procs"}) 0 0 0
1099 0 Carp::croak(
1100 "Maximum processes ($cl_ctx->{undoHeader}->{procs}) exceeded");
1101 }
1102  
1103 0 my $lockname = "SVR" . $try_proc_num;
1104 0 my $curLock =
1105 Genezzo::Contrib::Clustered::GLock::GLock->new(
1106 lock => $lockname, block => 0);
1107 0 ▶ if(defined($curLock->lock(shared => 0))){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $curLock->lock("shared", 0)) 0 0 0
1108 0 last; # Obtained lock.
1109 }
1110
1111 0 $try_proc_num++;
1112 }
1113  
1114 0 $cl_ctx->{proc_num} = $try_proc_num;
1115 0 print STDERR "Genezzo::Contrib::Clustered Assigned Process Number = $try_proc_num to OS process $$\n";
1116
1117 $cl_ctx->{proc_state_blocknum} =
1118 0 $cl_ctx->{proc_num} + 1; # 1 for undoHeader
1119 $cl_ctx->{proc_undo_blocknum} =
1120 1 + $cl_ctx->{undoHeader}->{procs} +
1121 0 ($cl_ctx->{undoHeader}->{blocks_per_proc} * $cl_ctx->{proc_num});
1122  
1123 0 $self->InitConstBuff(\$COMMITTED_BUFF, $COMMITTED_CODE);
1124 0 $self->InitConstBuff(\$ROLLEDBACK_BUFF, $ROLLEDBACK_CODE);
1125 0 $self->InitConstBuff(\$PENDING_BUFF, $PENDING_CODE);
1126 0 $self->InitConstBuff(\$CLEAR_BUFF, $CLEAR_CODE);
1127  
1128 # Hashed on fileno.
1129 # Contains IO::File.
1130 0 $cl_ctx->{open_files} = {};
1131  
1132 # Hashed on $fileno_$blockno.
1133 # contents are { f => $fileno, b => $blockno }
1134 0 $cl_ctx->{dirty_blocks} = {};
1135  
1136 0 my $gtxLock = Genezzo::Contrib::Clustered::GLock::GTXLock->new();
1137 0 $cl_ctx->{gtxLock} = $gtxLock;
1138  
1139 # Startup recovery.
1140 0 my $tx_state = $self->ReadTransactionState();
1141  
1142 0 ▶ if(($tx_state eq $PENDING_CODE) || ($tx_state eq $ROLLEDBACK_CODE)){
Branch: 2 branches
BranchTrueFalseTotal
if ($tx_state eq $Genezzo::Contrib::Clustered::PENDING_CODE or $tx_state eq $Genezzo::Contrib::Clustered::ROLLEDBACK_CODE) { } 0 0 0
elsif ($tx_state eq $Genezzo::Contrib::Clustered::COMMITTED_CODE) { } 0 0 0
Condition0%0/3
$tx_state eq $Genezzo::Contrib::Clustered::PENDING_CODE or $tx_state eq $Genezzo::Contrib::Clustered::ROLLEDBACK_CODE
l!l&&r!l&&!r
000
MC/DC0%0/2
$tx_state eq $Genezzo::Contrib::Clustered::PENDING_CODE or $tx_state eq $Genezzo::Contrib::Clustered::ROLLEDBACK_CODE
$tx_state eq $Genezzo::Contrib::Clustered::PENDING_CODE $tx_state eq $Genezzo::Contrib::Clustered::ROLLEDBACK_CODE
Truth table0%0/3
A or B
A= $tx_state eq $Genezzo::Contrib::Clustered::PENDING_CODEB= $tx_state eq $Genezzo::Contrib::Clustered::ROLLEDBACK_CODE
ABresult
1X1
011
000
1143 0 my $affected = $self->Rollback_Internal();
1144
1145 0 ▶ if($affected > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($affected > 0) 0 0 0
1146 0 print STDERR "rollback at startup necessary!\n";
1147 0 print STDERR "PLEASE TYPE ROLLBACK COMMAND\n";
1148 # note here no rollback work will occur, but system will restart
1149 # from disk (verify)
1150 }
1151 }elsif($tx_state eq $COMMITTED_CODE){
1152 # need to clear PID in blocks
1153 0 $self->ApplyFuncToUndo(\&CommitFunc);
1154 }
1155  
1156 0 $self->WriteTransactionState($CLEAR_BUFF);
1157  
1158 # Rollback_Internal and Commit accumulate locks.
1159 # Keep them.
1160 # $gtxLock->unlockAll();
1161 0 $gtxLock->demoteAll();
1162  
1163 0 $cl_ctx->{tx_id} = 0;
1164  
1165 0 whisper "G:C:C:_init begin init undo\n";
1166 # Init all undo blocks.
1167 0 $self->CreateUndoBlock();
1168 0 my $tmp_undo_blockid;
1169  
1170 0 ▶ for($tmp_undo_blockid = 0;
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp_undo_blockid < $cl_ctx->{"undoHeader"}{"blocks_per_proc"} / 2) 0 0 0
1171 $tmp_undo_blockid < ($cl_ctx->{undoHeader}->{blocks_per_proc}/2);
1172 $tmp_undo_blockid++)
1173 {
1174 0 $cl_ctx->{current_undo_blockid} = $tmp_undo_blockid;
1175 0 $self->WriteUndoBlock();
1176 }
1177  
1178 0 whisper "G:C:C:_init end init undo\n";
1179  
1180 0 $cl_ctx->{tx_id} = 1;
1181 0 $cl_ctx->{have_begin_trans} = 0;
1182  
1183 0 whisper "Genezzo::Contrib::Clustered::_init finished\n";
1184 0 $self->{init_done} = 1;
1185 }
1186  
1187 ####################################################################
1188 sub new
1189 0 ▶{
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
1190 0 whoami;
1191 0 my $invocant = shift;
1192 0 ▶ my $class = ref($invocant) || $invocant ;
Condition0%0/3
ref $invocant || $invocant
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $invocant || $invocant
ref $invocant $invocant
Truth table0%0/3
A || B
A= ref $invocantB= $invocant
ABresult
1X1
011
000
1193 0 my $self = {};
1194 0 $self->{MARK} = 1;
1195  
1196 # Clustered context.
1197 0 $self->{cl_ctx} = {};
1198  
1199 # Flag to avoid processing write to buffer during read.
1200 0 $self->{inReadBlock} = 0;
1201  
1202 0 $self->{init_done} = 0;
1203  
1204 0 $self->{dict} = shift @_;
1205 # greet $self->{dict}->{prefs};
1206  
1207 0 return bless $self, $class;
1208  
1209 }
1210  
1211 ####################################################################
1212 sub SysHookInit
1213 0 ▶{
Subroutine SysHookInit: not called CC=1 SCAR=6.9
Pod undocumented
1214 0 goto &new
1215  
1216 }
1217  
1218 ####################################################################
1219 BEGIN
1220 9 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
1221 # Rollback at start will obtain shared locks for all blocks in buffer
1222 # cache.
1223 9 print STDERR "Genezzo::Contrib::Clustered will be installed (please type rollback)\n";
1224  
1225 9 $COMMITTED_BUFF = "";
1226 9 $ROLLEDBACK_BUFF = "";
1227 9 $PENDING_BUFF = "";
1228 9 $CLEAR_BUFF = "";
1229  
1230 9 $COMMITTED_CODE = "C";
1231 9 $ROLLEDBACK_CODE = "R";
1232 9 $PENDING_CODE = "P";
1233 9 $CLEAR_CODE = "-";
1234  
1235 9 $UNDO_BLOCKSIZE = $Genezzo::Block::Std::DEFBLOCKSIZE;
1236  
1237 9 $starting_pid = 1;
1238 9 $pad_undo = 0;
1239 }
1240  
1241 9 1;
1242 __END__
↑ Summary lib/Genezzo/Contrib/Clustered/GLock/GLock.pm »