Skip to content

Commit

Permalink
Purge expired message in order
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Hoppe committed Mar 4, 2016
1 parent 8de5071 commit e89b4a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/NServiceBus.SqlServer/SqlServerQueueCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ [RowVersion] ASC
CREATE NONCLUSTERED INDEX [Index_Expires] ON [{0}].[{1}]
(
[Expires] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
INCLUDE
(
[Id],
[RowVersion]
)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
END";

Expand Down
2 changes: 1 addition & 1 deletion src/NServiceBus.SqlServer/TableBasedQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ DELETE FROM message
deleted.Recoverable, IIF(deleted.Expires IS NOT NULL, DATEDIFF(ms, GETUTCDATE(), deleted.Expires), NULL), deleted.Headers, deleted.Body;";

const string SqlPurgeBatchOfExpiredMessages =
@"DELETE TOP({0}) FROM [{1}].[{2}] WITH (UPDLOCK, READPAST, ROWLOCK) WHERE [Expires] < GETUTCDATE()";
@"DELETE FROM [{1}].[{2}] WHERE [Id] IN (SELECT TOP ({0}) [Id] FROM [{1}].[{2}] WITH (UPDLOCK, READPAST, ROWLOCK) WHERE [Expires] < GETUTCDATE() ORDER BY [RowVersion])";

const string SqlCheckIfExpiresIndexIsPresent =
@"SELECT COUNT(*) FROM [sys].[indexes] WHERE [name] = '{0}' AND [object_id] = OBJECT_ID('[{1}].[{2}]')";
Expand Down

0 comments on commit e89b4a8

Please sign in to comment.