2016-04-06 07:12:51 -06:00
|
|
|
# Copyright 2016 OpenMarket Ltd
|
2018-02-23 04:14:35 -07:00
|
|
|
# Copyright 2018 New Vector Ltd
|
2016-04-06 07:12:51 -06:00
|
|
|
#
|
|
|
|
# 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.
|
2017-11-09 12:00:20 -07:00
|
|
|
import logging
|
2021-10-22 11:15:41 -06:00
|
|
|
from typing import TYPE_CHECKING
|
2016-04-06 07:12:51 -06:00
|
|
|
|
2020-08-05 14:38:57 -06:00
|
|
|
from synapse.storage.database import DatabasePool
|
|
|
|
from synapse.storage.databases.main.event_federation import EventFederationWorkerStore
|
|
|
|
from synapse.storage.databases.main.event_push_actions import (
|
2019-10-21 05:56:42 -06:00
|
|
|
EventPushActionsWorkerStore,
|
|
|
|
)
|
2020-08-05 14:38:57 -06:00
|
|
|
from synapse.storage.databases.main.events_worker import EventsWorkerStore
|
|
|
|
from synapse.storage.databases.main.relations import RelationsWorkerStore
|
|
|
|
from synapse.storage.databases.main.roommember import RoomMemberWorkerStore
|
|
|
|
from synapse.storage.databases.main.signatures import SignatureWorkerStore
|
|
|
|
from synapse.storage.databases.main.state import StateGroupWorkerStore
|
|
|
|
from synapse.storage.databases.main.stream import StreamWorkerStore
|
|
|
|
from synapse.storage.databases.main.user_erasure_store import UserErasureWorkerStore
|
2020-02-25 09:56:55 -07:00
|
|
|
from synapse.util.caches.stream_change_cache import StreamChangeCache
|
2018-07-09 00:09:20 -06:00
|
|
|
|
2017-11-09 12:00:20 -07:00
|
|
|
from ._base import BaseSlavedStore
|
2016-11-17 08:46:44 -07:00
|
|
|
|
2021-10-22 11:15:41 -06:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from synapse.server import HomeServer
|
|
|
|
|
2016-11-17 08:46:44 -07:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2016-04-06 07:12:51 -06:00
|
|
|
|
|
|
|
# So, um, we want to borrow a load of functions intended for reading from
|
|
|
|
# a DataStore, but we don't want to take functions that either write to the
|
|
|
|
# DataStore or are cached and don't have cache invalidation logic.
|
|
|
|
#
|
|
|
|
# Rather than write duplicate versions of those functions, or lift them to
|
|
|
|
# a common base class, we going to grab the underlying __func__ object from
|
|
|
|
# the method descriptor on the DataStore and chuck them into our class.
|
|
|
|
|
|
|
|
|
2018-03-01 07:16:02 -07:00
|
|
|
class SlavedEventStore(
|
|
|
|
EventFederationWorkerStore,
|
|
|
|
RoomMemberWorkerStore,
|
|
|
|
EventPushActionsWorkerStore,
|
2018-03-01 09:59:39 -07:00
|
|
|
StreamWorkerStore,
|
2018-03-01 07:16:02 -07:00
|
|
|
StateGroupWorkerStore,
|
2018-07-25 15:10:39 -06:00
|
|
|
EventsWorkerStore,
|
2018-03-01 07:16:02 -07:00
|
|
|
SignatureWorkerStore,
|
2018-06-25 07:22:24 -06:00
|
|
|
UserErasureWorkerStore,
|
2019-05-16 03:18:53 -06:00
|
|
|
RelationsWorkerStore,
|
2018-02-23 04:46:24 -07:00
|
|
|
BaseSlavedStore,
|
|
|
|
):
|
2021-10-22 11:15:41 -06:00
|
|
|
def __init__(self, database: DatabasePool, db_conn, hs: "HomeServer"):
|
2020-09-18 07:56:44 -06:00
|
|
|
super().__init__(database, db_conn, hs)
|
2016-09-15 04:47:23 -06:00
|
|
|
|
2020-02-25 09:56:55 -07:00
|
|
|
events_max = self._stream_id_gen.get_current_token()
|
2020-08-05 14:38:57 -06:00
|
|
|
curr_state_delta_prefill, min_curr_state_delta_id = self.db_pool.get_cache_dict(
|
2020-02-25 09:56:55 -07:00
|
|
|
db_conn,
|
|
|
|
"current_state_delta_stream",
|
|
|
|
entity_column="room_id",
|
|
|
|
stream_column="stream_id",
|
|
|
|
max_value=events_max, # As we share the stream id with events token
|
|
|
|
limit=1000,
|
|
|
|
)
|
|
|
|
self._curr_state_delta_stream_cache = StreamChangeCache(
|
|
|
|
"_curr_state_delta_stream_cache",
|
|
|
|
min_curr_state_delta_id,
|
|
|
|
prefilled_cache=curr_state_delta_prefill,
|
|
|
|
)
|
|
|
|
|
2016-04-06 07:12:51 -06:00
|
|
|
# Cached functions can't be accessed through a class instance so we need
|
|
|
|
# to reach inside the __dict__ to extract them.
|
2018-02-23 04:46:24 -07:00
|
|
|
|
2018-03-01 06:56:03 -07:00
|
|
|
def get_room_max_stream_ordering(self):
|
|
|
|
return self._stream_id_gen.get_current_token()
|
2016-11-17 08:46:44 -07:00
|
|
|
|
2018-03-01 06:56:03 -07:00
|
|
|
def get_room_min_stream_ordering(self):
|
|
|
|
return self._backfill_id_gen.get_current_token()
|