-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log warning for varchar (old) headers column
- Loading branch information
Marcin Hoppe
committed
Jul 12, 2017
1 parent
4765488
commit eb27731
Showing
11 changed files
with
150 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/NServiceBus.SqlServer.IntegrationTests/When_checking_schema.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
namespace NServiceBus.SqlServer.AcceptanceTests.TransportTransaction | ||
{ | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
using Transport.SQLServer; | ||
using Transport; | ||
|
||
public class When_checking_schema | ||
{ | ||
const string QueueTableName = "CheckingSchema"; | ||
|
||
TableBasedQueue queue; | ||
|
||
[SetUp] | ||
public async Task SetUp() | ||
{ | ||
var addressParser = new QueueAddressParser("dbo", null, null); | ||
|
||
await ResetQueue(addressParser); | ||
|
||
queue = new TableBasedQueue(addressParser.Parse(QueueTableName)); | ||
} | ||
|
||
[Test] | ||
public async Task It_returns_type_for_headers_column() | ||
{ | ||
using (var connection = await sqlConnectionFactory.OpenNewConnection()) | ||
{ | ||
var type = await queue.CheckHeadersColumnType(connection); | ||
|
||
Assert.AreEqual("nvarchar", type); | ||
} | ||
} | ||
|
||
static SqlConnectionFactory sqlConnectionFactory = SqlConnectionFactory.Default(@"Data Source=.\SQLEXPRESS;Initial Catalog=nservicebus;Integrated Security=True"); | ||
|
||
static async Task ResetQueue(QueueAddressParser addressParser) | ||
{ | ||
var queueCreator = new QueueCreator(sqlConnectionFactory, addressParser); | ||
var queueBindings = new QueueBindings(); | ||
queueBindings.BindReceiving(QueueTableName); | ||
|
||
using (var connection = await sqlConnectionFactory.OpenNewConnection().ConfigureAwait(false)) | ||
{ | ||
using (var comm = connection.CreateCommand()) | ||
{ | ||
comm.CommandText = $"IF OBJECT_ID('{QueueTableName}', 'U') IS NOT NULL DROP TABLE {QueueTableName}"; | ||
comm.ExecuteNonQuery(); | ||
} | ||
} | ||
await queueCreator.CreateQueueIfNecessary(queueBindings, "").ConfigureAwait(false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
namespace NServiceBus.Transport.SQLServer | ||
{ | ||
using System; | ||
using System.Data.SqlClient; | ||
using System.Threading.Tasks; | ||
using Logging; | ||
|
||
class SchemaInspector | ||
{ | ||
public SchemaInspector(Func<TableBasedQueue, Task<SqlConnection>> openConnection) | ||
{ | ||
this.openConnection = openConnection; | ||
} | ||
|
||
public async Task PerformInspection(TableBasedQueue queue) | ||
{ | ||
await VerifyExpiredIndex(queue).ConfigureAwait(false); | ||
await VerifyHeadersColumnType(queue).ConfigureAwait(false); | ||
} | ||
|
||
async Task VerifyExpiredIndex(TableBasedQueue queue) | ||
{ | ||
try | ||
{ | ||
using (var connection = await openConnection(queue).ConfigureAwait(false)) | ||
{ | ||
var indexExists = await queue.CheckExpiresIndexPresence(connection).ConfigureAwait(false); | ||
if (!indexExists) | ||
{ | ||
Logger.Warn($@"Table {queue} does not contain index 'Index_Expires'.{Environment.NewLine}Adding this index will speed up the process of purging expired messages from the queue. Please consult the documentation for further information."); | ||
} | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Logger.WarnFormat("Checking indexes on table {0} failed. Exception: {1}", queue, ex); | ||
} | ||
} | ||
|
||
async Task VerifyHeadersColumnType(TableBasedQueue queue) | ||
{ | ||
try | ||
{ | ||
using (var connection = await openConnection(queue).ConfigureAwait(false)) | ||
{ | ||
var columnType = await queue.CheckHeadersColumnType(connection).ConfigureAwait(false); | ||
if (string.Equals(columnType, "varchar", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
Logger.Warn($"Table {queue} stores headers in a non Unicode-compatible column (varchar).{Environment.NewLine}This may lead to data loss when sending non-ASCII characters in headers. SQL Server transport 3.1 and newer can take advantage of the nvarchar column type for headers. Please change the column type in the database."); | ||
} | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Logger.WarnFormat("Checking indexes on table {0} failed. Exception: {1}", queue, ex); | ||
} | ||
} | ||
|
||
Func<TableBasedQueue, Task<SqlConnection>> openConnection; | ||
static ILog Logger = LogManager.GetLogger<ExpiredMessagesPurger>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters