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

Insert events into MSSQL in deterministic order #20

Merged
merged 1 commit into from
Mar 16, 2016

Conversation

LeeCampbell
Copy link
Contributor

I believe this closes #19

The change is based on a simple idea: SELECT queries do not have any guarantees of ordering unless you specify an ORDER BY. When any insert is being made, it is being done from a dbo.NewStreamEvents Table Value type parameter. This data is in an order, but that doesn't mean that it will be read in that order, which means it will not be inserted in that order. By simply specifying the ORDER BY StreamVersion; we can ensure that inserts will be in the order we expected.

I have added the test provided in #19, and was able to have it fail fairly consistently without the ORDER BY clauses. I have run the tests a dozen times since adding the ORDER BY clause and have not seen a failure.

Note this did NOT fix the other two failing tests.

@@ -20,7 +20,8 @@ BEGIN TRANSACTION AppendStream;
[Type],
JsonData,
JsonMetadata
FROM @newEvents;
FROM @newEvents
ORDER BY StreamVersion;
Copy link
Member

Choose a reason for hiding this comment

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

@yreynhout looks simple enough fix :)

damianh added a commit that referenced this pull request Mar 16, 2016
Insert events into MSSQL in deterministic order
@damianh damianh merged commit f22c0ac into SQLStreamStore:master Mar 16, 2016
@damianh
Copy link
Member

damianh commented Mar 16, 2016

Lovely, thanks @LeeCampbell !

@LeeCampbell LeeCampbell deleted the EventOrdering branch March 16, 2016 06:33
thefringeninja added a commit to thefringeninja/SQLStreamStore that referenced this pull request Oct 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cedar.EventStore.MsSql2008 doesn't store events in the correct order
2 participants