__init__.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2014-2016 OpenMarket Ltd
  3. # Copyright 2018,2019 New Vector Ltd
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. """
  17. The storage layer is split up into multiple parts to allow Synapse to run
  18. against different configurations of databases (e.g. single or multiple
  19. databases). The `Database` class represents a single physical database. The
  20. `data_stores` are classes that talk directly to a `Database` instance and have
  21. associated schemas, background updates, etc. On top of those there are classes
  22. that provide high level interfaces that combine calls to multiple `data_stores`.
  23. There are also schemas that get applied to every database, regardless of the
  24. data stores associated with them (e.g. the schema version tables), which are
  25. stored in `synapse.storage.schema`.
  26. """
  27. from synapse.storage.data_stores import DataStores
  28. from synapse.storage.data_stores.main import DataStore
  29. from synapse.storage.persist_events import EventsPersistenceStorage
  30. from synapse.storage.purge_events import PurgeEventsStorage
  31. from synapse.storage.state import StateGroupStorage
  32. __all__ = ["DataStores", "DataStore"]
  33. class Storage(object):
  34. """The high level interfaces for talking to various storage layers.
  35. """
  36. def __init__(self, hs, stores: DataStores):
  37. # We include the main data store here mainly so that we don't have to
  38. # rewrite all the existing code to split it into high vs low level
  39. # interfaces.
  40. self.main = stores.main
  41. self.persistence = EventsPersistenceStorage(hs, stores)
  42. self.purge_events = PurgeEventsStorage(hs, stores)
  43. self.state = StateGroupStorage(hs, stores)