Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Aug 15, 2024. It is now read-only.

Comments

Close side panel

Handle SetStreamMetadata idempotently#129

Merged
damianh merged 7 commits intoSQLStreamStore:masterSQLStreamStore/SQLStreamStore:masterfrom
damianh:idempotent-metadataCopy head branch name to clipboard
May 21, 2018
Merged

Handle SetStreamMetadata idempotently#129
damianh merged 7 commits intoSQLStreamStore:masterSQLStreamStore/SQLStreamStore:masterfrom
damianh:idempotent-metadataCopy head branch name to clipboard

Conversation

@damianh
Copy link
Member

@damianh damianh commented May 20, 2018

In many cases a developer will lazily set the metadata of a stream. There are scenarios, especially when appending with StreamVersion.Any that they may set the same metadata over and over. This will increase the metadata stream length unnecessarily.

In another case, if users want to handling this idempotently, they have to invoke a read'n'check first. This has subtle race conditions.

This PR:

  • Adds a deterministic guid generator and tests
  • Add a MetadataMessageIdGenerator with a fixed GUID namespace.

@damianh damianh self-assigned this May 20, 2018
@damianh
Copy link
Member Author

damianh commented May 20, 2018

I'm comfortable in declaring this as non-breaking.

@damianh damianh changed the title [WIP] Handle SetStreamMetadata idempotently Handle SetStreamMetadata idempotently May 20, 2018

var metadata = await store.GetStreamMetadata(streamId);

metadata.MetadataStreamVersion.ShouldBe(0);
Copy link
Member Author

Choose a reason for hiding this comment

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

The primary test. StreamVersion should not have been incremented and stay at 0.

<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<RootNamespace>SqlStreamStore</RootNamespace>
<NoWarn>1701;1702;1705;1591</NoWarn>
<LangVersion>latest</LangVersion>
Copy link
Member Author

Choose a reason for hiding this comment

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

Slipped this in to all projects

}

using(var command = new SqlCommand(commandText, connection))
using (var command = new SqlCommand(commandText, connection, transaction))
Copy link
Member Author

Choose a reason for hiding this comment

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

Needed to pass this down because command wouldn't work if in a transaction scope. In other paths, this is null, which is fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not completely following - are you saying that particular overload needs to be called even if transaction is null?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because this transcation

using(var transaction = connection.BeginTransaction())
was getting associated with the connection, if I didn't pass it to this sql command I was getting sql exception.

System.InvalidOperationException: BeginExecuteReader requires the command to have a transaction when the connection assigned to the command is in a pending local transaction.  The Transaction property of the command has not been initialized.
   at System.Data.SqlClient.SqlCommand.ValidateCommand(Boolean async, String method)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite, String method)
   at System.Data.SqlClient.SqlCommand.BeginExecuteReader(CommandBehavior behavior, AsyncCallback callback, Object stateObject)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncImpl[TArg1](Func`4 beginMethod, Func`2 endFunction, Action`1 endAction, TArg1 arg1, Object state, TaskCreationOptions creationOptions)
   at System.Threading.Tasks.TaskFactory`1.FromAsync[TArg1](Func`4 beginMethod, Func`2 endMethod, TArg1 arg1, Object state)
   at System.Data.SqlClient.SqlCommand.ExecuteReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)

@damianh damianh added this to the v1.1.2 milestone May 20, 2018
@damianh
Copy link
Member Author

damianh commented May 20, 2018

Would like to slip this into v1.1.2

/// <returns>
/// A deterministically generated GUID.
/// </returns>
public Guid Create(IEnumerable<byte> source)
Copy link
Contributor

Choose a reason for hiding this comment

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

Very minor, but there's no reason to step into the enumerable world - sticking with byte arrays keeps the translation down to a minimum.

}

using(var command = new SqlCommand(commandText, connection))
using (var command = new SqlCommand(commandText, connection, transaction))
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not completely following - are you saying that particular overload needs to be called even if transaction is null?

@damianh damianh merged commit b54cac7 into SQLStreamStore:master May 21, 2018
@damianh damianh deleted the idempotent-metadata branch May 21, 2018 11:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.