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
Package registry
Container registry
Model registry
Operate
Terraform modules
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
Timo Ley
synapse
Commits
041b6cba
Commit
041b6cba
authored
9 years ago
by
Mark Haines
Browse files
Options
Downloads
Patches
Plain Diff
SYN-369: Add comments to the sequence number logic in the cache
parent
63075118
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/storage/_base.py
+7
-0
7 additions, 0 deletions
synapse/storage/_base.py
with
7 additions
and
0 deletions
synapse/storage/_base.py
+
7
−
0
View file @
041b6cba
...
@@ -98,6 +98,8 @@ class Cache(object):
...
@@ -98,6 +98,8 @@ class Cache(object):
def
update
(
self
,
sequence
,
*
args
):
def
update
(
self
,
sequence
,
*
args
):
self
.
check_thread
()
self
.
check_thread
()
if
self
.
sequence
==
sequence
:
if
self
.
sequence
==
sequence
:
# Only update the cache if the caches sequence number matches the
# number that the cache had before the SELECT was started (SYN-369)
self
.
prefill
(
*
args
)
self
.
prefill
(
*
args
)
def
prefill
(
self
,
*
args
):
# because I can't *keyargs, value
def
prefill
(
self
,
*
args
):
# because I can't *keyargs, value
...
@@ -117,6 +119,8 @@ class Cache(object):
...
@@ -117,6 +119,8 @@ class Cache(object):
self
.
check_thread
()
self
.
check_thread
()
if
len
(
keyargs
)
!=
self
.
keylen
:
if
len
(
keyargs
)
!=
self
.
keylen
:
raise
ValueError
(
"
Expected a key to have %d items
"
,
self
.
keylen
)
raise
ValueError
(
"
Expected a key to have %d items
"
,
self
.
keylen
)
# Increment the sequence number so that any SELECT statements that
# raced with the INSERT don't update the cache (SYN-369)
self
.
sequence
+=
1
self
.
sequence
+=
1
self
.
cache
.
pop
(
keyargs
,
None
)
self
.
cache
.
pop
(
keyargs
,
None
)
...
@@ -159,6 +163,9 @@ def cached(max_entries=1000, num_args=1, lru=False):
...
@@ -159,6 +163,9 @@ def cached(max_entries=1000, num_args=1, lru=False):
raise
ValueError
(
"
Stale cache entry
"
)
raise
ValueError
(
"
Stale cache entry
"
)
defer
.
returnValue
(
cached_result
)
defer
.
returnValue
(
cached_result
)
except
KeyError
:
except
KeyError
:
# Get the sequence number of the cache before reading from the
# database so that we can tell if the cache is invalidated
# while the SELECT is executing (SYN-369)
sequence
=
cache
.
sequence
sequence
=
cache
.
sequence
ret
=
yield
orig
(
self
,
*
keyargs
)
ret
=
yield
orig
(
self
,
*
keyargs
)
...
...
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