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

Changing Permit redirection #1499

Merged
merged 11 commits into from
Jul 28, 2024
Merged

Changing Permit redirection #1499

merged 11 commits into from
Jul 28, 2024

Conversation

rusher
Copy link
Contributor

@rusher rusher commented Jul 20, 2024

Permit redirection, based on mariadb implementation https://jira.mariadb.org/browse/MDEV-15935: first OK_Packet can contain variable redirect_url using "mariadb/mysql://[{user}[:{password}]@]{host}[:{port}]/[{db}[?{opt1}={value1}[&{opt2}={value2}]]]']" format.

This is based on https://jira.mariadb.org/browse/MDEV-15935: first OK_Packet can contain variable `redirect_url` using "mariadb/mysql://[{user}[:{password}]@]{host}[:{port}]/[{db}[?{opt1}={value1}[&{opt2}={value2}]]]']" format.

Signed-off-by: rusher <diego.dupin@gmail.com>
@rusher
Copy link
Contributor Author

rusher commented Jul 20, 2024

This is done for either pool and single connection, contrary to previous implementation. I don't know why there was a restriction like this. Logger messages from previous pool/single connection are keeped, but it might be a good idea to have a simplier implemenation

Comment on lines 405 to 406
[LoggerMessage(EventIds.HasServerRedirectionHeader, LogLevel.Trace, "{poolPrefix}Session {SessionId} has server redirection header {Header}")]
public static partial void HasServerRedirectionHeader(ILogger logger, string poolPrefix, string sessionId, string header);
Copy link
Member

Choose a reason for hiding this comment

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

The log field names are significant, and are used for "structured logging" within Microsoft.Extensions.Logging; see https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-8.0#log-message-template.

We can't just change them for better code reuse (thinking of them like string concatenation).

@bgrainger
Copy link
Member

This is done for either pool and single connection, contrary to previous implementation. I don't know why there was a restriction like this.

I don't remember why, either. Based on the commit message for 48c6754 it looks like a bugfix introduced this change, and before that redirection was implemented for pooled and non-pooled.

Signed-off-by: Bradley Grainger <bgrainger@gmail.com>

namespace IntegrationTests;

public class RedirectionTests : IClassFixture<DatabaseFixture>, IDisposable
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding tests!

try
{
m_database.Connection.Execute(
$"set @@global.redirect_url=\"mariadb://{initialServer}:{initialPort}\"");
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this fails with MariaDB 11.4 since it does accept this global variable, but doesn't include it in the initial OK packet.

Copy link
Member

Choose a reason for hiding this comment

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

Usually I handle server-specific functionality by adding a new enum to ServerFeatures and skipping the test based on whether that's set in config.json.

change redirection logging

Signed-off-by: rusher <diego.dupin@gmail.com>
Signed-off-by: Bradley Grainger <bgrainger@gmail.com>
Signed-off-by: Bradley Grainger <bgrainger@gmail.com>
@bgrainger
Copy link
Member

I'm getting errors in the ConnectTimeout test locally; I want to dig into that more first before reviewing this further or merging it.

{
OwningConnection = new WeakReference<MySqlConnection>(this),
};
var session = await ServerSession.ConnectAndRedirectAsync(() => new ServerSession(m_logger), m_logger, null, connectionSettings, loadBalancer, this, null, startingTimestamp, null, actualIOBehavior, cancellationToken).ConfigureAwait(false);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var session = await ServerSession.ConnectAndRedirectAsync(() => new ServerSession(m_logger), m_logger, null, connectionSettings, loadBalancer, this, null, startingTimestamp, null, actualIOBehavior, cancellationToken).ConfigureAwait(false);
var session = await ServerSession.ConnectAndRedirectAsync(() => new ServerSession(m_logger), m_logger, null, connectionSettings, loadBalancer, this, null, startingTimestamp, null, actualIOBehavior, connectToken).ConfigureAwait(false);

See line 1073 below.

Signed-off-by: Bradley Grainger <bgrainger@gmail.com>
@@ -628,6 +628,8 @@ public override string ConnectionString
}
}

public string? SessionConnectionString => m_session?.ConnectionString;
Copy link
Member

Choose a reason for hiding this comment

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

Is this just for tests? We shouldn't add a new public property just to make testing easier; that will imply a commitment to support this.

Signed-off-by: Bradley Grainger <bgrainger@gmail.com>
Introduce IConnectionPoolMetadata to unify the code between pooled and non-pooled sessions.

Signed-off-by: Bradley Grainger <bgrainger@gmail.com>
This standardises all redirection logging to use the MySqlConnection logger, whether pooled or non-pooled.

Signed-off-by: Bradley Grainger <bgrainger@gmail.com>

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Signed-off-by: Bradley Grainger <bgrainger@gmail.com>
Use ServerFeatures.Redirection to ignore this test on servers that don't support it.

Signed-off-by: Bradley Grainger <bgrainger@gmail.com>
@bgrainger bgrainger merged commit 6e45dcd into mysql-net:master Jul 28, 2024
22 checks passed
@bgrainger
Copy link
Member

Fixed in 2.4.0.

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

Successfully merging this pull request may close these issues.

None yet

2 participants