dotnet / orleans

Cloud Native application framework for .NET
https://docs.microsoft.com/dotnet/orleans
MIT License
10.07k stars 2.03k forks source link

Custom grain placement #6837

Closed SarcoZ closed 2 years ago

SarcoZ commented 3 years ago

I have a scene like this, three silos, called G1、G2、G3 there is a grain with string key, if grain primary key start with G1,I want activate by silo G1,if grain primary key start with G2,,I want activate by silo G2,if grain primary key start with G3,,I want activate by silo G3 I see IPlacementDirector interface Task<SiloAddress> OnAddActivation(PlacementStrategy strategy, PlacementTarget target, IPlacementContext context); but context can only get SiloAddress array,I can not get any info about silo such as option read from silo configuration how can help me to choose silo by siloname or solo sign

sergeybykov commented 3 years ago

Currently, cluster membership uses silo addresses as their identities and does not propagate any other properties of silos to placement directors. There've been discussions about introducing logical silo identities. Until that is implemented, the only way around I can think of is for a placement director like that to use an out-of-band coordination mechanism. For example, each silos could write the data you need from it to some storage, so that the placement director could load from there, match it up addresses of available silos provided via IPlacementContext.GetCompatibleSilos(), and make its placement decisions.

SarcoZ commented 3 years ago

@sergeybykov I find that I can use silo name as silo identity, if i have the lastest membership map like IDictionary<string,SiloAddress> I can fast find the silo address my need,this can help me achieve the goal,so I look MembershipTableManager.cs,in this class,it keep the lastest MembershipTableSnapshot, I can use it to build my map like IDictionary<string,SiloAddress>,but MembershipTableSnapshot class is internal,can you provide an event,when MembershipTableManager.MembershipTableSnapshot change,notify the latest MembershipTableSnapshot,I can subscribe this event,then I can do many more thing,The changes are relatively small eg: change the MembershipTableSnapshot class to public,such as define an interface IMembershipTableSnapshotListener,MembershipTableManager implementation it, I subscribe IMembershipTableSnapshotListener.OnChange

another can place MembershipEntry in IPlacementContext

Ilchert commented 3 years ago

Just an idea of how to activate your grains on specific silos: You can create several marker interfaces IGrainOnG1, IGrainOnG2, IGrainOnG3 and create implementations of those interfaces in the specific Silo. Then you can control the placement of grain just choosing the right interface. This technique can be useful if you have a static count of the silo.

SarcoZ commented 3 years ago

@Ilchert grain type is same,I can not change interface to do that,my cluser may have many group,I used this as distribute file system,grain can not active random

Cloud33 commented 3 years ago

I thought about a way before

I don't know if I can do that

way:

Put the 'grain' parameter that needs to be activated in the same 'Silo', that is, the primary key is placed in the 'Requestcontext'. Then, the user-defined 'placement' is used to hash the primary key on the 'Requestcontext'

The key is whether 'requestcontext' can be used in 'placement' and whether it is thread safe?

thank you @sergeybykov @SarcoZ

sergeybykov commented 3 years ago

@SarcoZ MembershipTableSnapshot is intended for the gossip protocol between silos. ISiloStatusListener is the interface for receiving local notifications about changes in the cluster. Perhaps a better solution would be to add snapshot as an argument to ISiloStatusListener.SiloStatusChangeNotification(SiloAddress updatedSilo, SiloStatus status)? I wonder what @ReubenBond and @benjaminpetit think about that.

ReubenBond commented 3 years ago

There's IClusterMembershipService which exposes a similar snapshot (but without the implementation detail that IMembershipTable has): https://github.com/dotnet/orleans/blob/147b214c235b5528f6c7ed7837c559a4b0906816/src/Orleans.Runtime/MembershipService/IClusterMembershipService.cs#L6

SarcoZ commented 3 years ago

@sergeybykov @ReubenBond I also see IClusterMembershipService.cs, now it not support me to achieve my goal,need modify in framework,thanks

benjaminpetit commented 2 years ago

Closing this issue, since it seems you find a solution!