-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add TGrainState type constraints to document necessary system constraints - Resolves #1906 #1923
Add TGrainState type constraints to document necessary system constraints - Resolves #1906 #1923
Conversation
…ks implementing stateful grains. Fixes #1906
Hi @normanhh3, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution! TTYL, DNFBOT; |
I think we can safely limit grain state to be a class. No need to support structs, right? |
Activator.CreateInstance seems to be the limiting factor. I don't believe structs are supported today in the code so adding this constraint to exclude them would not break existing functionality from my reading of the code. |
@normanhh3 I personally don't believe CLA is required for such a small change, but it would be easier if you could sign it. The process is very straightforward and painless. Thanks. |
Yeah, I am on it. Just needed to double check with employer first. :-/ Sigh. Norman
|
Are you certain about this? I believe I've seen code that uses immutable structs as the state (they just set the entire State property on every modification). |
Also, if we are adding the |
@normanhh3, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR. |
@jdom fair enough critique. Activator.CreateInstance(typeof(Int32)) does indeed return an Int. The code here is where that state is created. I believe Line 79 is the relevant location. Maybe the challenge here is JUST with the String type, although the error seemed to indicate that any class used for state had to have a parameterless constructor (by way of Activator.CreateInstance). Maybe it should be struct, class, new() and Activator.CreateInstance can then appropriately determine how to construct struct's versus classes? |
Just for some context - a while ago there used to be |
The class constraint alone may have been the issue. I will play with all three and see if I can get it to support structs as well as classes. |
@dVakulen thanks for the clarification. @jdom, yes it appears that the intent is to support structs as well as classes. At the moment it does not appear that there will be a compatible compile time type check. :-( I was really hoping that The only other thing I can think to do, to ease the debugging challenge is to clarify the exception message that is generated from Thoughts? |
Not sure I understand the value of having both |
@jdom this is likely stemming from my potential misunderstanding of the purpose of the I did compile the project with just the Is there enough test coverage that I shouldn't need to add additional tests? I did review a number of them, but didn't see anything that was 100% what I was looking for as far as verification of supported Grain state types. At this point, any pointers are appreciated. |
well, I guess if the compiler enforces the constraint, it would be hard to create a unit test... If you can think of something to add coverage (now that you already browsed around the codebase) that would be welcome. But this additional constraint basically would disallow something that today was not covered (otherwise you would be getting compile time errors today) |
Having said that, if there isn't any, it might be good to add a test using a struct for state. |
@jdom So far I have spent a few hours debugging what should be a simple test to indicate support of structs as state. I finally tracked down why my test is failing, but don't have a great explanation for why the code is the way it is. Currently I have setup a test grain to use an Int64 to test the struct case with. The following code from: SiloAssemblyLoader.cs Line 95
Specifically the part where stateArg.GetTypeInfo().IsClass. This line causes the struct-based grain state test to fail. The issue here is that this code cannot determine the proper type for the grain because it does not support structs! I propose changing the above code to be the following:
This change allows my test to pass. Unfortunately I am having an issue with bcyrpt.dll not being found properly so I can't run a full regression on the codebase right now.
I will commit my changes and we can talk about how they might be good or bad. |
…ge capability with new() constraint
…ks implementing stateful grains. Fixes #1906
…ge capability with new() constraint
@@ -325,6 +325,26 @@ public void Persistence_Silo_StorageProvider_Name_Missing() | |||
} | |||
|
|||
[Fact, TestCategory("Functional"), TestCategory("Persistence")] | |||
public async Task Persistence_Read_Write_Struct_State() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, please use ValueType instead of Struct in the method name.
Thanks @normanhh3, adding coverage for value types is extremely useful. It seems (by the look at the dead code for BTW, not sure what that bcyrpt.dll issue is, never seen it before. Seems like the CI build didn't have the same issue anyway. |
@jdom I believe that the root cause of broken support of value types is this line - a9128de#diff-2af53438f066a85e2bb283c98debde41R104 |
Wow, @dVakulen, that is a very old commit. Nevertheless I guess that wasn't an issue back then when you were required to inherit from |
@dotnet-bot test this please |
Sorry guys, got caught up in some other major initiatives and haven't been able to get back to this yet. |
@normanhh3 @jdom I saw an issue which I did not get the time to work more on it and fix or something. If grainState is an int then the serializer throws a NullReferenceException if you try to write state by the grain was like class MyGrain : Graind<int>,IMyGrainINterface
{
pubcli Task Save()
{
return WriteStateAsync(); // throws NullReferenceException if called before setting State
}
} |
@dotnet-bot test this please |
@jdom check out the changes per your comments previously. @sergeybykov it looks like I can't fix some test errors that are being created because the source for those tests is outside the repo! Your suggestions on how to resolve these remaining issues are appreciated.
|
@normanhh3 Looks like those types aren't even used anywhere. I deleted them, and everything build fine. |
…ks implementing stateful grains. Fixes #1906
…ge capability with new() constraint
@normanhh3 I rebased/squashed your commits in fixed the build break in https://github.com/sergeybykov/orleans/commits/1923-rebased. Feel free to pull into your branch. |
Awesome, I'll pull it into my code once I figure out how. ;-) |
If it's too much hassle for you, I can simply submit a PR with my branch in lieu of this one. |
Thank you, @normanhh3! |
…ints - Resolves dotnet#1906 (dotnet#1923) * Add TGrainState constraints to document clearly what is needed by folks implementing stateful grains. Fixes dotnet#1906 * Removed class constraint because it was overly broad * Extended type interogation to determine the appropriate grain type from structs * Created test case to verify support of struct-based grain state storage capability with new() constraint * Add TGrainState constraints to document clearly what is needed by folks implementing stateful grains. Fixes dotnet#1906 * Removed class constraint because it was overly broad * Extended type interogation to determine the appropriate grain type from structs * Created test case to verify support of struct-based grain state storage capability with new() constraint * Moved test grain to non-internal location * Switched to using ValueTypeTestData * Moved test to new location and refactored to use non-internal methods * Add TGrainState constraints to document clearly what is needed by folks implementing stateful grains. Fixes dotnet#1906 * Created test case to verify support of struct-based grain state storage capability with new() constraint * Removed unused grain classes that were failing to compile. * Fixed MemoryStore provider name.
This adds constraint checking to the type for State types so that implementers get compile time checks instead of runtime errors.