Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
8615f19d
Commit
8615f19d
authored
7 years ago
by
Richard van der Hoff
Browse files
Options
Downloads
Patches
Plain Diff
rework runInteraction in terms of runConnection
... so that we can share the code
parent
febdca4b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/storage/_base.py
+31
-20
31 additions, 20 deletions
synapse/storage/_base.py
with
31 additions
and
20 deletions
synapse/storage/_base.py
+
31
−
20
View file @
8615f19d
...
@@ -291,33 +291,33 @@ class SQLBaseStore(object):
...
@@ -291,33 +291,33 @@ class SQLBaseStore(object):
@defer.inlineCallbacks
@defer.inlineCallbacks
def
runInteraction
(
self
,
desc
,
func
,
*
args
,
**
kwargs
):
def
runInteraction
(
self
,
desc
,
func
,
*
args
,
**
kwargs
):
"""
Wraps the .runInteraction() method on the underlying db_pool.
"""
"""
Starts a transaction on the database and runs a given function
current_context
=
LoggingContext
.
current_context
()
start_time
=
time
.
time
()
*
1000
Arguments:
desc (str): description of the transaction, for logging and metrics
func (func): callback function, which will be called with a
database transaction (twisted.enterprise.adbapi.Transaction) as
its first argument, followed by `args` and `kwargs`.
args (list): positional args to pass to `func`
kwargs (dict): named args to pass to `func`
Returns:
Deferred: The result of func
"""
current_context
=
LoggingContext
.
current_context
()
after_callbacks
=
[]
after_callbacks
=
[]
final_callbacks
=
[]
final_callbacks
=
[]
def
inner_func
(
conn
,
*
args
,
**
kwargs
):
def
inner_func
(
conn
,
*
args
,
**
kwargs
):
with
LoggingContext
(
"
runInteraction
"
)
as
context
:
return
self
.
_new_transaction
(
sql_scheduling_timer
.
inc_by
(
time
.
time
()
*
1000
-
start_time
)
conn
,
desc
,
after_callbacks
,
final_callbacks
,
current_context
,
func
,
*
args
,
**
kwargs
if
self
.
database_engine
.
is_connection_closed
(
conn
):
)
logger
.
debug
(
"
Reconnecting closed database connection
"
)
conn
.
reconnect
()
current_context
.
copy_to
(
context
)
return
self
.
_new_transaction
(
conn
,
desc
,
after_callbacks
,
final_callbacks
,
current_context
,
func
,
*
args
,
**
kwargs
)
try
:
try
:
with
PreserveLoggingContext
():
result
=
yield
self
.
runWithConnection
(
inner_func
,
*
args
,
**
kwargs
)
result
=
yield
self
.
_db_pool
.
runWithConnection
(
inner_func
,
*
args
,
**
kwargs
)
for
after_callback
,
after_args
,
after_kwargs
in
after_callbacks
:
for
after_callback
,
after_args
,
after_kwargs
in
after_callbacks
:
after_callback
(
*
after_args
,
**
after_kwargs
)
after_callback
(
*
after_args
,
**
after_kwargs
)
...
@@ -329,7 +329,18 @@ class SQLBaseStore(object):
...
@@ -329,7 +329,18 @@ class SQLBaseStore(object):
@defer.inlineCallbacks
@defer.inlineCallbacks
def
runWithConnection
(
self
,
func
,
*
args
,
**
kwargs
):
def
runWithConnection
(
self
,
func
,
*
args
,
**
kwargs
):
"""
Wraps the .runInteraction() method on the underlying db_pool.
"""
"""
Wraps the .runWithConnection() method on the underlying db_pool.
Arguments:
func (func): callback function, which will be called with a
database connection (twisted.enterprise.adbapi.Connection) as
its first argument, followed by `args` and `kwargs`.
args (list): positional args to pass to `func`
kwargs (dict): named args to pass to `func`
Returns:
Deferred: The result of func
"""
current_context
=
LoggingContext
.
current_context
()
current_context
=
LoggingContext
.
current_context
()
start_time
=
time
.
time
()
*
1000
start_time
=
time
.
time
()
*
1000
...
...
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