]> xenbits.xensource.com Git - people/aperard/osstest.git/commitdiff
Database: Introduce db_readonly_report
authorIan Jackson <ian.jackson@eu.citrix.com>
Fri, 9 Dec 2016 19:07:10 +0000 (19:07 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Mon, 12 Dec 2016 11:35:01 +0000 (11:35 +0000)
According to the PostgreSQL docs, this can improve the performance
implications of long-running read-only transactions.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Osstest.pm
Osstest/JobDB/Executive.pm
Osstest/JobDB/Standalone.pm
sg-report-flight
sg-report-job-history

index 814be2870843f81bf99e448b6481ed3a6f743155..26fd9d99e77a13ba238d2f63a66f218dad909cf2 100644 (file)
@@ -37,6 +37,7 @@ BEGIN {
                       flight_otherjob
                       main_revision_job_cond other_revision_job_suffix
                       $dbh_tests db_retry db_retry_retry db_retry_abort
+                     db_readonly_report
                       db_begin_work db_prepare
                       get_harness_rev
                       ensuredir get_filecontents_core_quiet system_checked
@@ -272,6 +273,14 @@ sub db_begin_work ($;$) {
     $mjobdb->begin_work($dbh, $tables);
 }
 
+# call this after db_begin_work or just at the top of a db_retry
+# db transaction will be readonly and suitable for a longrunning report
+sub db_readonly_report (;$) {
+    my ($dbh) = @_;
+    $dbh //= $dbh_tests;
+    $mjobdb->readonly_report($dbh);
+}
+
 sub db_retry ($$$;$$) {
     # $code should return whatever it likes, and that will
     #     be returned by db_retry
index d32bf43972838ac4b809785f70c52f17d84ed7a7..8d892b348f8f14a3b626898dfd02465dc1879f2b 100644 (file)
@@ -101,6 +101,12 @@ sub need_retry ($$$) {
     # https://www.postgresql.org/message-id/flat/D960CB61B694CF459DCFB4B0128514C203937E44%40exadv11.host.magwien.gv.at
 }
 
+sub readonly_report ($$) { #method
+    my ($jd, $dbh) = @_;
+    
+    $dbh->do("SET TRANSACTION READ ONLY DEFERRABLE");
+}
+
 sub current_flight ($) { #method
     return $ENV{'OSSTEST_FLIGHT'};
 }
index 21ea07bb8bc8fada705f1dfdf92d0c92aff0f7a3..4842e69499a6d800950e60e83baf7553d13a966b 100644 (file)
@@ -41,6 +41,7 @@ augmentconfigdefaults(
 sub new { return bless {}, $_[0]; };
 
 sub begin_work { }
+sub readonly_report { }
 sub need_retry ($$$) {
     my ($jd, $dbh,$committing) = @_;
     return $committing;
index 7380981c290852cdce5c20fff8c78a5b0a0e4822..ed49d69b5ec5c08edce71650834443c5c4736103 100755 (executable)
@@ -1301,6 +1301,7 @@ END
 }
 
 db_retry($dbh_tests, [], sub {
+    db_readonly_report();
     if (defined $mro) {
        open MRO, "> $mro.new" or die "$mro.new $!";
     }
index abfe63004ef0ebd45af1dad7b6722d0c78291202..f6c47c249954ab312955fe1ba8c69a9cb6181522 100755 (executable)
@@ -299,4 +299,5 @@ sub processjob ($) {
 }
 
 db_begin_work($dbh_tests, []);
+db_readonly_report();
 foreach my $j (@jobs) { processjob($j); }