[LNT] r312397 - v4db: Mark metatable relations as eager, simplify init code

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 1 17:11:35 PDT 2017


Author: matze
Date: Fri Sep  1 17:11:35 2017
New Revision: 312397

URL: http://llvm.org/viewvc/llvm-project?rev=312397&view=rev
Log:
v4db: Mark metatable relations as eager, simplify init code

Trying to avoid some deadlocks which I assume are caused by testsuite
metadata getting loaded lazily. This also simplifies the code by
avoiding long joinedload lists when querying the metatables.

Modified:
    lnt/trunk/lnt/server/db/testsuite.py
    lnt/trunk/lnt/server/db/v4db.py

Modified: lnt/trunk/lnt/server/db/testsuite.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/testsuite.py?rev=312397&r1=312396&r2=312397&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/testsuite.py (original)
+++ lnt/trunk/lnt/server/db/testsuite.py Fri Sep  1 17:11:35 2017
@@ -94,10 +94,14 @@ class TestSuite(Base):
     # as the LNT version).
     version = Column("Version", String(16))
 
-    machine_fields = relation('MachineField', backref='test_suite')
-    order_fields = relation('OrderField', backref='test_suite')
-    run_fields = relation('RunField', backref='test_suite')
-    sample_fields = relation('SampleField', backref='test_suite')
+    machine_fields = relation('MachineField', backref='test_suite',
+                              lazy='immediate')
+    order_fields = relation('OrderField', backref='test_suite',
+                            lazy='immediate')
+    run_fields = relation('RunField', backref='test_suite',
+                          lazy='immediate')
+    sample_fields = relation('SampleField', backref='test_suite',
+                             lazy='immediate')
 
     def __init__(self, name, db_key_name):
         self.name = name
@@ -268,7 +272,7 @@ class SampleField(FieldMixin, Base):
 
     # The type of sample this is.
     type_id = Column("Type", Integer, ForeignKey('SampleType.ID'))
-    type = relation(SampleType)
+    type = relation(SampleType, lazy='immediate')
 
     # The info key describes the key to expect this field to be present as in
     # the reported machine information. Missing keys result in NULL values in
@@ -280,7 +284,7 @@ class SampleField(FieldMixin, Base):
     # association is used by UI code to present the two status fields together.
     status_field_id = Column("status_field", Integer, ForeignKey(
             'TestSuiteSampleFields.ID'))
-    status_field = relation('SampleField', remote_side=id)
+    status_field = relation('SampleField', remote_side=id, lazy='immediate')
 
     # Most real type samples assume lower values are better than higher values.
     # This assumption can be inverted by setting this column to nonzero.

Modified: lnt/trunk/lnt/server/db/v4db.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/v4db.py?rev=312397&r1=312396&r2=312397&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/v4db.py (original)
+++ lnt/trunk/lnt/server/db/v4db.py Fri Sep  1 17:11:35 2017
@@ -35,13 +35,9 @@ class V4DB(object):
         suite = testsuite.sync_testsuite_with_metatables(session, suite)
         session.commit()
 
-        name = suite.name
-        ts = lnt.server.db.testsuitedb.TestSuiteDB(self, name, suite,
-                                                   create_tables=True)
-        if name in self.testsuite:
-            logger.error("Duplicate test-suite '%s' (while loading %s)" %
-                         (name, schema_file))
-        self.testsuite[name] = ts
+        # Create tables if necessary
+        lnt.server.db.testsuitedb.TestSuiteDB(self, suite.name, suite,
+                                              create_tables=True)
 
     def _load_schemas(self, session):
         # Load schema files (preferred)
@@ -52,18 +48,10 @@ class V4DB(object):
             except Exception as e:
                 fatal("Could not load schema '%s': %s\n" % (schema_file, e))
 
-        # Load schemas from database (deprecated)
-        ts_list = session.query(testsuite.TestSuite) \
-            .options(subqueryload(testsuite.TestSuite.sample_fields)
-                     .joinedload(testsuite.SampleField.status_field)) \
-            .options(joinedload(testsuite.TestSuite.order_fields)) \
-            .options(joinedload(testsuite.TestSuite.run_fields)) \
-            .options(joinedload(testsuite.TestSuite.machine_fields)) \
-            .all()
+        # Load schemas from database.
+        ts_list = session.query(testsuite.TestSuite).all()
         for suite in ts_list:
             name = suite.name
-            if name in self.testsuite:
-                continue
             ts = lnt.server.db.testsuitedb.TestSuiteDB(self, name, suite,
                                                        create_tables=False)
             self.testsuite[name] = ts




More information about the llvm-commits mailing list