Skip to content

Commit e7b1fc7

Browse files
committed
permit skipping redirection test
change redirection logging Signed-off-by: rusher <[email protected]>
1 parent 4e58e42 commit e7b1fc7

File tree

6 files changed

+36
-38
lines changed

6 files changed

+36
-38
lines changed

azure-pipelines.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,27 +187,27 @@ jobs:
187187
'MySQL 8.0':
188188
image: 'mysql:8.0'
189189
connectionStringExtra: 'AllowPublicKeyRetrieval=True'
190-
unsupportedFeatures: 'Ed25519,StreamingResults,Tls11,ZeroDateTime'
190+
unsupportedFeatures: 'Ed25519,StreamingResults,Tls11,ZeroDateTime,Redirection'
191191
'MySQL 8.4':
192192
image: 'mysql:8.4'
193193
connectionStringExtra: 'AllowPublicKeyRetrieval=True'
194-
unsupportedFeatures: 'Ed25519,StreamingResults,Tls11,ZeroDateTime'
194+
unsupportedFeatures: 'Ed25519,StreamingResults,Tls11,ZeroDateTime,Redirection'
195195
'MySQL 9.0':
196196
image: 'mysql:9.0'
197197
connectionStringExtra: 'AllowPublicKeyRetrieval=True'
198-
unsupportedFeatures: 'Ed25519,StreamingResults,Tls11,ZeroDateTime'
198+
unsupportedFeatures: 'Ed25519,StreamingResults,Tls11,ZeroDateTime,Redirection'
199199
'MariaDB 10.6':
200200
image: 'mariadb:10.6'
201201
connectionStringExtra: ''
202-
unsupportedFeatures: 'CachingSha2Password,CancelSleepSuccessfully,Json,RoundDateTime,QueryAttributes,Sha256Password,Tls11,UuidToBin'
202+
unsupportedFeatures: 'CachingSha2Password,CancelSleepSuccessfully,Json,RoundDateTime,QueryAttributes,Sha256Password,Tls11,UuidToBin,Redirection'
203203
'MariaDB 10.11':
204204
image: 'mariadb:10.11'
205205
connectionStringExtra: ''
206-
unsupportedFeatures: 'CachingSha2Password,CancelSleepSuccessfully,Json,RoundDateTime,QueryAttributes,Sha256Password,Tls11,UuidToBin'
206+
unsupportedFeatures: 'CachingSha2Password,CancelSleepSuccessfully,Json,RoundDateTime,QueryAttributes,Sha256Password,Tls11,UuidToBin,Redirection'
207207
'MariaDB 11.4':
208208
image: 'mariadb:11.4'
209209
connectionStringExtra: ''
210-
unsupportedFeatures: 'CachingSha2Password,CancelSleepSuccessfully,Json,RoundDateTime,QueryAttributes,Sha256Password,Tls11,UuidToBin'
210+
unsupportedFeatures: 'CachingSha2Password,CancelSleepSuccessfully,Json,RoundDateTime,QueryAttributes,Sha256Password,Tls11,UuidToBin,Redirection'
211211
steps:
212212
- template: '.ci/integration-tests-steps.yml'
213213
parameters:

