-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix in resolving serializer id #3135
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
Conversation
{ | ||
_serializers.Add(serializer.Identifier, serializer); | ||
_serializerIdByName.Add(name, serializer.Identifier); |
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.
Ok so technically, the Identifier is retrieved twice. But since Hocon caching is a thing. I found this to be more expressive then first storing the id in a temp var and using that.
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.
I'd take a look at my previous comment and consider just maintaining two <TKey, Serializer>
dictionaries - the ID-based one and the name based one, rather than go name --> id --> serializer you can just go name --> serializer. Does that make sense?
Going to do a review of this today |
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.
The fix is good but needs a bit of API love.
@@ -91,7 +92,8 @@ public Serialization(ExtendedActorSystem system) | |||
var serializer = serializerConfig != null | |||
? (Serializer)Activator.CreateInstance(serializerType, system, serializerConfig) | |||
: (Serializer)Activator.CreateInstance(serializerType, system); | |||
AddSerializer(serializer); | |||
|
|||
AddSerializer(kvp.Key, serializer); | |||
namedSerializers.Add(kvp.Key, serializer); |
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.
@Danthar so aren't we doing the same thing with _serializerIdByName
and the namedSerializers
local here? Why not just use that?
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.
Because we already have a dictionary mapping id => serializer instance. I could have promoted the namedSerializers
collection to a private member var. But that would mean we would store a reference to the same instance twice.
Not sure what my rationale was when i was writing this, but i wanted to avoid that. Hence the separate map _serializerIdByName
@@ -129,10 +131,9 @@ private Serializer GetSerializerByName(string name) | |||
{ | |||
if (kvp.Key.Equals(name)) | |||
{ | |||
var serializerTypeName = kvp.Value.GetString(); | |||
var serializerType = Type.GetType(serializerTypeName); | |||
if (!_serializerIdByName.TryGetValue(name, out int serializerId)) |
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.
I'd remove the serializersConfig
line here - no need to read in HOCON if we're just using a cached map.
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.
Yeah your right. The extra check on line 132 serves no purpose.
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public void AddSerializer(Serializer serializer) | ||
public void AddSerializer(string name, Serializer serializer) |
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.
This is a breaking API change since we're modifying a public method. IMHO, add a new overload and mark the old one as deprecated. That way we won't have binary compatibility issues on upgrade.
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.
You are correct. However seeing as its being aggressively inlined. Im wondering why it was public in the first place. But ok.
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.
{ | ||
_serializers.Add(serializer.Identifier, serializer); | ||
_serializerIdByName.Add(name, serializer.Identifier); |
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.
I'd take a look at my previous comment and consider just maintaining two <TKey, Serializer>
dictionaries - the ID-based one and the name based one, rather than go name --> id --> serializer you can just go name --> serializer. Does that make sense?
var serializerTypeName = kvp.Value.GetString(); | ||
var serializerType = Type.GetType(serializerTypeName); | ||
if (!_serializersByName.TryGetValue(name, out Serializer serializer)) | ||
throw new ArgumentException($"Couldn't find serializer for [{name}] make sure you correctly defined."); | ||
|
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.
I kept this check. Because it still possible to misconfigure for example serializer setting in persistence. Which is not checked during initialization.
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.
Sounds good
/// <param name="serializer">TBD</param> | ||
/// <returns>TBD</returns> | ||
/// <param name="serializer">Serializer instance</param> | ||
[Obsolete("No longer supported. Use the AddSerializer(name, serializer) overload instead.", true)] |
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.
Left out a "deadline" version here. Or would you rather have i put in something like. will be removed in 1.4 or something ?
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.
This is fine as-is.
@Danthar looks like a NRE in your new spec |
:D its interesting that the linux-netcore/unit-tests does complete. However another spec failed as well. Ill be fixing both. |
Serializer id is now only determined once, upon initialisation. And its the serializer implementation which dictates where that id comes from. We no longer assume it always comes from the hocon config.
This reverts commit 89a1d6b.
Serializer id is now only determined once, upon initialisation. And its
the serializer implementation which dictates where that id comes from.
We no longer assume it always comes from the hocon config.