« lib/Genezzo/Contrib/Clustered/genezzo_form.pl
↑ Summary
lib/Genezzo/Contrib/Clustered/ModPerlWrap.pm »
| 1 | #!/usr/bin/perl | ||
| 2 | # | ||
| 3 | # PrepUndo.pm | ||
| 4 | # | ||
| 5 | # Initialize undo file for Clustered Genezzo | ||
| 6 | # | ||
| 7 | # | ||
| 8 | package Genezzo::Contrib::Clustered::PrepUndo; | ||
| 9 | |||
| 10 | 9 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 9 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 0 | ▶ | use Genezzo::GenDBI; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 13 | use Data::Dumper; | ||
| 14 | use Carp; | ||
| 15 | use Genezzo::Dict; | ||
| 16 | use Genezzo::Block::RDBlock; | ||
| 17 | use Genezzo::Block::Std; | ||
| 18 | use FreezeThaw; | ||
| 19 | use Genezzo::Util; | ||
| 20 | use Genezzo::Contrib::Clustered; | ||
| 21 | |||
| 22 | our $GZERR = sub { | ||
| 23 | my %args = (@_); | ||
| 24 | |||
| 25 | return | ||
| 26 | unless (exists($args{msg})); | ||
| 27 | |||
| 28 | my $warn = 0; | ||
| 29 | if (exists($args{severity})) | ||
| 30 | { | ||
| 31 | my $sev = uc($args{severity}); | ||
| 32 | $sev = 'WARNING' | ||
| 33 | if ($sev =~ m/warn/i); | ||
| 34 | |||
| 35 | # don't print 'INFO' prefix | ||
| 36 | if ($args{severity} !~ m/info/i) | ||
| 37 | { | ||
| 38 | printf ("%s: ", $sev); | ||
| 39 | $warn = 1; | ||
| 40 | } | ||
| 41 | |||
| 42 | } | ||
| 43 | print $args{msg}; | ||
| 44 | # add a newline if necessary | ||
| 45 | print "\n" unless $args{msg}=~/\n$/; | ||
| 46 | # carp $args{msg} | ||
| 47 | # if (warnings::enabled() && $warn); | ||
| 48 | |||
| 49 | }; | ||
| 50 | |||
| 51 | sub MakeSQL | ||
| 52 | { | ||
| 53 | my $bigSQL; | ||
| 54 | ($bigSQL = <<EOF_SQL) =~ s/^\#//gm; | ||
| 55 | #REM prepare database for Genezzo::Contrib::Clustered | ||
| 56 | #REM ATAThavok.sql and ATATsyshook.sql first | ||
| 57 | #insert into sys_hook (xid, pkg, hook, replace, xtype, xname, args, owner, creationdate, version) values (1000, 'Genezzo::BufCa::BCFile', '_filereadblock', 'ReadBlock_Hook', 'oo_require', 'Genezzo::Contrib::Clustered', 'ReadBlock', 'SYSTEM', TODAY, '1'); | ||
| 58 | #insert into sys_hook (xid, pkg, hook, replace, xtype, xname, args, owner, creationdate, version) values (1001, 'Genezzo::BufCa::DirtyScalar', 'STORE', 'DirtyBlock_Hook', 'oo_require', 'Genezzo::Contrib::Clustered', 'DirtyBlock', 'SYSTEM', TODAY, '1'); | ||
| 59 | #insert into sys_hook (xid, pkg, hook, replace, xtype, xname, args, owner, creationdate, version) values (1002, 'Genezzo::GenDBI', 'Kgnz_Commit', 'Commit_Hook', 'oo_require', 'Genezzo::Contrib::Clustered', 'Commit', 'SYSTEM', TODAY, '1'); | ||
| 60 | #insert into sys_hook (xid, pkg, hook, replace, xtype, xname, args, owner, creationdate, version) values (1003, 'Genezzo::GenDBI', 'Kgnz_Rollback', 'Rollback_Hook', 'oo_require', 'Genezzo::Contrib::Clustered', 'Rollback', 'SYSTEM', TODAY, '1'); | ||
| 61 | #insert into sys_hook (xid, pkg, hook, replace, xtype, xname, args, owner, creationdate, version) values (1003, 'Genezzo::GenDBI', 'Kgnz_Execute', 'Execute_Hook', 'oo_require', 'Genezzo::Contrib::Clustered', 'Execute', 'SYSTEM', TODAY, '1'); | ||
| 62 | #insert into sys_hook (xid, pkg, hook, replace, xtype, xname, args, owner, creationdate, version) values (1004, 'Genezzo::BufCa::BCFile', '_init_filewriteblock', '_init_fwb_Hook', 'oo_require', 'Genezzo::Contrib::Clustered', '_init_filewriteblock', 'SYSTEM', TODAY, '1'); | ||
| 63 | #commit; | ||
| 64 | #shutdown; | ||
| 65 | #REM restart gendba.pl from command line, so havok routines will be redefined | ||
| 66 | #quit; | ||
| 67 | EOF_SQL | ||
| 68 | my $now = Genezzo::Dict::time_iso8601(); | ||
| 69 | $bigSQL =~ s/ATAT/\@/gm; | ||
| 70 | $bigSQL =~ s/TODAY/\'$now\'/gm; | ||
| 71 | my $pver = $Genezzo::Contrib::Clustered::VERSION; | ||
| 72 | $bigSQL =~ s/GPU_VERSION/$pver/gm; | ||
| 73 | $bigSQL = "REM Generated by " . __PACKAGE__ . " version " . | ||
| 74 | $pver . " on $now\nREM\n" . $bigSQL; | ||
| 75 | |||
| 76 | # print $bigSQL; | ||
| 77 | |||
| 78 | return $bigSQL; | ||
| 79 | } | ||
| 80 | |||
| 81 | |||
| 82 | my $glob_init; | ||
| 83 | my $glob_gnz_home; | ||
| 84 | my $glob_shutdown; | ||
| 85 | my $glob_id; | ||
| 86 | my $glob_defs; | ||
| 87 | |||
| 88 | sub prepareUndo | ||
| 89 | { | ||
| 90 | #my $self = shift; | ||
| 91 | my %optional = ( | ||
| 92 | number_of_processes => 256, | ||
| 93 | undo_blocks_per_process => 220, | ||
| 94 | undo_filename => "undo.und" | ||
| 95 | ); | ||
| 96 | |||
| 97 | my %required = ( | ||
| 98 | ); | ||
| 99 | |||
| 100 | my %args = (%optional, | ||
| 101 | @_); | ||
| 102 | |||
| 103 | return 0 | ||
| 104 | unless (Validate(\%args, \%required)); | ||
| 105 | |||
| 106 | |||
| 107 | my $glob_undo_filename = (exists($args{undo_filename})) | ||
| 108 | && (defined($args{undo_filename})) | ||
| 109 | && (length($args{undo_filename})) ? $args{undo_filename} : ""; | ||
| 110 | |||
| 111 | my $glob_gnz_home = $args{gnz_home}; | ||
| 112 | my $glob_procs = $args{number_of_processes}; # num of processes supported | ||
| 113 | # undo blocks per process | ||
| 114 | my $glob_blocks_per_proc = $args{undo_blocks_per_process}; | ||
| 115 | |||
| 116 | my $dbh = Genezzo::GenDBI->connect($glob_gnz_home, | ||
| 117 | "NOUSER", | ||
| 118 | "NOPASSWORD", | ||
| 119 | {GZERR => $GZERR}); | ||
| 120 | |||
| 121 | if(!defined($dbh)){ | ||
| 122 | Carp::croak("failed connect"); | ||
| 123 | } | ||
| 124 | |||
| 125 | $dbh->do("startup"); # start the database | ||
| 126 | |||
| 127 | #----------------------------------------------------------------- | ||
| 128 | # locate home | ||
| 129 | my $stmt = "select pref_value from _pref1 where pref_key='home'"; | ||
| 130 | |||
| 131 | my $sth = $dbh->prepare($stmt); | ||
| 132 | |||
| 133 | if(!defined($sth)){ | ||
| 134 | Carp::croak("failed prepare 2"); | ||
| 135 | } | ||
| 136 | |||
| 137 | my $ret = $sth->execute(); | ||
| 138 | |||
| 139 | if(!defined($ret)){ | ||
| 140 | Carp::croak("failed execute 2"); | ||
| 141 | } | ||
| 142 | |||
| 143 | my $ggg = $sth->fetchrow_hashref(); | ||
| 144 | |||
| 145 | if(!defined($ggg)){ | ||
| 146 | Carp::croak("zero rows 2"); | ||
| 147 | } | ||
| 148 | |||
| 149 | my $pref_home = $ggg->{pref_value}; | ||
| 150 | |||
| 151 | if ($glob_undo_filename eq ""){ | ||
| 152 | if($pref_home eq "/dev/raw"){ | ||
| 153 | print "ERROR: raw device -undo_filename required\n"; | ||
| 154 | exit(); | ||
| 155 | }else{ | ||
| 156 | $glob_undo_filename = "undo.und"; | ||
| 157 | } | ||
| 158 | } | ||
| 159 | |||
| 160 | #----------------------------------------------------------------- | ||
| 161 | # read per-file info | ||
| 162 | $stmt = "select fileidx,filename,blocksize,numblocks,tsid from _tsfiles"; | ||
| 163 | |||
| 164 | $sth = $dbh->prepare($stmt); | ||
| 165 | |||
| 166 | if(!defined($sth)){ | ||
| 167 | Carp::croak("failed prepare"); | ||
| 168 | } | ||
| 169 | |||
| 170 | $ret = $sth->execute(); | ||
| 171 | |||
| 172 | if(!defined($ret)){ | ||
| 173 | Carp::croak("failed execute"); | ||
| 174 | } | ||
| 175 | |||
| 176 | my $undoHeader = { | ||
| 177 | "procs" => $glob_procs, | ||
| 178 | "blocks_per_proc" => $glob_blocks_per_proc, | ||
| 179 | "files" => {} | ||
| 180 | }; | ||
| 181 | |||
| 182 | while(1) | ||
| 183 | { | ||
| 184 | my $ggg = $sth->fetchrow_hashref(); | ||
| 185 | |||
| 186 | last | ||
| 187 | unless(defined($ggg)); | ||
| 188 | |||
| 189 | # look up header size in file FIXME | ||
| 190 | my $full_filename; | ||
| 191 | |||
| 192 | if($pref_home eq "/dev/raw"){ | ||
| 193 | $full_filename = "$pref_home/$ggg->{filename}"; | ||
| 194 | }else{ | ||
| 195 | $full_filename = "$pref_home/ts/$ggg->{filename}"; | ||
| 196 | } | ||
| 197 | |||
| 198 | $ggg->{full_filename} = $full_filename; | ||
| 199 | |||
| 200 | my $fh; | ||
| 201 | open($fh, "<$full_filename") | ||
| 202 | or die "open $full_filename failed: $!\n"; | ||
| 203 | |||
| 204 | my ($hdrsize, $version, $blocksize, $h1) = | ||
| 205 | Genezzo::Util::FileGetHeaderInfo(filehandle => $fh, | ||
| 206 | filename => $full_filename); | ||
| 207 | |||
| 208 | $ggg->{hdrsize} = $hdrsize; | ||
| 209 | |||
| 210 | $undoHeader->{files}->{$ggg->{fileidx}} = $ggg; | ||
| 211 | } | ||
| 212 | |||
| 213 | #----------------------------------------------------------------- | ||
| 214 | my $dictobj = $dbh->{dictobj}; | ||
| 215 | $dictobj->DictSetFileInfo(newkey => "undo_filename", | ||
| 216 | newval => $glob_undo_filename); | ||
| 217 | |||
| 218 | $dbh->do("commit"); | ||
| 219 | |||
| 220 | my $full_filename; | ||
| 221 | |||
| 222 | if($pref_home eq "/dev/raw"){ | ||
| 223 | $full_filename = "$pref_home/$glob_undo_filename"; | ||
| 224 | }else{ | ||
| 225 | $full_filename = "$pref_home/ts/$glob_undo_filename"; | ||
| 226 | } | ||
| 227 | |||
| 228 | #----------------------------------------------------------------- | ||
| 229 | # store per-file info in file header block | ||
| 230 | my $frozen_undoHeader = FreezeThaw::freeze $undoHeader; | ||
| 231 | |||
| 232 | # construct an empty byte buffer | ||
| 233 | my $blocksize = $Genezzo::Block::Std::DEFBLOCKSIZE; | ||
| 234 | my $buff = "\0" x $blocksize; | ||
| 235 | |||
| 236 | my %tied_hash = (); | ||
| 237 | |||
| 238 | my $tie_val = | ||
| 239 | tie %tied_hash, 'Genezzo::Block::RDBlock', (refbufstr => \$buff, | ||
| 240 | blocksize => | ||
| 241 | $blocksize); | ||
| 242 | |||
| 243 | my $newkey = $tie_val->HPush($frozen_undoHeader); | ||
| 244 | |||
| 245 | my $fh; | ||
| 246 | open($fh, ">$full_filename") | ||
| 247 | or die "open $full_filename failed: $!\n"; | ||
| 248 | |||
| 249 | gnz_write ($fh, $buff, $blocksize) | ||
| 250 | == $blocksize | ||
| 251 | or die "bad write - file $full_filename : $! \n"; | ||
| 252 | |||
| 253 | #----------------------------------------------------------------- | ||
| 254 | # mark process status block for each process as no outstanding transaction | ||
| 255 | my $i; | ||
| 256 | for($i = 0; $i < $glob_procs; $i++){ | ||
| 257 | $buff = "-" x 10; | ||
| 258 | my $procstr = sprintf("%10d", $i); | ||
| 259 | $buff = $buff . $procstr; | ||
| 260 | $buff = $buff . ( "=" x ($blocksize - 20) ); | ||
| 261 | |||
| 262 | gnz_write ($fh, $buff, $blocksize) | ||
| 263 | == $blocksize | ||
| 264 | or die "bad write - file $full_filename ($i): $! \n"; | ||
| 265 | } | ||
| 266 | |||
| 267 | close $fh; | ||
| 268 | |||
| 269 | print "finished initialization of $full_filename.\n" ; | ||
| 270 | |||
| 271 | } | ||
| 272 | |||
| 273 | 1; | ||
| 274 | |||
| 275 | __END__ | ||