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

Support for custom placement strategies and directors #2932

Merged
merged 7 commits into from Apr 13, 2017

Conversation

sergeybykov
Copy link
Contributor

IPlacementDirector today defines two methods: OnAddActivation and OnSelectActivation. The latter is used only for a couple of special cases, and custom placement policies only need to be concerned with the former. OnSelectActivation depends on a number of internal types, while OnAddActivation does not.

I split the two operations between two interfaces: public IPlacementDirector for custom (and built-in) placement directors to implement and internal IActivationSelector for those special internal (for now) cases. A few more types needed to be made public, but those were easy.

This should enable #2764 and #96.

Placement strategies for now have to be serializable. We can look at removing this requirement later.

…lacementRuntime.

Make PlacementTarget and PlacementStrategy public.
Replace PlacementTarget.GrainId with PlacementTarget.GrainIdentity.
Make constructor of PlacementAttribute protected.

Guid GetPrimaryKey(out string keyExt);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: most of the codebase uses spaces for indentation

var director = this.ResolveDirector(strategy);
if (director is IActivationSelector)
this.ResolveSelector(strategy);
}
Copy link
Member

Choose a reason for hiding this comment

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

what was wrong with this approach? it was a nice one to avoid issues if more built in strategies support selection in the future. The only thing that was missing was passing true to ResolveSelector, right?
Anyway, I think it's OK regardless, even if my preference is the previous approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem was rather subtle. RandomPlacementDirector implements both IPlacementDirector and IActivationSelector. ActivationCountPlacementDirector extends RandomPlacementDirector, but it only really implements IPlacementDirector, though the check is IActivationSelector returns true for it. That was causing a problem.

I considered splitting RandomPlacementDirector into separate classes for placement director and activation selector, but thought it would cause even more code churn. Can be done as a separate change later.


public PlacementTarget(IGrainIdentity grainIdentity, int interfaceId, ushort interfaceVersion)
{
GrainIdentity = grainIdentity;
Copy link
Member

Choose a reason for hiding this comment

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

be careful with tabs in several places

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Weird. Must be different setting on my desktop. I fixed them, but Git seems to be ignoring the changes.

Copy link
Member

@benjaminpetit benjaminpetit left a comment

Choose a reason for hiding this comment

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

LGTM, apart from some tabs instead of spaces (had same issue with VS2017)

}


public enum CustomePlacementScenario
Copy link
Member

Choose a reason for hiding this comment

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

very nit: no 'e' after "Custom"

@@ -39,15 +33,15 @@ internal interface IPlacementContext
void GetGrainTypeInfo(int typeCode, out string grainClass, out PlacementStrategy placement, out MultiClusterRegistrationStrategy strategy, string genericArguments = null);
}

internal static class PlacementContextExtensions
internal static class PlacementContextExtensions

Choose a reason for hiding this comment

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

Minor: rename to PlacementRunTimeExtensions?

this.selectors[strategyType] = result;
}

return result ?? defaultActivationSelector;

Choose a reason for hiding this comment

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

Not very familiar with the code. But basic question: In line number 54 result is assigned to this.selectors[strategyType]. In line 57 if result is null --- defaultActivationSelector is returned. Should we update the this.selectors[strategyType] to default if result is null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not very familiar with the code.

Me neither. :-) result can be null if TryGetValue returns false. That's the case when we fall back to the default selector.

@jdom
Copy link
Member

jdom commented Apr 13, 2017

There's several other tabs that were introduced. Do you want me to fix them? I have push access to your repo

@sergeybykov
Copy link
Contributor Author

@jdom By all means. Thank you.

@jdom
Copy link
Member

jdom commented Apr 13, 2017

Done, I forced pushed to the Addressed review comments commit, since I'd like to merge without squashing

@sergeybykov
Copy link
Contributor Author

Perfect.

@jdom jdom merged commit 8e5d8cd into dotnet:master Apr 13, 2017
@sergeybykov sergeybykov deleted the public-placement-3 branch May 4, 2017 01:01
@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants