From: kirovs <ki...@us...> - 2008-01-09 20:09:46
|
Update of /cvsroot/cogs/ensupdate In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv10744 Modified Files: load_ensembl.pl Log Message: Overflow system implemented Index: load_ensembl.pl =================================================================== RCS file: /cvsroot/cogs/ensupdate/load_ensembl.pl,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** load_ensembl.pl 14 Sep 2007 18:04:55 -0000 1.6 --- load_ensembl.pl 9 Jan 2008 20:09:42 -0000 1.7 *************** *** 1,3 **** ! #!/usr/bin/perl use DBI; --- 1,3 ---- ! #!/stf/sys/bin/perl use DBI; *************** *** 16,20 **** my $msqldir=$ENV{MYSQL_DATA}; open (MSQLV,'mysql -V|')||die 'Mysql crashed or no mysql installed'; - if ($overfl) { $avail=check_for_overflow($msqldir) ; } my $msqlv=<MSQLV>; close MSQLV; --- 16,19 ---- *************** *** 27,30 **** --- 26,30 ---- $cs .= "port=$port;" if ($port); my $dbh= DBI->connect($cs,$user,$pass) or die "connecting: $DBI::errstr" ; + $dbh->{mysql_auto_reconnect}=1; #Special table with every DB that loads, should be created in advance *************** *** 50,53 **** --- 50,55 ---- my $dbname=join('_', @ver); my ($obsol)=grep(/$dbname/,@dbs); + my $ifed=$dbh->prepare("drop database if exists $db") ||die "Couldn't create DB $db\n"; #Should we check first and drop it if exists? + $ifed->execute||die; my $str=$dbh->prepare("create database $db") ||die "Couldn't create DB $db\n"; #Should we check first and drop it if exists? my $list=$dbh->prepare("insert into ens_dbnames (db_name, version,current) values (?,?,'yes')") ||die "Couldn't prepare- recording the DB list\n",$DBI::errstr; *************** *** 62,71 **** $up=$pass ? "-u $user -p$pass " : "-u $user"; my $sarg="mysql -h $host $up $db <$ddlfile"; ! my $avail; ! if ($overfl) { $avail=check_for_overflow($msqldir) ; } if (($avail<25)&&($msqldir)) { ! print "Using $overfl overflow\n"; ! system("mv $msqldir/$db $overfl")==0||die "Could not move to $overfl $?:$!"; ! system("ln -s $overfl/$db $msqldir")==0||die "Could not move to $overfl $?:$!"; } print "$sarg\n"; --- 64,74 ---- $up=$pass ? "-u $user -p$pass " : "-u $user"; my $sarg="mysql -h $host $up $db <$ddlfile"; ! my ($avail,$next); ! if ($overfl) { ($avail,$next)=check_for_overflow($msqldir,$overfl) ; } if (($avail<25)&&($msqldir)) { ! die "No space left on original device and in overflow devices (if defined), cannot continue" unless ($next); ! print "Using $overfl $next\n"; ! system("mv $msqldir/$db $next")==0||die "Could not move to $overfl $?:$!"; ! system("ln -s $next/$db $msqldir")==0||die "Could not move to $overfl $?:$!"; } print "$sarg\n"; *************** *** 78,81 **** --- 81,91 ---- system($load)==0||die"Couldn't import\n$load\n"; } + open (DATF, "ls *.txt| wc -l|")||die; + my $cntd=<DATF>; + close DATF; + if ($cntd>0) { + my $load="mysqlimport -L -h $host $up $db *.txt"; + system($load)==0||die"Couldn't import\n$load\n"; + } $dbh= DBI->connect($cs,$user,$pass) or die "connecting: $DBI::errstr" ; if ($obsol) { *************** *** 99,105 **** sub check_for_overflow { ! my $storage=shift; ! unless ($storage) { die "Do not know where to overflow to, see that environment var MYSQL_DATA is set"; } ! open (SZ,"df -h $storage|")||die "$?:$!"; my $head=<SZ>; my $where=<SZ>; --- 109,114 ---- sub check_for_overflow { ! my $default=shift; ! open (SZ,"df -h $default|")||die "$?:$!"; my $head=<SZ>; my $where=<SZ>; *************** *** 107,113 **** $dat=~s/^[\s\t]+//; my ($size,$used,$avail,$mount)=split(/[\t\s]+/,$dat); ! unless ($avail=~/G$/) { return 0}; ! $avail=~s/\D//g; ! return $avail; } --- 116,140 ---- $dat=~s/^[\s\t]+//; my ($size,$used,$avail,$mount)=split(/[\t\s]+/,$dat); ! if ($avail=~/G$/) { ! $avail=~s/\D//g; ! return $avail,undef if ($avail>20); ! } ! my $disks=shift; ! unless ($disks) { die "Do not know where to overflow to, see that environment var MYSQL_DATA is set"; } ! my @storage=split(/:/,$disks); ! my $next; ! foreach my $storage (@storage) { ! open (SZ,"df -h $storage|")||die "$?:$!"; ! my $head=<SZ>; ! #my $where=<SZ>; ! my $dat=<SZ>; ! $dat=~s/^[\s\t]+//; ! my ($fs,$size,$used,$availnext,$mount)=split(/[\t\s]+/,$dat); ! unless ($availnext=~/G$/) { next }; ! $availnext=~s/\D//g; ! if ($availnext>20) { $next=$storage;} ! } ! ! return $avail,$next; } |