-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider how multiple hosts can be specified when establishing a connection #45
Comments
Here's the proposed credentials schema by @tailhook https://gist.github.com/tailhook/bb64fc0fa67a5981876d3646cfc326c7 |
With the above in mind, I would propose the following:
With the following semantics:
The couple of points:
While
instead of having full configuration. Some open-source projects, like django-based ones have pythonic config anyway, so users can create Obviously, we can bikeshed on the names. |
For the record, I don't either.
So, this is basically a "host selector" kind of API. Something like:
I think that could work. |
I agree. FWIW I only saw Elvis proposing Regarding
and
I assume it would also override regularly passed host/port? E.g. would this be a legal call Other than that, I'm not a big fan of the "ha_config" name -- it only allows to configure a certain tiny aspect and it doesn't suggest that it can override something. Which makes me wonder why do we need to stuff all this functionality into one |
I would make it produce a subclass of a connection pool: pool: Pool = ha_config.create_pool(credentials_file=..., **kwargs) I think there might be much more than just But anyway we should not make any public API out of
We already do that in Rust, because it has no keyword arguments. In python it's common to have keyword arguments for many things, instead of builder/fluent. In Python community there is often backlash for builder/fluent. So, yes if it wasn't clear I propose a builder only for
But simpler things like tutorials and ad-hoc scripts will still look simpler like
Well, I'm not saying this is a perfect name. The idea is that until you don't need high-availability (HA), you don't specify this name, and once you have, you specify everything that may influence availability in the class that build HA config. This includes multi-level timeouts, failover conditions, load-balancing way. This interoperates very much with settings of the connection pool, but they are still pretty orthogonal. So, I don't think this should be But I'm not married to the specific name. I've thought of Another thing I've just noticed that
This is very Rustish way, but I would prefer it be keyword argument, because discoverability. Here is the difference between usages: create_async_pool(**kwargs) # (1)
create_async_pool(ha_config=config, **kwargs) # (2)
config.create_pool() # (3) The difference between (1) and (2) is much smaller than between (1) and (3). And when you create a pool for the first time it's easier to remember how to create HA (production) config by looking at the function signature. Otherwise, we need to explicitly show example with And it's also easier to make a config that toggles keyword argument (production vs dev env). |
I actually quite like what @elprans proposed in edgedb/edgedb#1683. IMO the approach allows to implement what @tailhook and I have in mind with a builder API. |
Currently, we only allow a single host/port pair to be passed to the
connect()
call. To make building HA setups around the binding(s) easier, we should allow passing a list of addresses to be tried in order. On its own, this would satisfy simple HA setups with static hostlists, either direct server addresses or load-balancing proxy lists.For reference, PostgreSQL's libpq documentation on how to specify multiple hosts is here.
Their approach is hybrid:
host
andport
are separate arguments and both may contain lists. Ifhost
andport
are both lists, they must be of the same size, ifhost
is a list andport
is not, the specified port is applied to all hosts.The upside of this approach is that it keeps things simple in the very common case of a single host/port, and the downside is that separate
host
andport
lists are harder to specify and manage.An alternative approach is to remove the
port
argument and instead allow passinghost
as either a string, a single (named) tuple, or a list of (named) tuples.All of this applies to how the
credentials
file is structured, since we want to keep the resemblance withconnect()
call signatures.The text was updated successfully, but these errors were encountered: