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
922788c6
Unverified
Commit
922788c6
authored
4 years ago
by
Patrick Cloke
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Purge chain cover tables when purging events. (#9498)
parent
d790d0d3
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
changelog.d/9498.bugfix
+1
-0
1 addition, 0 deletions
changelog.d/9498.bugfix
synapse/storage/databases/main/purge_events.py
+37
-5
37 additions, 5 deletions
synapse/storage/databases/main/purge_events.py
synapse/storage/purge_events.py
+0
-5
0 additions, 5 deletions
synapse/storage/purge_events.py
with
38 additions
and
10 deletions
changelog.d/9498.bugfix
0 → 100644
+
1
−
0
View file @
922788c6
Properly purge the event chain cover index when purging history.
This diff is collapsed.
Click to expand it.
synapse/storage/databases/main/purge_events.py
+
37
−
5
View file @
922788c6
...
...
@@ -28,7 +28,10 @@ class PurgeEventsStore(StateGroupWorkerStore, SQLBaseStore):
async
def
purge_history
(
self
,
room_id
:
str
,
token
:
str
,
delete_local_events
:
bool
)
->
Set
[
int
]:
"""
Deletes room history before a certain point
"""
Deletes room history before a certain point.
Note that only a single purge can occur at once, this is guaranteed via
a higher level (in the PaginationHandler).
Args:
room_id:
...
...
@@ -52,7 +55,9 @@ class PurgeEventsStore(StateGroupWorkerStore, SQLBaseStore):
delete_local_events
,
)
def
_purge_history_txn
(
self
,
txn
,
room_id
,
token
,
delete_local_events
):
def
_purge_history_txn
(
self
,
txn
,
room_id
:
str
,
token
:
RoomStreamToken
,
delete_local_events
:
bool
)
->
Set
[
int
]:
# Tables that should be pruned:
# event_auth
# event_backward_extremities
...
...
@@ -103,7 +108,7 @@ class PurgeEventsStore(StateGroupWorkerStore, SQLBaseStore):
if
max_depth
<
token
.
topological
:
# We need to ensure we don't delete all the events from the database
# otherwise we wouldn't be able to send any events (due to not
# having any backwards extrem
e
ties)
# having any backwards extrem
i
ties)
raise
SynapseError
(
400
,
"
topological_ordering is greater than forward extremeties
"
)
...
...
@@ -154,7 +159,7 @@ class PurgeEventsStore(StateGroupWorkerStore, SQLBaseStore):
logger
.
info
(
"
[purge] Finding new backward extremities
"
)
# We calculate the new entries for the backward extrem
e
ties by finding
# We calculate the new entries for the backward extrem
i
ties by finding
# events to be purged that are pointed to by events we're not going to
# purge.
txn
.
execute
(
...
...
@@ -296,7 +301,7 @@ class PurgeEventsStore(StateGroupWorkerStore, SQLBaseStore):
"
purge_room
"
,
self
.
_purge_room_txn
,
room_id
)
def
_purge_room_txn
(
self
,
txn
,
room_id
)
:
def
_purge_room_txn
(
self
,
txn
,
room_id
:
str
)
->
List
[
int
]
:
# First we fetch all the state groups that should be deleted, before
# we delete that information.
txn
.
execute
(
...
...
@@ -310,6 +315,31 @@ class PurgeEventsStore(StateGroupWorkerStore, SQLBaseStore):
state_groups
=
[
row
[
0
]
for
row
in
txn
]
# Get all the auth chains that are referenced by events that are to be
# deleted.
txn
.
execute
(
"""
SELECT chain_id, sequence_number FROM events
LEFT JOIN event_auth_chains USING (event_id)
WHERE room_id = ?
"""
,
(
room_id
,),
)
referenced_chain_id_tuples
=
list
(
txn
)
logger
.
info
(
"
[purge] removing events from event_auth_chain_links
"
)
txn
.
executemany
(
"""
DELETE FROM event_auth_chain_links WHERE
(origin_chain_id = ? AND origin_sequence_number = ?) OR
(target_chain_id = ? AND target_sequence_number = ?)
"""
,
(
(
chain_id
,
seq_num
,
chain_id
,
seq_num
)
for
(
chain_id
,
seq_num
)
in
referenced_chain_id_tuples
),
)
# Now we delete tables which lack an index on room_id but have one on event_id
for
table
in
(
"
event_auth
"
,
...
...
@@ -319,6 +349,8 @@ class PurgeEventsStore(StateGroupWorkerStore, SQLBaseStore):
"
event_reference_hashes
"
,
"
event_relations
"
,
"
event_to_state_groups
"
,
"
event_auth_chains
"
,
"
event_auth_chain_to_calculate
"
,
"
redactions
"
,
"
rejections
"
,
"
state_events
"
,
...
...
This diff is collapsed.
Click to expand it.
synapse/storage/purge_events.py
+
0
−
5
View file @
922788c6
...
...
@@ -73,9 +73,6 @@ class PurgeEventsStorage:
Returns:
The set of state groups that can be deleted.
"""
# Graph of state group -> previous group
graph
=
{}
# Set of events that we have found to be referenced by events
referenced_groups
=
set
()
...
...
@@ -111,8 +108,6 @@ class PurgeEventsStorage:
next_to_search
|=
prevs
state_groups_seen
|=
prevs
graph
.
update
(
edges
)
to_delete
=
state_groups_seen
-
referenced_groups
return
to_delete
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