Skip to content

Commit

Permalink
Remove COM_MULTI implementation. Fixes #946
Browse files Browse the repository at this point in the history
The only server that supported this capability bit was MariaDB prior to version 10.6. Additionally, this code is never regularly tested because CI only runs against MariaDB 10.6 and later.
  • Loading branch information
bgrainger committed Oct 29, 2023
1 parent 63362c2 commit 5ad4cf3
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 179 deletions.
37 changes: 0 additions & 37 deletions src/MySqlConnector/Core/BatchedCommandPayloadCreator.cs

This file was deleted.

3 changes: 0 additions & 3 deletions src/MySqlConnector/Core/ServerSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public ServerSession(ILogger logger, ConnectionPool? pool, int poolGeneration, i
public IPEndPoint? IPEndPoint => m_tcpClient?.Client.RemoteEndPoint as IPEndPoint;
public string? UserID { get; private set; }
public WeakReference<MySqlConnection>? OwningConnection { get; set; }
public bool SupportsComMulti => m_supportsComMulti;
public bool SupportsDeprecateEof => m_supportsDeprecateEof;
public bool SupportsCachedPreparedMetadata { get; private set; }
public bool SupportsQueryAttributes { get; private set; }
Expand Down Expand Up @@ -485,7 +484,6 @@ public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancella
activity.SetTag(ActivitySourceHelper.DatabaseConnectionIdTagName, connectionId);
}

m_supportsComMulti = (initialHandshake.ProtocolCapabilities & ProtocolCapabilities.MariaDbComMulti) != 0;
m_supportsConnectionAttributes = (initialHandshake.ProtocolCapabilities & ProtocolCapabilities.ConnectionAttributes) != 0;
m_supportsDeprecateEof = (initialHandshake.ProtocolCapabilities & ProtocolCapabilities.DeprecateEof) != 0;
SupportsCachedPreparedMetadata = (initialHandshake.ProtocolCapabilities & ProtocolCapabilities.MariaDbCacheMetadata) != 0;
Expand Down Expand Up @@ -1933,7 +1931,6 @@ protected override void OnStatementBegin(int index)
private IPayloadHandler? m_payloadHandler;
private bool m_useCompression;
private bool m_isSecureConnection;
private bool m_supportsComMulti;
private bool m_supportsConnectionAttributes;
private bool m_supportsDeprecateEof;
private bool m_supportsSessionTrack;
Expand Down
3 changes: 1 addition & 2 deletions src/MySqlConnector/MySqlBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ private ValueTask<MySqlDataReader> ExecuteReaderAsync(CommandBehavior behavior,
foreach (MySqlBatchCommand batchCommand in BatchCommands)
batchCommand.Batch = this;

var payloadCreator = Connection!.Session.SupportsComMulti ? BatchedCommandPayloadCreator.Instance :
IsPrepared ? SingleCommandPayloadCreator.Instance :
var payloadCreator = IsPrepared ? SingleCommandPayloadCreator.Instance :
ConcatenatedCommandPayloadCreator.Instance;
return CommandExecutor.ExecuteReaderAsync(new(BatchCommands!.Commands), payloadCreator, behavior, default, ioBehavior, cancellationToken);
}
Expand Down
1 change: 0 additions & 1 deletion src/MySqlConnector/Protocol/CommandKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ internal enum CommandKind
StatementPrepare = 22,
StatementExecute = 23,
ResetConnection = 31,
Multi = 254,
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ private static ByteBufferWriter CreateCapabilitiesPayload(ProtocolCapabilities s
ProtocolCapabilities.SessionTrack |
ProtocolCapabilities.DeprecateEof |
ProtocolCapabilities.QueryAttributes |
ProtocolCapabilities.MariaDbComMulti |
ProtocolCapabilities.MariaDbCacheMetadata |
additionalCapabilities) & serverCapabilities;

Expand Down
23 changes: 0 additions & 23 deletions tests/IntegrationTests/BatchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,29 +223,6 @@ public void ExecuteBatch(string suffix)
Assert.Equal(16, total);
}

