[LNT] r307415 - Move some v4db methds down to TestSuiteDB

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 7 10:56:08 PDT 2017


Author: matze
Date: Fri Jul  7 10:56:07 2017
New Revision: 307415

URL: http://llvm.org/viewvc/llvm-project?rev=307415&view=rev
Log:
Move some v4db methds down to TestSuiteDB

This moves getNum{Machines|Runs|Samples|Tests}() and
importDataFromDict() from v4db into TestSuiteDB so they only operate on
a single testsuite.

They are only ever used to compute the delta when inserting into
a single test-suite anyway, so we are fine with the simpler
per-testsuite version.

It also fixes wrong numbers getting reported when submitting to a
testsuite for the first time after a server restart. getNumXXX() would
not see the testsuite at first as it wasn't loaded yet but after loading
the suite and inserting it would see all the old data and report bogus
numbers.

Modified:
    lnt/trunk/lnt/server/db/testsuitedb.py
    lnt/trunk/lnt/server/db/v4db.py
    lnt/trunk/lnt/util/ImportData.py

Modified: lnt/trunk/lnt/server/db/testsuitedb.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/testsuitedb.py?rev=307415&r1=307414&r2=307415&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/testsuitedb.py (original)
+++ lnt/trunk/lnt/server/db/testsuitedb.py Fri Jul  7 10:56:07 2017
@@ -1065,3 +1065,15 @@ class TestSuiteDB(object):
 
     def __repr__(self):
         return "{} (on {})".format(self.name, self.v4db.path)
+
+    def getNumMachines(self):
+        return self.query(self.Machine).count()
+
+    def getNumRuns(self):
+        return self.query(self.Run).count()
+
+    def getNumSamples(self):
+        return self.query(self.Sample).count()
+
+    def getNumTests(self):
+        return self.query(self.Test).count()

Modified: lnt/trunk/lnt/server/db/v4db.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/v4db.py?rev=307415&r1=307414&r2=307415&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/v4db.py (original)
+++ lnt/trunk/lnt/server/db/v4db.py Fri Jul  7 10:56:07 2017
@@ -197,32 +197,3 @@ class V4DB(object):
         if self._testsuite_proxy is None:
             self._testsuite_proxy = V4DB.TestSuiteAccessor(self)
         return self._testsuite_proxy
-
-    # FIXME: The getNum...() methods below should be phased out once we can
-    # eliminate the v0.3 style databases.
-    def getNumMachines(self):
-        return sum([ts.query(ts.Machine).count()
-                    for ts in self.testsuite.values()])
-    def getNumRuns(self):
-        return sum([ts.query(ts.Run).count()
-                    for ts in self.testsuite.values()])
-    def getNumSamples(self):
-        return sum([ts.query(ts.Sample).count()
-                    for ts in self.testsuite.values()])
-    def getNumTests(self):
-        return sum([ts.query(ts.Test).count()
-                    for ts in self.testsuite.values()])
-
-    def importDataFromDict(self, data, commit, testsuite_schema, config=None):
-        # Select the database to import into.
-        data_schema = data.get('schema')
-        if data_schema is not None and data_schema != testsuite_schema:
-            raise ValueError, "Tried to import '%s' data into schema '%s'" % \
-                              (data_schema, testsuite_schema)
-
-        db = self.testsuite.get(testsuite_schema)
-        if db is None:
-            raise ValueError, "test suite %r not present in this database!" % (
-                testsuite_schema)
-
-        return db.importDataFromDict(data, commit, config)

Modified: lnt/trunk/lnt/util/ImportData.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/util/ImportData.py?rev=307415&r1=307414&r2=307415&view=diff
==============================================================================
--- lnt/trunk/lnt/util/ImportData.py (original)
+++ lnt/trunk/lnt/util/ImportData.py Fri Jul  7 10:56:07 2017
@@ -23,18 +23,23 @@ def import_and_report(config, db_name, d
     The result object is a dictionary containing information on the imported run
     and its comparison to the previous run.
     """
-    numMachines = db.getNumMachines()
-    numRuns = db.getNumRuns()
-    numTests = db.getNumTests()
+    result = {
+        'success': False,
+        'error': None,
+        'import_file': file,
+    }
+
+    ts = db.testsuite.get(ts_name)
+    if ts is None:
+        result['error'] = "Unknown test suite '%s'!" % ts_name
+        return result
+    numMachines = ts.getNumMachines()
+    numRuns = ts.getNumRuns()
+    numTests = ts.getNumTests()
 
     # If the database gets fragmented, count(*) in SQLite can get really slow!?!
     if show_sample_count:
-        numSamples = db.getNumSamples()
-
-    result = {}
-    result['success'] = False
-    result['error'] = None
-    result['import_file'] = file
+        numSamples = ts.getNumSamples()
 
     startTime = time.time()
     try:
@@ -72,8 +77,12 @@ def import_and_report(config, db_name, d
 
     importStartTime = time.time()
     try:
-        success, run = db.importDataFromDict(data, commit, ts_name,
-                                             config=db_config)
+        data_schema = data.get('schema')
+        if data_schema is not None and data_schema != ts_name:
+            raise ValueError("Importing '%s' data into test suite '%s'" %
+                             (data_schema, ts_name))
+
+        success, run = ts.importDataFromDict(data, commit, config=db_config)
     except KeyboardInterrupt:
         raise
     except:
@@ -103,25 +112,24 @@ def import_and_report(config, db_name, d
         NTEmailReport.emailReport(result, db, run, report_url,
                                   email_config, toAddress, success, commit)
 
-    result['added_machines'] = db.getNumMachines() - numMachines
-    result['added_runs'] = db.getNumRuns() - numRuns
-    result['added_tests'] = db.getNumTests() - numTests
+    result['added_machines'] = ts.getNumMachines() - numMachines
+    result['added_runs'] = ts.getNumRuns() - numRuns
+    result['added_tests'] = ts.getNumTests() - numTests
     if show_sample_count:
-        result['added_samples'] = db.getNumSamples() - numSamples
+        result['added_samples'] = ts.getNumSamples() - numSamples
 
     result['committed'] = commit
     result['run_id'] = run.id
     if commit:
-        db.commit()
+        ts.commit()
         if db_config:
             #  If we are not in a dummy instance, also run background jobs.
             #  We have to have a commit before we run, so subprocesses can
             #  see the submitted data.
-            ts = db.testsuite.get(ts_name)
             async_ops.async_fieldchange_calc(db_name, ts, run, config)
 
     else:
-        db.rollback()
+        ts.rollback()
     # Add a handy relative link to the submitted run.
 
     result['result_url'] = "db_{}/v4/{}/{}".format(db_name, ts_name, run.id)




More information about the llvm-commits mailing list