Nikolay Izhikov created IGNITE-29259:
----------------------------------------
Summary: Affinity key field of a type listed in
BinaryTypeConfiguration is ignored when the class is visible only through
IgniteConfiguration.classLoader
Key: IGNITE-29259
URL: https://issues.apache.org/jira/browse/IGNITE-29259
Project: Ignite
Issue Type: Bug
Reporter: Nikolay Izhikov
Assignee: Nikolay Izhikov
{{BinaryContext#configure}} resolves the class of every
{{BinaryTypeConfiguration}} entry with
{{ClassLoaderUtils.classForName(clsName)}}, i.e. through the class loader
Ignite itself was loaded by. The class loader set via
{{IgniteConfiguration#setClassLoader}} is not consulted. When the class is
visible only through the configured loader the lookup returns {{null}} and the
{{@AffinityKeyMapped}} field is not detected.
{{BinaryContext#registerUserType}}, called right after for the same type,
resolves the class through the configured loader, finds it and registers the
descriptor and the binary metadata with {{affinityKeyFieldName = null}}. The
descriptor is cached in {{predefinedTypes}}/{{descByCls}}, so marshalling an
instance later does not fix the metadata.
Result: for the same key class the affinity key field is {{null}} if the type
is listed in {{BinaryConfiguration#setTypeConfigurations}} and is detected
correctly if it is not listed (the class is then examined when the first
instance is marshalled). Keys of configured types are therefore routed by the
whole key instead of the annotated field.
Reproducer: {{BinaryTypeConfigurationCustomClassLoaderTest}} compiles a key
class at runtime into a directory that is not on the test classpath, sets a
{{URLClassLoader}} over it as {{IgniteConfiguration#setClassLoader}} and checks
{{ignite.binary().type(clsName).affinityKeyFieldName()}} with and without a
{{BinaryTypeConfiguration}} for the class.
{{testAffinityKeyFieldOfConfiguredType}} fails on master with {{expected:<aff>
but was:<null>}}, {{testAffinityKeyFieldOfUnconfiguredType}} passes.
Fix: resolve the class in {{configure}} through
{{BinaryContext#classLoader()}}, the same loader {{registerUserType}} uses.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)