[Fact(Skip = "COM_MULTI")]
public void ExecuteInvalidSqlBatch()
{
using var connection = new MySqlConnection(AppConfig.ConnectionString);
connection.Open();
using var batch = new MySqlBatch(connection)
{
BatchCommands =
{
new MySqlBatchCommand("SELECT 1;"),
new MySqlBatchCommand("SELECT 2 /* incomplete"),
new MySqlBatchCommand("SELECT 3;"),
},
};
using var reader = batch.ExecuteReader();
Assert.True(reader.Read());
Assert.Equal(1, reader.GetInt32(0));
Assert.False(reader.Read());

var ex = Assert.Throws<MySqlException>(() => reader.NextResult());
Assert.Equal(MySqlErrorCode.ParseError, ex.ErrorCode);
}

[Theory]
[InlineData(false)]
[InlineData(true)]
Expand Down
112 changes: 0 additions & 112 deletions tests/IntegrationTests/CancelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,50 +519,6 @@ public void CancelBatchBeforeRead()
Assert.InRange(rows, 0, 10000000);
}

[SkippableFact(ServerFeatures.StreamingResults | ServerFeatures.Timeout, Skip = "COM_MULTI")]
public void CancelMultiCommandBatchReader()
{
using var barrier = new Barrier(2);
using var batch = new MySqlBatch(m_database.Connection)
{
BatchCommands =
{
new MySqlBatchCommand(c_hugeQuery),
new MySqlBatchCommand(c_hugeQuery),
new MySqlBatchCommand(c_hugeQuery),
},
};
var task = Task.Run(() =>
{
barrier.SignalAndWait();
batch.Cancel();
});

int rows = 0;
using (var reader = batch.ExecuteReader())
{
Assert.True(reader.Read());

barrier.SignalAndWait();
try
{
while (reader.Read())
rows++;
}
catch (MySqlException ex)
{
Assert.Equal(MySqlErrorCode.QueryInterrupted, ex.ErrorCode);
}

// query returns 25 billion rows; we shouldn't have read many of them
Assert.InRange(rows, 0, 10000000);

Assert.False(reader.NextResult());
}

task.Wait(); // shouldn't throw
}

[Fact]
public async Task CancelBatchWithTokenBeforeExecuteScalar()
{
Expand Down Expand Up @@ -688,41 +644,6 @@ public async Task CancelHugeQueryBatchWithTokenAfterExecuteReader()
Assert.False(reader.NextResult());
}

[SkippableFact(ServerFeatures.StreamingResults | ServerFeatures.Timeout, Skip = "COM_MULTI")]
public async Task CancelHugeQueryBatchWithTokenInNextResult()
{
using var batch = new MySqlBatch(m_database.Connection)
{
BatchCommands =
{
new MySqlBatchCommand(c_hugeQuery),
new MySqlBatchCommand("select 1, 2, 3;"),
},
};
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(0.5));
using var reader = await batch.ExecuteReaderAsync(cts.Token);

// read first result set
Assert.True(await reader.ReadAsync(cts.Token));

try
{
// skip to the next result set
Assert.True(await reader.NextResultAsync(cts.Token));

// shouldn't get here
Assert.True(false);
}
catch (OperationCanceledException ex)
{
Assert.Equal(cts.Token, ex.CancellationToken);
}

// no more result sets
Assert.False(reader.Read());
Assert.False(reader.NextResult());
}

[SkippableFact(ServerFeatures.Timeout)]
public async Task CancelSlowQueryBatchWithTokenAfterExecuteReader()
{
Expand Down Expand Up @@ -796,39 +717,6 @@ public async Task CancelSlowQueryBatchWithTokenAfterNextResult()

Assert.False(await reader.NextResultAsync());
}

[SkippableFact(ServerFeatures.StreamingResults | ServerFeatures.Timeout, Skip = "COM_MULTI")]
public async Task CancelMultiStatementBatchInRead()
{
using var batch = new MySqlBatch(m_database.Connection)
{
BatchCommands =
{
new MySqlBatchCommand(c_hugeQuery),
new MySqlBatchCommand(c_hugeQuery),
new MySqlBatchCommand(c_hugeQuery),
},
};
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(0.5));
using var reader = await batch.ExecuteReaderAsync();
var rows = 0;
try
{
while (await reader.ReadAsync(cts.Token))
rows++;

Assert.True(false);
}
catch (OperationCanceledException ex)
{
Assert.Equal(cts.Token, ex.CancellationToken);
Assert.InRange(rows, 0, 10000000);
}

// no more result sets; the whole command was cancelled
Assert.False(reader.Read());
Assert.False(reader.NextResult());
}
#endif

private static CancellationToken GetCanceledToken()
Expand Down

0 comments on commit 5ad4cf3

Please sign in to comment.