__init__.py 2.3 KB

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