Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mentat-test
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
713
Mentat
mentat-test
Commits
0396d2ef
Commit
0396d2ef
authored
3 years ago
by
Rajmund Hruška
Browse files
Options
Downloads
Plain Diff
Merge branch 'hruska-feature-#6205-sqlalchemy-v2' into devel
parents
8a33c6f5
4286f394
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/mentat/services/sqlstorage.py
+14
-8
14 additions, 8 deletions
lib/mentat/services/sqlstorage.py
lib/mentat/services/whois.py
+1
-4
1 addition, 4 deletions
lib/mentat/services/whois.py
with
15 additions
and
12 deletions
lib/mentat/services/sqlstorage.py
+
14
−
8
View file @
0396d2ef
...
...
@@ -10,7 +10,8 @@
"""
Database storage abstraction layer. The current implementation is based on the
awesome `SQLAlchemy <http://www.sqlalchemy.org/>`__ library.
awesome `SQLAlchemy <http://www.sqlalchemy.org/>`__ library accessed by
`flask_sqlalchemy <https://flask-sqlalchemy.palletsprojects.com/>`__.
.. warning::
...
...
@@ -26,8 +27,8 @@ __credits__ = "Pavel Kácha <pavel.kacha@cesnet.cz>, Andrea Kropáčová <andrea
import
copy
import
sqlalchemy
from
sqlalchemy.orm
import
Quer
y
from
flask
import
Flask
import
flask_sqlalchem
y
#
# Custom libraries
...
...
@@ -39,7 +40,7 @@ from mentat.datatype.sqldb import MODEL
_MANAGER
=
None
class
RetryingQuery
(
Query
):
class
RetryingQuery
(
flask_sqlalchemy
.
orm
.
Query
):
"""
An override of SQLAlchemy
'
s Query class, allowing for recovery from a lost DB
connection.
...
...
@@ -48,7 +49,7 @@ class RetryingQuery(Query):
for
_
in
range
(
2
):
try
:
return
super
().
_execute_and_instances
(
querycontext
)
except
sqlalchemy
.
exc
.
OperationalError
:
except
flask_
sqlalchemy
.
orm
.
exc
.
sa_
exc
.
OperationalError
:
self
.
session
.
close
()
continue
...
...
@@ -67,9 +68,14 @@ class StorageService:
:param enginecfg: Connection arguments.
"""
self
.
dbengine
=
sqlalchemy
.
engine_from_config
(
enginecfg
,
prefix
=
''
)
self
.
sessionmaker
=
sqlalchemy
.
orm
.
sessionmaker
(
bind
=
self
.
dbengine
)
self
.
_session
=
self
.
sessionmaker
(
query_cls
=
RetryingQuery
)
self
.
app
=
Flask
(
__name__
)
self
.
app
.
config
[
'
SQLALCHEMY_DATABASE_URI
'
]
=
enginecfg
[
'
url
'
]
self
.
app
.
config
[
'
SQLALCHEMY_TRACK_MODIFICATIONS
'
]
=
False
self
.
db
=
flask_sqlalchemy
.
SQLAlchemy
(
self
.
app
)
self
.
dbengine
=
self
.
db
.
engine_from_config
(
enginecfg
,
prefix
=
''
)
self
.
sessionmaker
=
flask_sqlalchemy
.
orm
.
sessionmaker
(
bind
=
self
.
dbengine
)
self
.
_session
=
self
.
sessionmaker
(
query_cls
=
RetryingQuery
)
def
__del__
(
self
):
self
.
close
()
...
...
This diff is collapsed.
Click to expand it.
lib/mentat/services/whois.py
+
1
−
4
View file @
0396d2ef
...
...
@@ -270,10 +270,7 @@ class SqldbWhoisModule(WhoisModule):
})
networks
.
append
(
netw
)
# Use rollback to close transaction, please see issue #4251 for details.
# In short: In SQLAlchemy commit immediatelly opens new transaction, which
# then keeps hanging in "transaction-idle" state.
storage
.
session
.
rollback
()
storage
.
session
.
commit
()
# Let the parent implementation take care of loading internal lookup table.
return
super
().
setup
(
networks
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment