Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/6240.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Move `persist_events` out from main data store.
3 changes: 2 additions & 1 deletion synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def __init__(self, hs):
self.hs = hs

self.store = hs.get_datastore()
self.storage = hs.get_storage()
self.federation_client = hs.get_federation_client()
self.state_handler = hs.get_state_handler()
self.server_name = hs.hostname
Expand Down Expand Up @@ -2664,7 +2665,7 @@ def persist_events_and_notify(self, event_and_contexts, backfilled=False):
backfilled=backfilled,
)
else:
max_stream_id = yield self.store.persist_events(
max_stream_id = yield self.storage.persistence.persist_events(
event_and_contexts, backfilled=backfilled
)

Expand Down
3 changes: 2 additions & 1 deletion synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ def __init__(self, hs):
self.hs = hs
self.auth = hs.get_auth()
self.store = hs.get_datastore()
self.storage = hs.get_storage()
self.state = hs.get_state_handler()
self.clock = hs.get_clock()
self.validator = EventValidator()
Expand Down Expand Up @@ -868,7 +869,7 @@ def is_inviter_member_event(e):
if prev_state_ids:
raise AuthError(403, "Changing the room create event is forbidden")

(event_stream_id, max_stream_id) = yield self.store.persist_event(
event_stream_id, max_stream_id = yield self.storage.persistence.persist_event(
event, context=context
)

Expand Down
12 changes: 9 additions & 3 deletions synapse/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
WorkerServerNoticesSender,
)
from synapse.state import StateHandler, StateResolutionHandler
from synapse.storage import DataStores, Storage
from synapse.streams.events import EventSources
from synapse.util import Clock
from synapse.util.distributor import Distributor
Expand Down Expand Up @@ -196,6 +197,7 @@ def build_DEPENDENCY(self)
"account_validity_handler",
"saml_handler",
"event_client_serializer",
"storage",
]

REQUIRED_ON_MASTER_STARTUP = ["user_directory_handler", "stats_handler"]
Expand Down Expand Up @@ -224,7 +226,7 @@ def __init__(self, hostname, reactor=None, **kwargs):
self.admin_redaction_ratelimiter = Ratelimiter()
self.registration_ratelimiter = Ratelimiter()

self.datastore = None
self.datastores = None

# Other kwargs are explicit dependencies
for depname in kwargs:
Expand All @@ -233,7 +235,8 @@ def __init__(self, hostname, reactor=None, **kwargs):
def setup(self):
logger.info("Setting up.")
with self.get_db_conn() as conn:
self.datastore = self.DATASTORE_CLASS(conn, self)
datastore = self.DATASTORE_CLASS(conn, self)
self.datastores = DataStores(datastore, conn, self)
conn.commit()
logger.info("Finished setting up.")

Expand Down Expand Up @@ -266,7 +269,7 @@ def get_clock(self):
return self.clock

def get_datastore(self):
return self.datastore
return self.datastores.main

def get_config(self):
return self.config
Expand Down Expand Up @@ -537,6 +540,9 @@ def build_saml_handler(self):
def build_event_client_serializer(self):
return EventClientSerializer(self)

def build_storage(self) -> Storage:
return Storage(self, self.datastores)

def remove_pusher(self, app_id, push_key, user_id):
return self.get_pusherpool().remove_pusher(app_id, push_key, user_id)

Expand Down
19 changes: 18 additions & 1 deletion synapse/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,24 @@
stored in `synapse.storage.schema`.
"""

from synapse.storage.data_stores.main import DataStore # noqa: F401
from synapse.storage.data_stores import DataStores
from synapse.storage.data_stores.main import DataStore
from synapse.storage.persist_events import EventsPersistenceStorage

__all__ = ["DataStores", "DataStore"]


class Storage(object):
"""The high level interfaces for talking to various storage layers.
"""

def __init__(self, hs, stores: DataStores):
# We include the main data store here mainly so that we don't have to
# rewrite all the existing code to split it into high vs low level
# interfaces.
self.main = stores.main

self.persistence = EventsPersistenceStorage(hs, stores)


def are_all_users_on_domain(txn, database_engine, domain):
Expand Down
12 changes: 12 additions & 0 deletions synapse/storage/data_stores/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,15 @@
# 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.


class DataStores(object):
"""The various data stores.

These are low level interfaces to physical databases.
"""

def __init__(self, main_store, db_conn, hs):
# Note we pass in the main store here as workers use a different main
# store.
self.main = main_store
Loading