Changeset 29060 for branches/sc_branches/trunkTest/tools/czartool/CzarDb.pm
- Timestamp:
- Aug 26, 2010, 9:18:39 AM (16 years ago)
- Location:
- branches/sc_branches/trunkTest
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
tools/czartool/CzarDb.pm (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/sc_branches/trunkTest
- Property svn:mergeinfo changed
-
branches/sc_branches/trunkTest/tools/czartool/CzarDb.pm
r28921 r29060 1 #!/usr/bin/perl i-w1 #!/usr/bin/perl -w 2 2 3 3 package czartool::CzarDb; … … 6 6 use strict; 7 7 8 my @stages = (" chip", "cam", "fake", "warp", "stack", "diff", "magic", "magicDS", "dist"); # TODO put elsewhere8 my @stages = ("burntool", "chip", "cam", "fake", "warp", "stack", "diff", "magic", "magicDS", "dist"); # TODO put elsewhere 9 9 10 10 use base 'czartool::MySQLDb'; … … 491 491 } 492 492 493 494 ########################################################################### 495 # 496 # Deletes all but one row per interval from all stage tables for all labels between the two dates 497 # 498 ########################################################################### 499 sub cleanupDateRange { 500 my ($self, $startDay, $endDay, $interval) = @_; 501 502 my $thisDay = $startDay; 503 my $quit = 0; 504 while(!$quit) { 505 506 if (!$self->isBefore($thisDay, $endDay)) { 507 508 $quit = 1; 509 } 510 511 print "* Running cleanup for $thisDay with an interval of $interval\n"; 512 $self->cleanupADay($thisDay, $interval); 513 $thisDay = $self->addInterval($thisDay, "1 DAY"); 514 515 } 516 } 517 ########################################################################### 518 # 519 # Deletes all but one row per interval from all stage tables for all labels between the provided day 520 # 521 ########################################################################### 522 sub cleanupADay { 523 my ($self, $startDay, $interval) = @_; 524 525 my $endDay = $self->addInterval($startDay, "1 DAY"); 526 527 my $labels = undef; 528 my $fromTime = $startDay; 529 my $toTime = undef; 530 my $totalDeleted = undef; 531 my $quit = 0; 532 while(!$quit) { 533 534 $toTime = $self->addInterval($fromTime, $interval); 535 if (!$self->isBefore($toTime, $endDay)) { 536 537 $toTime = $endDay; 538 $quit = 1; 539 } 540 541 my $stage = undef; 542 $totalDeleted = 0; 543 foreach $stage (@stages) { 544 545 if (!$self->getLabelsInThisTimePeriod($stage, $fromTime, $toTime, \$labels)) {next;} 546 547 my $label = undef; 548 my $row = undef; 549 foreach $row ( @{$labels} ) { 550 my ($label) = @{$row}; 551 552 my $query = $self->{_db}->prepare(<<SQL); 553 SELECT COUNT(*) 554 FROM $stage 555 WHERE timestamp > '$fromTime' 556 AND timestamp <= '$toTime' 557 AND label = '$label' 558 SQL 559 560 $query->execute; 561 562 my $toDelete = scalar $query->fetchrow_array() - 1; 563 if ($toDelete < 1) {next;} 564 565 $query = $self->{_db}->prepare(<<SQL); 566 DELETE FROM $stage 567 WHERE timestamp > '$fromTime' 568 AND timestamp <= '$toTime' 569 AND label = '$label' ORDER BY timestamp DESC LIMIT $toDelete 570 SQL 571 $query->execute; 572 573 $totalDeleted += $toDelete; 574 } 575 } 576 print " * Deleted $totalDeleted between $fromTime and $toTime\n"; 577 $fromTime = $toTime; 578 } 579 } 580 581 ########################################################################### 582 # 583 # Returns an array of labels present during the provided time frame 584 # 585 ########################################################################### 586 sub getLabelsInThisTimePeriod { 587 my ($self, $stage, $fromTime, $toTime, $labels) = @_; 588 589 my $query = $self->{_db}->prepare(<<SQL); 590 SELECT DISTINCT label 591 FROM $stage 592 WHERE timestamp > '$fromTime' 593 AND timestamp <= '$toTime'; 594 SQL 595 596 if (!$query->execute) { 597 598 return 0; 599 } 600 601 ${$labels} = $query->fetchall_arrayref(); 602 603 return 1; 604 } 605 493 606 ########################################################################### 494 607 # … … 500 613 501 614 my $currentRevision = -1; 502 my $latestRevision = 10; 503 504 while ($currentRevision != $latestRevision) { 615 616 while (1) { 505 617 506 618 $currentRevision = $self->getRevision(); … … 517 629 elsif ($currentRevision == 8) {$self->createRevision_9();} 518 630 elsif ($currentRevision == 9) {$self->createRevision_10();} 631 elsif ($currentRevision == 10) {$self->createRevision_11();} 632 else {last;} 519 633 } 520 634 } … … 841 955 } 842 956 957 ####################################################################################### 958 # 959 # Create revision 11 of the database 960 # 961 ####################################################################################### 962 sub createRevision_11 { 963 my ($self) = @_; 964 965 print "* Creating revision 11 of '$self->{_dbName}'\n"; 966 967 # same shape as other stage tables to enable easy update 968 my $query = $self->{_db}->prepare(<<SQL); 969 CREATE TABLE burntool ( 970 timestamp TIMESTAMP DEFAULT NOW(), 971 label VARCHAR(128) DEFAULT "NONE", 972 pending BIGINT NOT NULL, 973 processed BIGINT NOT NULL, 974 faults BIGINT NOT NULL); 975 SQL 976 977 $query->execute; 978 $query = $self->{_db}->prepare(<<SQL); 979 CREATE INDEX burntoolIndex ON burntool (timestamp, label); 980 SQL 981 982 $query->execute; 983 984 $self->setRevision(11); 985 } 986 987 988 843 989 1; 844 990
Note:
See TracChangeset
for help on using the changeset viewer.