src/MySqlConnector/Core/ServerSession.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -576,14 +576,7 @@ public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancella
576576
public static async ValueTask<ServerSession> ConnectAndRedirectAsync(Func<ServerSession> createSession, ILogger logger, int? poolId, ConnectionSettings cs, ILoadBalancer? loadBalancer, MySqlConnection connection, Action<ILogger, int, string, Exception?>? logMessage, long startingTimestamp, Activity? activity, IOBehavior ioBehavior, CancellationToken cancellationToken)
577577
{
578578
var session = createSession();
579-
if (poolId is not null)
580-
{
581-
if (logger.IsEnabled(LogLevel.Debug)) logMessage!(logger, poolId.Value, session.Id, null);
582-
}
583-
else
584-
{
585-
Log.CreatedNonPooledSession(logger, session.Id);
586-
}
579+
if (poolId is not null && logger.IsEnabled(LogLevel.Debug)) logMessage!(logger, poolId.Value, session.Id, null);
587580

588581
string? redirectionUrl;
589582
try
@@ -597,13 +590,12 @@ public static async ValueTask<ServerSession> ConnectAndRedirectAsync(Func<Server
597590
}
598591

599592
Exception? redirectionException = null;
600-
var poolPrefix = poolId is not null ? "Pool {PoolId} " : "";
601593
if (redirectionUrl is not null)
602594
{
603-
Log.HasServerRedirectionHeader(logger, poolPrefix, session.Id, redirectionUrl!);
595+
Log.HasServerRedirectionHeader(logger, session.Id, redirectionUrl);
604596
if (cs.ServerRedirectionMode == MySqlServerRedirectionMode.Disabled)
605597
{
606-
Log.ServerRedirectionIsDisabled(logger, poolPrefix);
598+
Log.ServerRedirectionIsDisabled(logger, session.Id);
607599
return session;
608600
}
609601

@@ -612,19 +604,19 @@ public static async ValueTask<ServerSession> ConnectAndRedirectAsync(Func<Server
612604
if (host != cs.HostNames![0] || port != cs.Port || user != cs.UserID)
613605
{
614606
var redirectedSettings = cs.CloneWith(host, port, user);
615-
Log.OpeningNewConnection(logger, poolPrefix, host, port, user);
607+
Log.OpeningNewConnection(logger, host, port, user);
616608
var redirectedSession = createSession();
617609
try
618610
{
619611
await redirectedSession.ConnectAsync(redirectedSettings, connection, startingTimestamp, loadBalancer, activity, ioBehavior, cancellationToken).ConfigureAwait(false);
620-
Log.ClosingSessionToUseRedirectedSession(logger, poolPrefix, session.Id, redirectedSession.Id);
612+
Log.ClosingSessionToUseRedirectedSession(logger, session.Id, redirectedSession.Id);
621613
await session.DisposeAsync(ioBehavior, cancellationToken).ConfigureAwait(false);
622614
return redirectedSession;
623615
}
624616
catch (Exception ex)
625617
{
626618
redirectionException = ex;
627-
Log.FailedToConnectRedirectedSession(logger, ex, poolPrefix, redirectedSession.Id);
619+
Log.FailedToConnectRedirectedSession(logger, ex, redirectedSession.Id);
628620
try
629621
{
630622
await redirectedSession.DisposeAsync(ioBehavior, cancellationToken).ConfigureAwait(false);
@@ -636,14 +628,14 @@ public static async ValueTask<ServerSession> ConnectAndRedirectAsync(Func<Server
636628
}
637629
else
638630
{
639-
Log.SessionAlreadyConnectedToServer(logger, poolPrefix, session.Id);
631+
Log.SessionAlreadyConnectedToServer(logger, session.Id);
640632
}
641633
}
642634
}
643635

644636
if (cs.ServerRedirectionMode == MySqlServerRedirectionMode.Required)
645637
{
646-
Log.RequiresServerRedirection(logger, poolPrefix);
638+
Log.RequiresServerRedirection(logger, session.Id);
647639
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Server does not support redirection", redirectionException);
648640
}
649641
return session;

src/MySqlConnector/Logging/Log.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -402,26 +402,26 @@ internal static partial class Log
402402
[LoggerMessage(EventIds.FoundSessionToCleanUp, LogLevel.Debug, "Pool {PoolId} found session {SessionId} to clean up")]
403403
public static partial void FoundSessionToCleanUp(ILogger logger, int poolId, string sessionId);
404404

405-
[LoggerMessage(EventIds.HasServerRedirectionHeader, LogLevel.Trace, "{poolPrefix}Session {SessionId} has server redirection header {Header}")]
406-
public static partial void HasServerRedirectionHeader(ILogger logger, string poolPrefix, string sessionId, string header);
405+
[LoggerMessage(EventIds.HasServerRedirectionHeader, LogLevel.Trace, "Session {SessionId} has server redirection header {Header}")]
406+
public static partial void HasServerRedirectionHeader(ILogger logger, string sessionId, string header);
407407

408-
[LoggerMessage(EventIds.ServerRedirectionIsDisabled, LogLevel.Trace, "{poolPrefix}server redirection is disabled; ignoring redirection")]
409-
public static partial void ServerRedirectionIsDisabled(ILogger logger, string poolPrefix);
408+
[LoggerMessage(EventIds.ServerRedirectionIsDisabled, LogLevel.Trace, "Session {SessionId}, server redirection is disabled; ignoring redirection")]
409+
public static partial void ServerRedirectionIsDisabled(ILogger logger, string sessionId);
410410

411-
[LoggerMessage(EventIds.OpeningNewConnection, LogLevel.Debug, "{poolPrefix}opening new connection to {Host}:{Port} as {User}")]
412-
public static partial void OpeningNewConnection(ILogger logger, string poolPrefix, string host, int port, string user);
411+
[LoggerMessage(EventIds.OpeningNewConnection, LogLevel.Debug, "opening new connection to {Host}:{Port} as {User}")]
412+
public static partial void OpeningNewConnection(ILogger logger, string host, int port, string user);
413413

414-
[LoggerMessage(EventIds.FailedToConnectRedirectedSession, LogLevel.Information, "{poolPrefix}failed to connect redirected session {SessionId}")]
415-
public static partial void FailedToConnectRedirectedSession(ILogger logger, Exception ex, string poolPrefix, string sessionId);
414+
[LoggerMessage(EventIds.FailedToConnectRedirectedSession, LogLevel.Information, "failed to connect redirected session {SessionId}")]
415+
public static partial void FailedToConnectRedirectedSession(ILogger logger, Exception ex, string sessionId);
416416

417-
[LoggerMessage(EventIds.ClosingSessionToUseRedirectedSession, LogLevel.Trace, "{poolPrefix}closing session {SessionId} to use redirected session {RedirectedSessionId} instead")]
418-
public static partial void ClosingSessionToUseRedirectedSession(ILogger logger, string poolPrefix, string sessionId, string redirectedSessionId);
417+
[LoggerMessage(EventIds.ClosingSessionToUseRedirectedSession, LogLevel.Trace, "closing session {SessionId} to use redirected session {RedirectedSessionId} instead")]
418+
public static partial void ClosingSessionToUseRedirectedSession(ILogger logger, string sessionId, string redirectedSessionId);
419419

420-
[LoggerMessage(EventIds.SessionAlreadyConnectedToServer, LogLevel.Trace, "{poolPrefix}Session {SessionId} is already connected to this server; ignoring redirection")]
421-
public static partial void SessionAlreadyConnectedToServer(ILogger logger, string poolPrefix, string sessionId);
420+
[LoggerMessage(EventIds.SessionAlreadyConnectedToServer, LogLevel.Trace, "Session {SessionId} is already connected to this server; ignoring redirection")]
421+
public static partial void SessionAlreadyConnectedToServer(ILogger logger, string sessionId);
422422

423-
[LoggerMessage(EventIds.RequiresServerRedirection, LogLevel.Error, "{poolPrefix}new connection requires server redirection but server doesn't support it")]
424-
public static partial void RequiresServerRedirection(ILogger logger, string poolPrefix);
423+
[LoggerMessage(EventIds.RequiresServerRedirection, LogLevel.Error, "Session {SessionId}, new connection requires server redirection but server doesn't support it")]
424+
public static partial void RequiresServerRedirection(ILogger logger, string SessionId);
425425

426426
[LoggerMessage(EventIds.CreatedPoolWillNotBeUsed, LogLevel.Debug, "Pool {PoolId} was created but will not be used (due to race)")]
427427
public static partial void CreatedPoolWillNotBeUsed(ILogger logger, int poolId);

src/MySqlConnector/MySqlConnection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,7 @@ private async ValueTask<ServerSession> CreateSessionAsync(ConnectionPool? pool,
10661066
RandomLoadBalancer.Instance : FailOverLoadBalancer.Instance;
10671067
var session = await ServerSession.ConnectAndRedirectAsync(() => new ServerSession(m_logger), m_logger, null, connectionSettings, loadBalancer, this, null, startingTimestamp, null, actualIOBehavior, cancellationToken).ConfigureAwait(false);
10681068
session.OwningConnection = new WeakReference<MySqlConnection>(this);
1069+
Log.CreatedNonPooledSession(m_logger, session.Id);
10691070
return session;
10701071
}
10711072
}

tests/IntegrationTests/RedirectionTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ public void Dispose()
1717
m_database.Connection.Close();
1818
}
1919

20-
21-
[Fact]
20+
[SkippableFact(ServerFeatures.Redirection)]
2221
public void RedirectionTest()
2322
{
2423
StartProxy();

tests/IntegrationTests/ServerFeatures.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,10 @@ public enum ServerFeatures
3535
/// A "SLEEP" command produces a result set when it is cancelled, not an error payload.
3636
/// </summary>
3737
CancelSleepSuccessfully = 0x40_0000,
38+
39+
/// <summary>
40+
/// Server permit redirection, available on first OK_Packet
41+
/// </summary>
42+
Redirection = 0x80_0000,
43+
3844
}

0 commit comments

Comments
 (0)