__init__.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 `DatabasePool` class represents connections to a single physical
  20. database. The `databases` are classes that talk directly to a `DatabasePool`
  21. instance and have associated schemas, background updates, etc. On top of those
  22. there are classes that provide high level interfaces that combine calls to
  23. multiple `databases`.
  24. There are also schemas that get applied to every database, regardless of the
  25. data stores associated with them (e.g. the schema version tables), which are
  26. stored in `synapse.storage.schema`.
  27. """
  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. __all__ = ["DataStores", "DataStore"]
  34. class Storage(object):
  35. """The high level interfaces for talking to various storage layers.
  36. """
  37. def __init__(self, hs, stores: Databases):
  38. # We include the main data store here mainly so that we don't have to
  39. # rewrite all the existing code to split it into high vs low level
  40. # interfaces.
  41. self.main = stores.main
  42. self.persistence = EventsPersistenceStorage(hs, stores)
  43. self.purge_events = PurgeEventsStorage(hs, stores)
  44. self.state = StateGroupStorage(hs, stores)