orleans icon indicating copy to clipboard operation
orleans copied to clipboard

Pass stream namespace to implicit subscription grain

Open DixonDs opened this issue 9 years ago • 10 comments

We could pass stream ID + namespace, if the target grain implements IGrainWithGuidCompoundKey. This could be useful for grains implicitly subscribed to multiple streams and, for example, if https://github.com/dotnet/orleans/issues/1747 is implemented.

DixonDs avatar May 01 '17 09:05 DixonDs

I'm not entirely sure I follow you. Are you suggesting we make streamId + namespace to be the implicit subscribed grain's primary key so that the grain which subscribed to multiple namespaces can give information like: I was activated by stream xxxx under namespace yyy?

xiazen avatar May 02 '17 23:05 xiazen

If yes, I think I will vote a slight no to this case. Grain primary key is used for uniquely identifying a grain. I would be careful on adding more information to grain primary key unless there's concrete need for it. So I guess my question is, why does grain care which stream with namespace yy wakes it up?

xiazen avatar May 02 '17 23:05 xiazen

@xiazen

Are you suggesting we make streamId + namespace to be the implicit subscribed grain's primary key so that the grain which subscribed to multiple namespaces can give information like: I was activated by stream xxxx under namespace yyy?

Yes, but only if the grain implements IGrainWithGuidCompoundKey. We can preserve the existing behavior if the grain implements IGrainWithGuidKey

why does grain care which stream with namespace yy wakes it up?

It needs to subscribe to the stream in OnActivateAsync and thus needs to know the stream namespace, unless I am missing something.

DixonDs avatar May 03 '17 05:05 DixonDs

The implicit subscribe side of streaming is designed on the assumption that consumer grain knows what stream and namespace it will subscribe to, which leads to my confusion of 'why does grain care which stream with namespace yy wakes it up?', because it should already know.

But this pattern is not easy or user friendly or straightforward to use IMO. And you are not the first person to bring it up. And the case of the grain implicit subscribe to multiple name space definitely make it harder for the consumer grain to figure out what kind of handle it should attach to the stream which wakes it up.

I think I agree that we should notify the consumer grain about the name space and stream id in some way. But I'm not convinced that through grain id is the way to go. It is against the sole responsibility of grainId. And it is not type safe in the sense of object design pattern. It's like a hidden trick in Orleans with really low discoverability.

xiazen avatar May 03 '17 17:05 xiazen

But I see we already hide streamId in grainId. I guess it is reasonable to bring that trick one step further as a quick fix to fix the situation of "consumer grain subscribe to multiple namespace".

But I really hope we can remove the design assumption of "the consumer grain should know what stream or name space it will subscribe to" in the future, and provide the grain more information about what stream it is dealing with.

xiazen avatar May 03 '17 18:05 xiazen

I think we should do it . And when you do it, add a extensions method to decode namespace and streamId from grainId. Since it will be hard for user to figure out how Orleans encode those info into the GrainID.

xiazen avatar May 03 '17 18:05 xiazen

@xiazen I see that it is currently tagged as 2.0.0. Is it possible to have it in 1.5.0?

DixonDs avatar May 16 '17 07:05 DixonDs

yes it is possible. especially now we are thinking about getting a 1.5 beta2 .

xiazen avatar May 16 '17 19:05 xiazen

@jdom when we do a 1.5 beta2, can we include changes in #3011 and #2988 , both of which are in master? Since I'm not sure we are going to do a cherry pick or include all commits in master so far.

xiazen avatar May 16 '17 19:05 xiazen

checked with Jdom, those changes will be in 1.5 beta2

xiazen avatar May 19 '17 17:05 xiazen