[ https://issues.apache.org/jira/browse/IGNITE-19359?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17723873#comment-17723873 ]
Pavel Tupitsyn commented on IGNITE-19359: ----------------------------------------- Merged to master: bdfc379fe925782d7ff581985389b8268a39a3d5 > .NET: Thin client: 'Affinity keys are not supported exception' on put > --------------------------------------------------------------------- > > Key: IGNITE-19359 > URL: https://issues.apache.org/jira/browse/IGNITE-19359 > Project: Ignite > Issue Type: Bug > Components: platforms, thin client > Affects Versions: 2.14 > Reporter: Pavel Tupitsyn > Assignee: Pavel Tupitsyn > Priority: Major > Labels: .NET > Fix For: 2.16 > > > Reproducer from > [StackOverflow|https://stackoverflow.com/questions/76099508/why-cant-i-add-data-with-an-affinitykey-into-an-apache-ignite-cache] > {code:C#} > using Apache.Ignite.Core; > using Apache.Ignite.Core.Cache.Affinity; > using Apache.Ignite.Core.Cache.Configuration; > using Apache.Ignite.Core.Cache.Query; > using Apache.Ignite.Core.Client; > using Apache.Ignite.Core.Client.Cache; > public record PERSONKEY( > [property:AffinityKeyMapped] [property: QuerySqlField(NotNull = true)] > long COMPANYID, > [property: QuerySqlField(NotNull = true)] long PERSONID); > public record PERSONVALUE( > [property: QuerySqlField(NotNull = true)] string FIRSTNAME, > [property: QuerySqlField(NotNull = true)] string LASTNAME); > internal class Program > { > public static void Main(string[] args) > { > var cfg = new IgniteClientConfiguration > { > Endpoints = new[] {"10.7.116.49:10800"}, > }; > using var client = Ignition.StartClient(cfg); > var schemaBuilder = client.GetOrCreateCache<int, int>(new > CacheClientConfiguration > { > Name = "RR", SqlSchema = "PUBLIC" > }); > schemaBuilder.Query(new SqlFieldsQuery( > $@"CREATE TABLE IF NOT EXISTS PERSON ( > COMPANYID BIGINT NOT NULL, > PERSONID BIGINT NOT NULL, > FIRSTNAME VARCHAR NOT NULL, > LASTNAME VARCHAR NOT NULL, > PRIMARY KEY(COMPANYID, PERSONID) > ) WITH > ""TEMPLATE=PARTITIONED,BACKUPS=1,AFFINITY_KEY=COMPANYID,CACHE_NAME=PERSON, > > KEY_TYPE={typeof(PERSONKEY).FullName},VALUE_TYPE={typeof(PERSONVALUE).FullName}""" > ) { Schema = "PUBLIC" }).GetAll(); > > var cache = client.GetCache<PERSONKEY, PERSONVALUE>("PERSON"); > > var key = new PERSONKEY(1, 2); > var value = new PERSONVALUE("JOHN", "SMITH"); > > // Throws an exception > // Apache.Ignite.Core.Common.IgniteException: Affinity keys are not > supported. > // Object 'PERSONKEY { COMPANYID = 1, PERSONID = 2 }' has an affinity > key. > cache.Put(key, value); > > // Does not throw an exception > cache.PutAll(new[]{KeyValuePair.Create(key, value)}); > > var people = cache.Query(new SqlFieldsQuery("SELECT * FROM PERSON > WHERE COMPANYID = ?", key.COMPANYID)).GetAll(); > // Correctly prints "1 2 JOHN SMITH" > Console.WriteLine(string.Join("\n", people.Select(p => $"{p[0]} > {p[1]} {p[2]} {p[3]}"))); > } > } > {code} > *Exception:* > {code} > Apache.Ignite.Core.Common.IgniteException: Affinity keys are not supported. > Object 'PERSONKEY { COMPANYID = 1, PERSONID = 2 }' has an affinity key. > {code} > We should not throw an exception when partition can't be calculated. Instead, > log a warning and bypass partition awareness. -- This message was sent by Atlassian Jira (v8.20.10#820010)