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

Support for abstract configuration

    XMLWordPrintableJSON

Details

    • Task
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 3.0.0-beta1
    • None

    Description

      NOTE

      Description may not be complete.

      Problem
      We need the ability to create a basic configuration schema so that we can define a common configuration schema and inherit from it with additional configuration added.

      Let's look at an example:

      We need to create two configuration schemes for the PageMemory based storage engine, they should have a common property "page size in bytes" and then they should be different, let's sketch an example scheme.

      public class BasePageMemoryStorageEngineConfigurationSchema {
          @Value(hasDefault = true)
          public int pageSize = 16 * 1024;
      }
      
      @ConfigurationRoot(rootName = "in-memory-page-memory", type = DISTRIBUTED) 
      public class VolatilePageMemoryStorageEngineConfigurationSchema extends BasePageMemoryStorageEngineConfigurationSchema{
          @ConfigValue
          public VolatilePageMemoryDataRegionConfigurationSchema defaultRegion;
      
          @NamedConfigValue
          public VolatilePageMemoryDataRegionConfigurationSchema regions;
      }
      
      @ConfigurationRoot(rootName = "persistent-page-memory", type = DISTRIBUTED)
      public class PersistentPageMemoryStorageEngineConfigurationSchema extends BasePageMemoryStorageEngineConfigurationSchema{
          @ConfigValue
          public PersistentPageMemoryDataRegionConfigurationSchema defaultRegion;
      
          @NamedConfigValue
          public PersistentPageMemoryDataRegionConfigurationSchema regions;
      
          @ConfigValue
          public PageMemoryCheckpointConfigurationSchema checkpoint;
      }

      How can we implement this at the moment:

      • internal extension of the configuration: then the user will not be able to see and change it - not suitable;
      • polymorphic configuration:
        • by design, we cannot create root config schemas for polymorphic config or instances;
        • by design, we can change the type of polymorphic configuration to any instance, we do not fix its type, which does not suit us;
        • by design, we cannot expose a polymorphic instance as a configuration schema property;
        • hocon will display the type of polymorphic configuration, which is not necessary in this case and will look a little strange.

      The possible options do not suit us, so I propose to add another solution.

      Proposal

      Add an abstract configuration schema from which we can inherit, add properties, but only its heirs could be used as properties of other configurations schemas or configuration roots. Unlike a polymorphic configuration, it will not store and display the type in hocon, and the type cannot be changed. 
      The abstract configuration schema from which will be inherited will contain the annotation @AbstractConfiguration, and any successor must extend it and contain @Config or @ConfigurationRoot, consider examples:

      @AbstractConfiguration
      public class BasePageMemoryStorageEngineConfigurationSchema {
          @Value(hasDefault = true)
          public int pageSize = 16 * 1024;
      }
      
      @ConfigurationRoot(rootName = "in-memory-page-memory", type = DISTRIBUTED) 
      public class VolatilePageMemoryStorageEngineConfigurationSchema extends BasePageMemoryStorageEngineConfigurationSchema{
          @ConfigValue
          public VolatilePageMemoryDataRegionConfigurationSchema defaultRegion;
      
          @NamedConfigValue
          public VolatilePageMemoryDataRegionConfigurationSchema regions;
      }
      
      @Config
      public class PersistentPageMemoryStorageEngineConfigurationSchema extends BasePageMemoryStorageEngineConfigurationSchema{
          @ConfigValue
          public PersistentPageMemoryDataRegionConfigurationSchema defaultRegion;
      
          @NamedConfigValue
          public PersistentPageMemoryDataRegionConfigurationSchema regions;
      
          @ConfigValue
          public PageMemoryCheckpointConfigurationSchema checkpoint;
      }

      Implementation notes

      1. Add annotation org.apache.ignite.configuration.annotation.AbstractConfiguration;
      2. Add processing to org.apache.ignite.internal.configuration.processor.Processor;
      3. Add processing to org.apache.ignite.internal.configuration.asm.ConfigurationAsmGenerator;
      4. Cover with tests.

      Further development

      • Consider the possibility and necessity of crossing with the annotation InternalConfiguration and PolymorphicConfig in a separate ticket, at the moment they cannot be used together in the same class (for simplicity).

      Attachments

        Issue Links

          Activity

            People

              ktkalenko@gridgain.com Kirill Tkalenko
              ktkalenko@gridgain.com Kirill Tkalenko
              Aleksandr Polovtsev Aleksandr Polovtsev
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 10h 40m
                  10h 40m