mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-02 19:16:12 -04:00
Add database config class (#6513)
This encapsulates config for a given database and is the way to get new connections.
This commit is contained in:
parent
91ccfe9f37
commit
2284eb3a53
19 changed files with 286 additions and 208 deletions
|
@ -13,24 +13,50 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from synapse.storage.database import Database
|
||||
import logging
|
||||
|
||||
from synapse.storage.database import Database, make_conn
|
||||
from synapse.storage.engines import create_engine
|
||||
from synapse.storage.prepare_database import prepare_database
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DataStores(object):
|
||||
"""The various data stores.
|
||||
|
||||
These are low level interfaces to physical databases.
|
||||
|
||||
Attributes:
|
||||
main (DataStore)
|
||||
"""
|
||||
|
||||
def __init__(self, main_store_class, db_conn, hs):
|
||||
def __init__(self, main_store_class, hs):
|
||||
# Note we pass in the main store class here as workers use a different main
|
||||
# store.
|
||||
database = Database(hs)
|
||||
|
||||
# Check that db is correctly configured.
|
||||
database.engine.check_database(db_conn.cursor())
|
||||
self.databases = []
|
||||
|
||||
prepare_database(db_conn, database.engine, config=hs.config)
|
||||
for database_config in hs.config.database.databases:
|
||||
db_name = database_config.name
|
||||
engine = create_engine(database_config.config)
|
||||
|
||||
self.main = main_store_class(database, db_conn, hs)
|
||||
with make_conn(database_config, engine) as db_conn:
|
||||
logger.info("Preparing database %r...", db_name)
|
||||
|
||||
engine.check_database(db_conn.cursor())
|
||||
prepare_database(
|
||||
db_conn, engine, hs.config, data_stores=database_config.data_stores,
|
||||
)
|
||||
|
||||
database = Database(hs, database_config, engine)
|
||||
|
||||
if "main" in database_config.data_stores:
|
||||
logger.info("Starting 'main' data store")
|
||||
self.main = main_store_class(database, db_conn, hs)
|
||||
|
||||
db_conn.commit()
|
||||
|
||||
self.databases.append(database)
|
||||
|
||||
logger.info("Database %r prepared", db_name)
|
||||
|
|
|
@ -412,7 +412,7 @@ class ClientIpStore(ClientIpBackgroundUpdateStore):
|
|||
def _update_client_ips_batch(self):
|
||||
|
||||
# If the DB pool has already terminated, don't try updating
|
||||
if not self.hs.get_db_pool().running:
|
||||
if not self.db.is_running():
|
||||
return
|
||||
|
||||
to_update = self._batch_row_update
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue