[LNT] r312398 - Create shorter lived session in v4db init
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 1 17:35:57 PDT 2017
Author: matze
Date: Fri Sep 1 17:35:56 2017
New Revision: 312398
URL: http://llvm.org/viewvc/llvm-project?rev=312398&view=rev
Log:
Create shorter lived session in v4db init
The next attempt to avoid database deadlocks in the metadata tables:
Make sure no session is active when we create tables.
Modified:
lnt/trunk/lnt/server/db/testsuitedb.py
lnt/trunk/lnt/server/db/v4db.py
Modified: lnt/trunk/lnt/server/db/testsuitedb.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/testsuitedb.py?rev=312398&r1=312397&r2=312398&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/testsuitedb.py (original)
+++ lnt/trunk/lnt/server/db/testsuitedb.py Fri Sep 1 17:35:56 2017
@@ -74,7 +74,7 @@ class TestSuiteDB(object):
through the model classes constructed by this wrapper object.
"""
- def __init__(self, v4db, name, test_suite, create_tables=False):
+ def __init__(self, v4db, name, test_suite):
testsuitedb = self
self.v4db = v4db
self.name = name
@@ -748,8 +748,8 @@ class TestSuiteDB(object):
sqlalchemy.schema.Index("ix_%s_Sample_RunID_TestID" % db_key_name,
Sample.run_id, Sample.test_id)
- if create_tables:
- self.base.metadata.create_all(v4db.engine)
+ def create_tables(self, engine):
+ self.base.metadata.create_all(engine)
def get_baselines(self, session):
return session.query(self.Baseline).all()
Modified: lnt/trunk/lnt/server/db/v4db.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/v4db.py?rev=312398&r1=312397&r2=312398&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/v4db.py (original)
+++ lnt/trunk/lnt/server/db/v4db.py Fri Sep 1 17:35:56 2017
@@ -27,7 +27,8 @@ class V4DB(object):
"""
_engine_lock = threading.Lock()
_engines = []
- def _load_schema_file(self, session, schema_file):
+ def _load_schema_file(self, schema_file):
+ session = self.make_session()
with open(schema_file) as schema_fd:
data = yaml.load(schema_fd)
suite = testsuite.TestSuite.from_json(data)
@@ -36,24 +37,27 @@ class V4DB(object):
session.commit()
# Create tables if necessary
- lnt.server.db.testsuitedb.TestSuiteDB(self, suite.name, suite,
- create_tables=True)
+ tsdb = lnt.server.db.testsuitedb.TestSuiteDB(self, suite.name, suite)
+ session.close()
+ tsdb.create_tables(self.engine)
- def _load_schemas(self, session):
+ def _load_schemas(self):
# Load schema files (preferred)
schemasDir = self.config.schemasDir
for schema_file in glob.glob('%s/*.yaml' % schemasDir):
try:
- self._load_schema_file(session, schema_file)
+ self._load_schema_file(schema_file)
except Exception as e:
fatal("Could not load schema '%s': %s\n" % (schema_file, e))
# Load schemas from database.
+ session = self.make_session()
ts_list = session.query(testsuite.TestSuite).all()
+ session.expunge_all()
+ session.close()
for suite in ts_list:
name = suite.name
- ts = lnt.server.db.testsuitedb.TestSuiteDB(self, name, suite,
- create_tables=False)
+ ts = lnt.server.db.testsuitedb.TestSuiteDB(self, name, suite)
self.testsuite[name] = ts
def __init__(self, path, config, baseline_revision=0):
@@ -80,12 +84,9 @@ class V4DB(object):
lnt.server.db.migrate.update(self.engine)
self.sessionmaker = sqlalchemy.orm.sessionmaker(self.engine)
- session = self.make_session()
self.testsuite = dict()
- self._load_schemas(session)
- session.expunge_all()
- session.close()
+ self._load_schemas()
def close(self):
self.engine.dispose()
More information about the llvm-commits
mailing list