Skip to content
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

Host list #19

Closed
wants to merge 2 commits into from
Closed

Host list #19

wants to merge 2 commits into from

Conversation

altmannmarcelo
Copy link
Collaborator

This commit adds the ability to read a list of hosts from mysql_servers
table instead of a single host from config file.

This merges the old server.rs into the hosts file.
This also remove the Pooled connection to a single connection.

Fixes: #5

This commit adds a minimal build of a proxysql, mysql and readyset
via docker compose file. With this we can start a local environment
to test the scheduler.
This commit adds the ability to read a list of hosts from mysql_servers
table instead of a single host from config file.

This merges the old server.rs into the hosts file.
This also remove the Pooled connection to a single connection.

Fixes: #5
Copy link

@mvzink mvzink left a comment

Choose a reason for hiding this comment

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

I think this is fine but want to take another look later. In the meantime, some nitpicks for your enjoyment.

build/proxysql.cnf Show resolved Hide resolved
src/hosts.rs Show resolved Hide resolved
Online,
//backend sever is temporarily taken out of use because of either too many connection errors in a time that was too short, or the replication lag exceeded the allowed threshold
Shunned,
//when a server is put into OFFLINE_SOFT mode, no new connections are created toward that server, while the existing connections are kept until they are returned to the connection pool or destructed. In other words, connections are kept in use until multiplexing is enabled again, for example when a transaction is completed. This makes it possible to gracefully detach a backend as long as multiplexing is efficient
Copy link

Choose a reason for hiding this comment

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

Seems like you might want to run cargo fmt to wrap these longer lines

Copy link
Contributor

Choose a reason for hiding this comment

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

Should the rest of these be /// comments too for doc comment purposes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The longer lines do not format. Currently this project enforces cargo fmt already.
I can see we use a specific config to wrap comments on Readyset, however, those features are from nightly:

marcelo Work/readyset_proxysql_scheduler [query-search-method] $ cargo fmt --check
Warning: can't set `wrap_comments = true`, unstable features are only available in nightly channel.
Warning: can't set `format_code_in_doc_comments = true`, unstable features are only available in nightly channel.
Warning: can't set `comment_width = 100`, unstable features are only available in nightly channel.
Warning: can't set `imports_granularity = Module`, unstable features are only available in nightly channel.
Warning: can't set `group_imports = StdExternalCrate`, unstable features are only available in nightly channel.

Added the /// to make it consistent.

None => Ok(false),
}
}
None => Ok(false),
Copy link

Choose a reason for hiding this comment

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

Hmm, why not return an error here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't know one example of when EXPLAIN will return no rows. I am running the query with ? which will make the caller return the same error. I think it still make sense to differ an Error from an empty result.

///
/// # Returns
///
/// true if the query was cached successfully, false otherwise.
Copy link

Choose a reason for hiding this comment

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

Might make sense to return a descriptive error if there's no connection instead of false

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Make sense. Just FYI, this part is unreachable. The only reason for having conn as an Option is to allow the creation of a Host even if a connection fail. Later at ProxySQL::health_check we call Host::check_readyset_is_ready if conn is None we return an error and mark the node as Shunned. Cache a query comes as a later point after where we only kept the online hosts.

Fixed

None => return Ok(false),
Some(conn) => {
conn.query_drop(format!("CREATE CACHE d_{} FROM {}", digest, digest_text))
.expect("Failed to create readyset cache");
Copy link

Choose a reason for hiding this comment

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

I think this could fail for a lot of unexpected reasons and we should probably return an error instead of panic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed. Btw, we are panicking in the caller if cache_query returns an error. Basically we are iterating through all online readyset hosts and if one readyset fails to cache a query, this is one unrecoverable error. Given the nature of the scheduler (crontab that runs every X seconds) I don't see any difference in panicking right away versus handling an error.

ps_conn: &mut Conn,
config: &Config,
status: HostStatus,
) -> Result<bool, mysql::Error> {
Copy link

Choose a reason for hiding this comment

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

Doesn't look like we return anything other than true so we should probably return Result<(), ...>

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This function migrated to ProxySQL::health_check - ProxySQL handles all the changes required to proxysql and host.change_status is just an in memory version of the state of the host.

Online,
//backend sever is temporarily taken out of use because of either too many connection errors in a time that was too short, or the replication lag exceeded the allowed threshold
Shunned,
//when a server is put into OFFLINE_SOFT mode, no new connections are created toward that server, while the existing connections are kept until they are returned to the connection pool or destructed. In other words, connections are kept in use until multiplexing is enabled again, for example when a transaction is completed. This makes it possible to gracefully detach a backend as long as multiplexing is efficient
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the rest of these be /// comments too for doc comment purposes?

src/hosts.rs Show resolved Hide resolved
Comment on lines +93 to +97
/// Gets the hostname of the host.
///
/// # Returns
///
/// The hostname of the host.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: This is a lot of vertical space for a comment for an accessor function

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have used the same comment formatting for all functions. Do you want to remove the empty lines ?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I don't think I'm asking for you to do that, and if you have a consistent thing going on, I don't care that much that it be changed.

I think the value of comments for accessor functions is pretty low, as this tells the reader the same thing (get the hostname) 3 times (including the name of the function). If you can comfortably make these types of comments just 1 line, I do think that would be an improvement.

Feel free to ignore this advice.

src/hosts.rs Show resolved Hide resolved
Copy link
Contributor

@davisjc davisjc left a comment

Choose a reason for hiding this comment

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

Thanks!

@altmannmarcelo
Copy link
Collaborator Author

closing in favor of #21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get the list of Readyset Servers from mysql_servers table
3 participants