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

Mixing attributes #107

Closed
yevhen opened this issue Feb 10, 2015 · 10 comments
Closed

Mixing attributes #107

yevhen opened this issue Feb 10, 2015 · 10 comments
Milestone

Comments

@yevhen
Copy link
Contributor

yevhen commented Feb 10, 2015

There are a number of attribute combinations which doesn't make sense to mix together. For example: mixing StatelessWorker with any of Placement attributes doesn't make sense, but it looks like currently it is allowed to combine them within same class declaration.

I'm not sure what will happen in this case and I guess that handling code is smart enough to just ignore placement attributes if used along with StatelessWorker. Nevertheless, I found it to be confusing and I think it might be better to fail with exception to prevent users polluting grain declarations with useless combinations of attributes, which will confuse all future readers. Also, such validation should prevent users from cargo-culting Orleans.

Other invalid combinations:

  • Mixing attributes from same category - looks like now I can put both RandomPlacement and ActivationCountBased or PreferLocal. Which one will Orleans choose?
  • Reentrant could be mixed with AlwaysInterleave - seems like another confusing combination. Grain is either fully reentrant (class-level attribute) - all methods are subject to interleaving, or only some individual methods allow interleaving.

Another, possible and probably more intuitive approach will be, is to group all choices under respective category attributes (and use AllowMultiple=false), to make alternation explcit. Something like:

  • Activation - Singleton / StatelessWorker
  • Concurrency - Strict / Reentrant
  • Placement - Random / PreferLocal / ActivationCountBased
  • Delivery - Ordered / Unordered
  • etc

What do you think?

@pherbel
Copy link
Contributor

pherbel commented Feb 10, 2015

+1
This is more straightforward approach I like it

@gabikliot
Copy link
Contributor

I like the straightforward approach. Maybe the naming for some categories will be a different.

@yevhen
Copy link
Contributor Author

yevhen commented Feb 10, 2015

@gabikliot sure, it was just an example

@sergeybykov
Copy link
Contributor

Should we catch such violations at compile/codegen time, just like we do for grain interface rules?

@yevhen
Copy link
Contributor Author

yevhen commented Feb 10, 2015

@sergeybykov hmmm, but isn't codegen only operates on interface project? And those attributes target grain class implementations ...

@sergeybykov
Copy link
Contributor

Codegen runs for grain implementations too, to generate state classes from state interfaces.

@sergeybykov
Copy link
Contributor

To clarify, I meant to say that in addition to structuring attributes into categories and having compiler enforce AllowMultiple=false, which I think is a great suggestion, we can also catch any violations that pass that filter at codegen time.

@jkonecki
Copy link
Contributor

Another +1 for grouping attributes.

On Tue, 10 Feb 2015 22:10 Sergey Bykov notifications@github.com wrote:

Codegen runs for grain implementations too, to generate state classes from
state interfaces.


Reply to this email directly or view it on GitHub
#107 (comment).

@yevhen
Copy link
Contributor Author

yevhen commented Feb 10, 2015

@sergeybykov ah, sorry, forgot about that. I don't use built-in persistence :) Ye, it would be great, since grouping into category attributes with backed choice enums is not enough to catch invalid combinations across categories, such as StatelessWorker + Placement, or Reentrant + AlwaysInterleave

@yevhen
Copy link
Contributor Author

yevhen commented Feb 18, 2015

From my PoC, I've think that best way to group attributes is by having a configuration attribute for each type of activation. That will elegantly restrict what could be configured for each type of activation:

public enum Placement
{
    Auto,
    PreferLocal,
    DistributeEvenly
}

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class GrainAttribute : Attribute
{
    public readonly Placement Placement;

    public GrainAttribute(Placement placement = Placement.Auto)
    { 
        Placement = placement; 
    }
}

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class StatelessWorkerAttribute : Attribute
{
    // no additional configuration options at the moment
}

That only leaves us with mixing Reentrant and AlwaysInterleave but that not a big deal at all.

@sergeybykov sergeybykov added this to the Backlog milestone Jan 7, 2017
@jason-bragg jason-bragg added the P4 label Jul 5, 2018
@yevhen yevhen closed this as completed Apr 7, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Sep 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants