Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add database config class #6513

Merged
merged 7 commits into from
Dec 18, 2019
Merged

Add database config class #6513

merged 7 commits into from
Dec 18, 2019

Conversation

erikjohnston
Copy link
Member

@erikjohnston erikjohnston commented Dec 10, 2019

Replaces #6481.

Based on #6510, #6511 and #6512.

@erikjohnston erikjohnston force-pushed the erikj/split_database_config branch 3 times, most recently from 3137d27 to 210b520 Compare December 12, 2019 11:35
This encapsulates config for a given database and is the way to get new
connections.
@erikjohnston erikjohnston requested a review from a team December 12, 2019 12:10
@erikjohnston
Copy link
Member Author

This is still quite large I'm afraid, though a fair chunk of it is just fixing up tests.

synapse/config/database.py Outdated Show resolved Hide resolved
from twisted.enterprise import adbapi

from synapse.config._base import Config, ConfigError
from synapse.storage.engines import create_engine
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having config import from synapse.storage sounds like a great way to end up with horrible import loops (I found a fun one yesterday where if you import synapse.storage first you're ok, but if you import synapse.state it all explodes).

It seems to me that DatabaseConnectionConfig is doing more than a config object should: why can't the call to create_engine, and the get_pool and make_conn and co move into the Database class?

An alternative looks like it might be to move create_engine into config, but that feels wrong to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(that said: a big +1 to moving these things out of the HomeServer god object)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't disagree, it is a pain. At the moment the Database object represents a fully prepared and configured database, we could move the preparation into the __init__, but then we need want to reuse the connection to give to the data stores, which is fiddly if we create the connection in the Database :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then we need want to reuse the connection to give to the data stores, which is fiddly if we create the connection in the Database :(

I'm not quite following this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically its a bit hard to see how to rewrite https://github.com/matrix-org/synapse/pull/6513/files#diff-23406f76811c2c98a6ed1758c0bda2abR42-R54 if we move make_conn to Database

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Make it a top-level function, in synapse.storage.database (or similar), which takes a DatabaseConfig as a param?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, ok, I can give that a go

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So 439e043 is my attempt at that, the tests are a bit hacky but that's true of them already.

synapse/config/database.py Show resolved Hide resolved
synapse/config/database.py Show resolved Hide resolved
@erikjohnston erikjohnston force-pushed the erikj/split_database_config branch 2 times, most recently from 7318971 to 7b297a4 Compare December 16, 2019 14:11
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks much better!

logger = logging.getLogger(__name__)


class DatabaseConnectionConfig:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might make more sense as an attr.s ? Just a thought

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I thought about that, but then I find the validation stuff non intuitive.

@erikjohnston erikjohnston merged commit 2284eb3 into develop Dec 18, 2019
@erikjohnston erikjohnston deleted the erikj/split_database_config branch January 9, 2020 15:47
richvdh added a commit that referenced this pull request Oct 16, 2020
This seems to have been broken since #6513.
@richvdh richvdh mentioned this pull request Oct 16, 2020
richvdh added a commit that referenced this pull request Oct 16, 2020
This seems to have been broken since #6513.
babolivier pushed a commit that referenced this pull request Sep 1, 2021
* commit '2284eb3a5':
  Add database config class (#6513)
  too many parens
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants