Uploaded image for project: 'Ignite'
  1. Ignite
  2. IGNITE-19359

.NET: Thin client: 'Affinity keys are not supported exception' on put

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.14
    • 2.16
    • platforms, thin client
    • .NET: Thin client: Added partition awareness support for types with affinity key.
    • Release Notes Required

    Description

      Reproducer from StackOverflow

      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]}")));
          }
      }
      

      Exception:

      Apache.Ignite.Core.Common.IgniteException: Affinity keys are not supported. Object 'PERSONKEY { COMPANYID = 1, PERSONID = 2 }' has an affinity key.
      

      We should not throw an exception when partition can't be calculated. Instead, log a warning and bypass partition awareness.

      Attachments

        Activity

          People

            ptupitsyn Pavel Tupitsyn
            ptupitsyn Pavel Tupitsyn
            Igor Sapego Igor Sapego
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: