mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-07-28 11:44:07 -04:00
Split state groups into a separate data store (#6296)
This commit is contained in:
parent
fa780e9721
commit
75d8f26ac8
28 changed files with 1159 additions and 1168 deletions
|
@ -1,16 +0,0 @@
|
|||
/* Copyright 2015, 2016 OpenMarket Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
DROP INDEX IF EXISTS state_groups_state_tuple;
|
|
@ -1,33 +0,0 @@
|
|||
/* Copyright 2016 OpenMarket Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
/* We used to create a table called current_state_resets, but this is no
|
||||
* longer used and is removed in delta 54.
|
||||
*/
|
||||
|
||||
/* The outlier events that have aquired a state group typically through
|
||||
* backfill. This is tracked separately to the events table, as assigning a
|
||||
* state group change the position of the existing event in the stream
|
||||
* ordering.
|
||||
* However since a stream_ordering is assigned in persist_event for the
|
||||
* (event, state) pair, we can use that stream_ordering to identify when
|
||||
* the new state was assigned for the event.
|
||||
*/
|
||||
CREATE TABLE IF NOT EXISTS ex_outlier_stream(
|
||||
event_stream_ordering BIGINT PRIMARY KEY NOT NULL,
|
||||
event_id TEXT NOT NULL,
|
||||
state_group BIGINT NOT NULL
|
||||
);
|
|
@ -20,7 +20,6 @@ DROP INDEX IF EXISTS events_room_id; -- Prefix of events_room_stream
|
|||
DROP INDEX IF EXISTS events_order; -- Prefix of events_order_topo_stream_room
|
||||
DROP INDEX IF EXISTS events_topological_ordering; -- Prefix of events_order_topo_stream_room
|
||||
DROP INDEX IF EXISTS events_stream_ordering; -- Duplicate of PRIMARY KEY
|
||||
DROP INDEX IF EXISTS state_groups_id; -- Duplicate of PRIMARY KEY
|
||||
DROP INDEX IF EXISTS event_to_state_groups_id; -- Duplicate of PRIMARY KEY
|
||||
DROP INDEX IF EXISTS event_push_actions_room_id_event_id_user_id_profile_tag; -- Duplicate of UNIQUE CONSTRAINT
|
||||
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
/* Copyright 2016 OpenMarket Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
INSERT into background_updates (update_name, progress_json, depends_on)
|
||||
VALUES ('state_group_state_type_index', '{}', 'state_group_state_deduplication');
|
|
@ -1,22 +0,0 @@
|
|||
/* Copyright 2016 OpenMarket Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
CREATE TABLE state_group_edges(
|
||||
state_group BIGINT NOT NULL,
|
||||
prev_state_group BIGINT NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX state_group_edges_idx ON state_group_edges(state_group);
|
||||
CREATE INDEX state_group_edges_prev_idx ON state_group_edges(prev_state_group);
|
|
@ -1,17 +0,0 @@
|
|||
/* Copyright 2016 OpenMarket Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
INSERT into background_updates (update_name, progress_json)
|
||||
VALUES ('state_group_state_deduplication', '{}');
|
|
@ -1,34 +0,0 @@
|
|||
# Copyright 2018 New Vector Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from synapse.storage.engines import PostgresEngine
|
||||
|
||||
|
||||
def run_create(cur, database_engine, *args, **kwargs):
|
||||
if isinstance(database_engine, PostgresEngine):
|
||||
# if we already have some state groups, we want to start making new
|
||||
# ones with a higher id.
|
||||
cur.execute("SELECT max(id) FROM state_groups")
|
||||
row = cur.fetchone()
|
||||
|
||||
if row[0] is None:
|
||||
start_val = 1
|
||||
else:
|
||||
start_val = row[0] + 1
|
||||
|
||||
cur.execute("CREATE SEQUENCE state_group_id_seq START WITH %s", (start_val,))
|
||||
|
||||
|
||||
def run_upgrade(*args, **kwargs):
|
||||
pass
|
|
@ -975,40 +975,6 @@ CREATE TABLE state_events (
|
|||
|
||||
|
||||
|
||||
CREATE TABLE state_group_edges (
|
||||
state_group bigint NOT NULL,
|
||||
prev_state_group bigint NOT NULL
|
||||
);
|
||||
|
||||
|
||||
|
||||
CREATE SEQUENCE state_group_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
|
||||
CREATE TABLE state_groups (
|
||||
id bigint NOT NULL,
|
||||
room_id text NOT NULL,
|
||||
event_id text NOT NULL
|
||||
);
|
||||
|
||||
|
||||
|
||||
CREATE TABLE state_groups_state (
|
||||
state_group bigint NOT NULL,
|
||||
room_id text NOT NULL,
|
||||
type text NOT NULL,
|
||||
state_key text NOT NULL,
|
||||
event_id text NOT NULL
|
||||
);
|
||||
|
||||
|
||||
|
||||
CREATE TABLE stats_stream_pos (
|
||||
lock character(1) DEFAULT 'X'::bpchar NOT NULL,
|
||||
stream_id bigint,
|
||||
|
@ -1482,12 +1448,6 @@ ALTER TABLE ONLY state_events
|
|||
ADD CONSTRAINT state_events_event_id_key UNIQUE (event_id);
|
||||
|
||||
|
||||
|
||||
ALTER TABLE ONLY state_groups
|
||||
ADD CONSTRAINT state_groups_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
|
||||
ALTER TABLE ONLY stats_stream_pos
|
||||
ADD CONSTRAINT stats_stream_pos_lock_key UNIQUE (lock);
|
||||
|
||||
|
@ -1928,18 +1888,6 @@ CREATE UNIQUE INDEX room_stats_room_ts ON room_stats USING btree (room_id, ts);
|
|||
|
||||
|
||||
|
||||
CREATE INDEX state_group_edges_idx ON state_group_edges USING btree (state_group);
|
||||
|
||||
|
||||
|
||||
CREATE INDEX state_group_edges_prev_idx ON state_group_edges USING btree (prev_state_group);
|
||||
|
||||
|
||||
|
||||
CREATE INDEX state_groups_state_type_idx ON state_groups_state USING btree (state_group, type, state_key);
|
||||
|
||||
|
||||
|
||||
CREATE INDEX stream_ordering_to_exterm_idx ON stream_ordering_to_exterm USING btree (stream_ordering);
|
||||
|
||||
|
||||
|
|
|
@ -42,8 +42,6 @@ CREATE INDEX ev_edges_id ON event_edges(event_id);
|
|||
CREATE INDEX ev_edges_prev_id ON event_edges(prev_event_id);
|
||||
CREATE TABLE room_depth( room_id TEXT NOT NULL, min_depth INTEGER NOT NULL, UNIQUE (room_id) );
|
||||
CREATE INDEX room_depth_room ON room_depth(room_id);
|
||||
CREATE TABLE state_groups( id BIGINT PRIMARY KEY, room_id TEXT NOT NULL, event_id TEXT NOT NULL );
|
||||
CREATE TABLE state_groups_state( state_group BIGINT NOT NULL, room_id TEXT NOT NULL, type TEXT NOT NULL, state_key TEXT NOT NULL, event_id TEXT NOT NULL );
|
||||
CREATE TABLE event_to_state_groups( event_id TEXT NOT NULL, state_group BIGINT NOT NULL, UNIQUE (event_id) );
|
||||
CREATE TABLE local_media_repository ( media_id TEXT, media_type TEXT, media_length INTEGER, created_ts BIGINT, upload_name TEXT, user_id TEXT, quarantined_by TEXT, url_cache TEXT, last_access_ts BIGINT, UNIQUE (media_id) );
|
||||
CREATE TABLE local_media_repository_thumbnails ( media_id TEXT, thumbnail_width INTEGER, thumbnail_height INTEGER, thumbnail_type TEXT, thumbnail_method TEXT, thumbnail_length INTEGER, UNIQUE ( media_id, thumbnail_width, thumbnail_height, thumbnail_type ) );
|
||||
|
@ -120,9 +118,6 @@ CREATE TABLE device_max_stream_id ( stream_id BIGINT NOT NULL );
|
|||
CREATE TABLE public_room_list_stream ( stream_id BIGINT NOT NULL, room_id TEXT NOT NULL, visibility BOOLEAN NOT NULL , appservice_id TEXT, network_id TEXT);
|
||||
CREATE INDEX public_room_list_stream_idx on public_room_list_stream( stream_id );
|
||||
CREATE INDEX public_room_list_stream_rm_idx on public_room_list_stream( room_id, stream_id );
|
||||
CREATE TABLE state_group_edges( state_group BIGINT NOT NULL, prev_state_group BIGINT NOT NULL );
|
||||
CREATE INDEX state_group_edges_idx ON state_group_edges(state_group);
|
||||
CREATE INDEX state_group_edges_prev_idx ON state_group_edges(prev_state_group);
|
||||
CREATE TABLE stream_ordering_to_exterm ( stream_ordering BIGINT NOT NULL, room_id TEXT NOT NULL, event_id TEXT NOT NULL );
|
||||
CREATE INDEX stream_ordering_to_exterm_idx on stream_ordering_to_exterm( stream_ordering );
|
||||
CREATE INDEX stream_ordering_to_exterm_rm_idx on stream_ordering_to_exterm( room_id, stream_ordering );
|
||||
|
@ -254,6 +249,5 @@ CREATE INDEX user_ips_last_seen_only ON user_ips (last_seen);
|
|||
CREATE INDEX users_creation_ts ON users (creation_ts);
|
||||
CREATE INDEX event_to_state_groups_sg_index ON event_to_state_groups (state_group);
|
||||
CREATE UNIQUE INDEX device_lists_remote_cache_unique_id ON device_lists_remote_cache (user_id, device_id);
|
||||
CREATE INDEX state_groups_state_type_idx ON state_groups_state(state_group, type, state_key);
|
||||
CREATE UNIQUE INDEX device_lists_remote_extremeties_unique_idx ON device_lists_remote_extremeties (user_id);
|
||||
CREATE UNIQUE INDEX user_ips_user_token_ip_unique_index ON user_ips (user_id, access_token, ip);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue