[ 
https://issues.apache.org/jira/browse/IGNITE-13160?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Alexandr Shapkin updated IGNITE-13160:
--------------------------------------
    Description: 
When QueryEntities is set alongside a custom key that utilizes the 
AffinityKeyMapped attribute, the field won't be taken into account for some 
reason. When QueryEntities configuration gets removed, all works fine, setting 
KeyConfiguration manually helps as well. At the same time, the BinaryType 
registration itself looks fine.

After the investigation, it turned out that affinityKey field is not being 
registered on cache registration, and null is being cached instead. Later on 
Ignite correctly tries to register a custom class as a key, but it's never 
being updated internally case the real value is already cached.

 

NOTE: there is a workaround - you need to specify the key configuration 
explicitly:

cacheConfiguration.KeyConfiguration = new List<CacheKeyConfiguration>(1)
{code:java}
{
 //affinityKey should be auto adjusted with Reflection
 new CacheKeyConfiguration(typeof(MyKey))
};
 
{code}
 

Reproducer (add to the AffinityTest.cs):
{code:java}
        /// <summary>
        /// Tests AffinityKeyMapped attribute should map to the same partitions
        /// for the same field value.
        /// </summary>
        [Test]
        public void TestCustomAffinity()
        {
            IIgnite g = Ignition.GetIgnite("grid-0");

            var cacheCfg = new CacheConfiguration("mycache")
            {
                // Without QueryEntities tests passes.
                QueryEntities = new List<QueryEntity>()
                {
                    new QueryEntity(typeof(MyKey), typeof(int))
                }
            };
            g.GetOrCreateCache<MyKey, int>(cacheCfg);

            var key1 = new MyKey {Data = "data1", AffinityKey = 1};
            var key2 = new MyKey {Data = "data2", AffinityKey = 1};

            ICacheAffinity aff = g.GetAffinity(cacheCfg.Name);
            Assert.AreEqual(aff.GetPartition(key1), aff.GetPartition(key2));
        }

        public class MyKey
        {
            [QuerySqlField]
            public string Data { get; set; }
            [AffinityKeyMapped]
            public long AffinityKey { get; set; }
        }
{code}

  was:
When QueryEntities is set alongside a custom key that utilizes the 
AffinityKeyMapped attribute, the field won't be taken into account for some 
reason. When QueryEntities configuration gets removed, all works fine, setting 
KeyConfiguration manually helps as well. At the same time, the BinaryType 
registration itself looks fine.

After the investigation, it turned out that affinityKey field is not being 
registered on cache registration, and null is being cached instead. Later on 
Ignite correctly tries to register a custom class as a key, but it's never 
being updated internally case the real value is already cached.

 

Reproducer (add to the AffinityTest.cs):
{code:java}
        /// <summary>
        /// Tests AffinityKeyMapped attribute should map to the same partitions
        /// for the same field value.
        /// </summary>
        [Test]
        public void TestCustomAffinity()
        {
            IIgnite g = Ignition.GetIgnite("grid-0");

            var cacheCfg = new CacheConfiguration("mycache")
            {
                // Without QueryEntities tests passes.
                QueryEntities = new List<QueryEntity>()
                {
                    new QueryEntity(typeof(MyKey), typeof(int))
                }
            };
            g.GetOrCreateCache<MyKey, int>(cacheCfg);

            var key1 = new MyKey {Data = "data1", AffinityKey = 1};
            var key2 = new MyKey {Data = "data2", AffinityKey = 1};

            ICacheAffinity aff = g.GetAffinity(cacheCfg.Name);
            Assert.AreEqual(aff.GetPartition(key1), aff.GetPartition(key2));
        }

        public class MyKey
        {
            [QuerySqlField]
            public string Data { get; set; }
            [AffinityKeyMapped]
            public long AffinityKey { get; set; }
        }
{code}


> .NET: wrong affinity key registration with AffinityKeyMapped attribute
> ----------------------------------------------------------------------
>
>                 Key: IGNITE-13160
>                 URL: https://issues.apache.org/jira/browse/IGNITE-13160
>             Project: Ignite
>          Issue Type: Bug
>          Components: platforms
>    Affects Versions: 2.8.1
>            Reporter: Alexandr Shapkin
>            Priority: Major
>
> When QueryEntities is set alongside a custom key that utilizes the 
> AffinityKeyMapped attribute, the field won't be taken into account for some 
> reason. When QueryEntities configuration gets removed, all works fine, 
> setting KeyConfiguration manually helps as well. At the same time, the 
> BinaryType registration itself looks fine.
> After the investigation, it turned out that affinityKey field is not being 
> registered on cache registration, and null is being cached instead. Later on 
> Ignite correctly tries to register a custom class as a key, but it's never 
> being updated internally case the real value is already cached.
>  
> NOTE: there is a workaround - you need to specify the key configuration 
> explicitly:
> cacheConfiguration.KeyConfiguration = new List<CacheKeyConfiguration>(1)
> {code:java}
> {
>  //affinityKey should be auto adjusted with Reflection
>  new CacheKeyConfiguration(typeof(MyKey))
> };
>  
> {code}
>  
> Reproducer (add to the AffinityTest.cs):
> {code:java}
>         /// <summary>
>         /// Tests AffinityKeyMapped attribute should map to the same 
> partitions
>         /// for the same field value.
>         /// </summary>
>         [Test]
>         public void TestCustomAffinity()
>         {
>             IIgnite g = Ignition.GetIgnite("grid-0");
>             var cacheCfg = new CacheConfiguration("mycache")
>             {
>                 // Without QueryEntities tests passes.
>                 QueryEntities = new List<QueryEntity>()
>                 {
>                     new QueryEntity(typeof(MyKey), typeof(int))
>                 }
>             };
>             g.GetOrCreateCache<MyKey, int>(cacheCfg);
>             var key1 = new MyKey {Data = "data1", AffinityKey = 1};
>             var key2 = new MyKey {Data = "data2", AffinityKey = 1};
>             ICacheAffinity aff = g.GetAffinity(cacheCfg.Name);
>             Assert.AreEqual(aff.GetPartition(key1), aff.GetPartition(key2));
>         }
>         public class MyKey
>         {
>             [QuerySqlField]
>             public string Data { get; set; }
>             [AffinityKeyMapped]
>             public long AffinityKey { get; set; }
>         }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to