Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
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
TeDomum
Matrix
Commits
cd94728e
Unverified
Commit
cd94728e
authored
7 years ago
by
Erik Johnston
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #2871 from matrix-org/erikj/event_creator_state
Fix state group storage bug in workers
parents
b8d821aa
fd1601c5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/storage/state.py
+41
-41
41 additions, 41 deletions
synapse/storage/state.py
with
41 additions
and
41 deletions
synapse/storage/state.py
+
41
−
41
View file @
cd94728e
...
...
@@ -655,6 +655,47 @@ class StateGroupWorkerStore(SQLBaseStore):
return
self
.
runInteraction
(
"
store_state_group
"
,
_store_state_group_txn
)
def
_count_state_group_hops_txn
(
self
,
txn
,
state_group
):
"""
Given a state group, count how many hops there are in the tree.
This is used to ensure the delta chains don
'
t get too long.
"""
if
isinstance
(
self
.
database_engine
,
PostgresEngine
):
sql
=
(
"""
WITH RECURSIVE state(state_group) AS (
VALUES(?::bigint)
UNION ALL
SELECT prev_state_group FROM state_group_edges e, state s
WHERE s.state_group = e.state_group
)
SELECT count(*) FROM state;
"""
)
txn
.
execute
(
sql
,
(
state_group
,))
row
=
txn
.
fetchone
()
if
row
and
row
[
0
]:
return
row
[
0
]
else
:
return
0
else
:
# We don't use WITH RECURSIVE on sqlite3 as there are distributions
# that ship with an sqlite3 version that doesn't support it (e.g. wheezy)
next_group
=
state_group
count
=
0
while
next_group
:
next_group
=
self
.
_simple_select_one_onecol_txn
(
txn
,
table
=
"
state_group_edges
"
,
keyvalues
=
{
"
state_group
"
:
next_group
},
retcol
=
"
prev_state_group
"
,
allow_none
=
True
,
)
if
next_group
:
count
+=
1
return
count
class
StateStore
(
StateGroupWorkerStore
,
BackgroundUpdateStore
):
"""
Keeps track of the state at a given event.
...
...
@@ -729,47 +770,6 @@ class StateStore(StateGroupWorkerStore, BackgroundUpdateStore):
(
event_id
,),
state_group_id
)
def
_count_state_group_hops_txn
(
self
,
txn
,
state_group
):
"""
Given a state group, count how many hops there are in the tree.
This is used to ensure the delta chains don
'
t get too long.
"""
if
isinstance
(
self
.
database_engine
,
PostgresEngine
):
sql
=
(
"""
WITH RECURSIVE state(state_group) AS (
VALUES(?::bigint)
UNION ALL
SELECT prev_state_group FROM state_group_edges e, state s
WHERE s.state_group = e.state_group
)
SELECT count(*) FROM state;
"""
)
txn
.
execute
(
sql
,
(
state_group
,))
row
=
txn
.
fetchone
()
if
row
and
row
[
0
]:
return
row
[
0
]
else
:
return
0
else
:
# We don't use WITH RECURSIVE on sqlite3 as there are distributions
# that ship with an sqlite3 version that doesn't support it (e.g. wheezy)
next_group
=
state_group
count
=
0
while
next_group
:
next_group
=
self
.
_simple_select_one_onecol_txn
(
txn
,
table
=
"
state_group_edges
"
,
keyvalues
=
{
"
state_group
"
:
next_group
},
retcol
=
"
prev_state_group
"
,
allow_none
=
True
,
)
if
next_group
:
count
+=
1
return
count
@defer.inlineCallbacks
def
_background_deduplicate_state
(
self
,
progress
,
batch_size
):
"""
This background update will slowly deduplicate state by reencoding
...
...
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