IGNITE-7288 Thin client: allow partial cache configuration
authorPavel Tupitsyn <ptupitsyn@apache.org>
Thu, 28 Dec 2017 09:58:11 +0000 (12:58 +0300)
committerPavel Tupitsyn <ptupitsyn@apache.org>
Thu, 28 Dec 2017 09:58:11 +0000 (12:58 +0300)
This closes #3286

modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cache/ClientCacheConfigurationSerializer.java
modules/platforms/dotnet/Apache.Ignite.Core.Tests.DotNetCore/Apache.Ignite.Core.Tests.DotNetCore.csproj
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/ClientCacheConfigurationTest.cs
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/CreateCacheTest.cs
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/ClientTestBase.cs
modules/platforms/dotnet/Apache.Ignite.Core/Client/Cache/CacheClientConfiguration.cs
modules/platforms/dotnet/Apache.Ignite.Core/Configuration/ClientConnectorConfiguration.cs
modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/Cache/ClientCacheConfigurationSerializer.cs

index 0f28b81..839720b 100644 (file)
@@ -18,7 +18,6 @@
 package org.apache.ignite.internal.processors.platform.client.cache;
 
 import org.apache.ignite.binary.BinaryRawReader;
-import org.apache.ignite.binary.BinaryRawWriter;
 import org.apache.ignite.cache.CacheAtomicityMode;
 import org.apache.ignite.cache.CacheKeyConfiguration;
 import org.apache.ignite.cache.CacheMode;
@@ -40,6 +39,97 @@ import static org.apache.ignite.internal.processors.platform.utils.PlatformConfi
  * Cache configuration serializer.
  */
 public class ClientCacheConfigurationSerializer {
+    /** Name. */
+    private static final short NAME = 0;
+
+    /** Common properties. */
+    private static final short CACHE_MODE = 1;
+
+    /** */
+    private static final short ATOMICITY_MODE = 2;
+
+    /** */
+    private static final short BACKUPS = 3;
+
+    /** */
+    private static final short WRITE_SYNCHRONIZATION_MODE = 4;
+
+    /** */
+    private static final short COPY_ON_READ = 5;
+
+    /** */
+    private static final short READ_FROM_BACKUP = 6;
+
+    /** Memory settings. */
+    private static final short DATA_REGION_NAME = 100;
+
+    /** */
+    private static final short ONHEAP_CACHE_ENABLED = 101;
+
+    /** SQL. */
+    private static final short QUERY_ENTITIES = 200;
+
+    /** */
+    private static final short QUERY_PARALLELISM = 201;
+
+    /** */
+    private static final short QUERY_DETAIL_METRICS_SIZE = 202;
+
+    /** */
+    private static final short SQL_SCHEMA = 203;
+
+    /** */
+    private static final short SQL_INDEX_MAX_INLINE_SIZE = 204;
+
+    /** */
+    private static final short SQL_ESCAPE_ALL = 205;
+
+    /** */
+    private static final short MAX_QUERY_ITERATORS_COUNT = 206;
+
+    /** Rebalance. */
+    private static final short REBALANCE_MODE = 300;
+
+    /** */
+    private static final short REBALANCE_DELAY = 301;
+
+    /** */
+    private static final short REBALANCE_TIMEOUT = 302;
+
+    /** */
+    private static final short REBALANCE_BATCH_SIZE = 303;
+
+    /** */
+    private static final short REBALANCE_BATCHES_PREFETCH_COUNT = 304;
+
+    /** */
+    private static final short REBALANCE_ORDER = 305;
+
+    /** */
+    private static final short REBALANCE_THROTTLE = 306;
+
+    /** Advanced. */
+    private static final short GROUP_NAME = 400;
+
+    /** */
+    private static final short KEY_CONFIGURATION = 401;
+
+    /** */
+    private static final short DEFAULT_LOCK_TIMEOUT = 402;
+
+    /** */
+    private static final short MAX_CONCURRENT_ASYNC_OPERATIONS = 403;
+
+    /** */
+    private static final short PARTITION_LOSS_POLICY = 404;
+
+    /** */
+    private static final short EAGER_TTL = 405;
+
+    /** */
+    private static final short STATISTICS_ENABLED = 406;
+
+
     /**
      * Writes the cache configuration.
      * @param writer Writer.
@@ -60,7 +150,6 @@ public class ClientCacheConfigurationSerializer {
         writer.writeBoolean(cfg.isEagerTtl());
         writer.writeBoolean(cfg.isStatisticsEnabled());
         writer.writeString(cfg.getGroupName());
-        writer.writeBoolean(cfg.isInvalidate());
         writer.writeLong(cfg.getDefaultLockTimeout());
         writer.writeInt(cfg.getMaxConcurrentAsyncOperations());
         writer.writeInt(cfg.getMaxQueryIteratorsCount());
@@ -119,60 +208,153 @@ public class ClientCacheConfigurationSerializer {
     static CacheConfiguration read(BinaryRawReader reader) {
         reader.readInt();  // Skip length.
 
-        CacheConfiguration cfg = new CacheConfiguration()
-                .setAtomicityMode(CacheAtomicityMode.fromOrdinal(reader.readInt()))
-                .setBackups(reader.readInt())
-                .setCacheMode(CacheMode.fromOrdinal(reader.readInt()))
-                .setCopyOnRead(reader.readBoolean())
-                .setDataRegionName(reader.readString())
-                .setEagerTtl(reader.readBoolean())
-                .setStatisticsEnabled(reader.readBoolean())
-                .setGroupName(reader.readString())
-                .setInvalidate(reader.readBoolean())
-                .setDefaultLockTimeout(reader.readLong())
-                .setMaxConcurrentAsyncOperations(reader.readInt())
-                .setMaxQueryIteratorsCount(reader.readInt())
-                .setName(reader.readString())
-                .setOnheapCacheEnabled(reader.readBoolean())
-                .setPartitionLossPolicy(PartitionLossPolicy.fromOrdinal((byte)reader.readInt()))
-                .setQueryDetailMetricsSize(reader.readInt())
-                .setQueryParallelism(reader.readInt())
-                .setReadFromBackup(reader.readBoolean())
-                .setRebalanceBatchSize(reader.readInt())
-                .setRebalanceBatchesPrefetchCount(reader.readLong())
-                .setRebalanceDelay(reader.readLong())
-                .setRebalanceMode(CacheRebalanceMode.fromOrdinal(reader.readInt()))
-                .setRebalanceOrder(reader.readInt())
-                .setRebalanceThrottle(reader.readLong())
-                .setRebalanceTimeout(reader.readLong())
-                .setSqlEscapeAll(reader.readBoolean())
-                .setSqlIndexMaxInlineSize(reader.readInt())
-                .setSqlSchema(reader.readString())
-                .setWriteSynchronizationMode(CacheWriteSynchronizationMode.fromOrdinal(reader.readInt()));
-
-        // Key configuration.
-        int keyCnt = reader.readInt();
-
-        if (keyCnt > 0) {
-            CacheKeyConfiguration[] keys = new CacheKeyConfiguration[keyCnt];
-
-            for (int i = 0; i < keyCnt; i++) {
-                keys[i] = new CacheKeyConfiguration(reader.readString(), reader.readString());
-            }
+        short propCnt = reader.readShort();
 
-            cfg.setKeyConfiguration(keys);
-        }
+        CacheConfiguration cfg = new CacheConfiguration();
+
+        for (int i = 0; i < propCnt; i++) {
+            short code = reader.readShort();
 
-        // Query entities.
-        int qryEntCnt = reader.readInt();
+            switch (code) {
+                case ATOMICITY_MODE:
+                    cfg.setAtomicityMode(CacheAtomicityMode.fromOrdinal(reader.readInt()));
+                    break;
 
-        if (qryEntCnt > 0) {
-            Collection<QueryEntity> entities = new ArrayList<>(qryEntCnt);
+                case BACKUPS:
+                    cfg.setBackups(reader.readInt());
+                    break;
 
-            for (int i = 0; i < qryEntCnt; i++)
-                entities.add(readQueryEntity(reader));
+                case CACHE_MODE:
+                    cfg.setCacheMode(CacheMode.fromOrdinal(reader.readInt()));
+                    break;
 
-            cfg.setQueryEntities(entities);
+                case COPY_ON_READ:
+                    cfg.setCopyOnRead(reader.readBoolean());
+                    break;
+
+                case DATA_REGION_NAME:
+                    cfg.setDataRegionName(reader.readString());
+                    break;
+
+                case EAGER_TTL:
+                    cfg.setEagerTtl(reader.readBoolean());
+                    break;
+
+                case STATISTICS_ENABLED:
+                    cfg.setStatisticsEnabled(reader.readBoolean());
+                    break;
+
+                case GROUP_NAME:
+                    cfg.setGroupName(reader.readString());
+                    break;
+
+                case DEFAULT_LOCK_TIMEOUT:
+                    cfg.setDefaultLockTimeout(reader.readLong());
+                    break;
+
+                case MAX_CONCURRENT_ASYNC_OPERATIONS:
+                    cfg.setMaxConcurrentAsyncOperations(reader.readInt());
+                    break;
+
+                case MAX_QUERY_ITERATORS_COUNT:
+                    cfg.setMaxQueryIteratorsCount(reader.readInt());
+                    break;
+
+                case NAME:
+                    cfg.setName(reader.readString());
+                    break;
+
+                case ONHEAP_CACHE_ENABLED:
+                    cfg.setOnheapCacheEnabled(reader.readBoolean());
+                    break;
+
+                case PARTITION_LOSS_POLICY:
+                    cfg.setPartitionLossPolicy(PartitionLossPolicy.fromOrdinal((byte) reader.readInt()));
+                    break;
+
+                case QUERY_DETAIL_METRICS_SIZE:
+                    cfg.setQueryDetailMetricsSize(reader.readInt());
+                    break;
+
+                case QUERY_PARALLELISM:
+                    cfg.setQueryParallelism(reader.readInt());
+                    break;
+
+                case READ_FROM_BACKUP:
+                    cfg.setReadFromBackup(reader.readBoolean());
+                    break;
+
+                case REBALANCE_BATCH_SIZE:
+                    cfg.setRebalanceBatchSize(reader.readInt());
+                    break;
+
+                case REBALANCE_BATCHES_PREFETCH_COUNT:
+                    cfg.setRebalanceBatchesPrefetchCount(reader.readLong());
+                    break;
+
+                case REBALANCE_DELAY:
+                    cfg.setRebalanceDelay(reader.readLong());
+                    break;
+
+                case REBALANCE_MODE:
+                    cfg.setRebalanceMode(CacheRebalanceMode.fromOrdinal(reader.readInt()));
+                    break;
+
+                case REBALANCE_ORDER:
+                    cfg.setRebalanceOrder(reader.readInt());
+                    break;
+
+                case REBALANCE_THROTTLE:
+                    cfg.setRebalanceThrottle(reader.readLong());
+                    break;
+
+                case REBALANCE_TIMEOUT:
+                    cfg.setRebalanceTimeout(reader.readLong());
+                    break;
+
+                case SQL_ESCAPE_ALL:
+                    cfg.setSqlEscapeAll(reader.readBoolean());
+                    break;
+
+                case SQL_INDEX_MAX_INLINE_SIZE:
+                    cfg.setSqlIndexMaxInlineSize(reader.readInt());
+                    break;
+
+                case SQL_SCHEMA:
+                    cfg.setSqlSchema(reader.readString());
+                    break;
+
+                case WRITE_SYNCHRONIZATION_MODE:
+                    cfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.fromOrdinal(reader.readInt()));
+                    break;
+
+                case KEY_CONFIGURATION:
+                    int keyCnt = reader.readInt();
+
+                    if (keyCnt > 0) {
+                        CacheKeyConfiguration[] keys = new CacheKeyConfiguration[keyCnt];
+
+                        for (int j = 0; j < keyCnt; j++) {
+                            keys[j] = new CacheKeyConfiguration(reader.readString(), reader.readString());
+                        }
+
+                        cfg.setKeyConfiguration(keys);
+                    }
+                    break;
+
+                case QUERY_ENTITIES:
+                    int qryEntCnt = reader.readInt();
+
+                    if (qryEntCnt > 0) {
+                        Collection<QueryEntity> entities = new ArrayList<>(qryEntCnt);
+
+                        for (int j = 0; j < qryEntCnt; j++)
+                            entities.add(readQueryEntity(reader));
+
+                        cfg.setQueryEntities(entities);
+                    }
+                    break;
+            }
         }
 
         return cfg;
index f1ccb06..d660b62 100644 (file)
@@ -53,6 +53,7 @@
     <Compile Include="..\Apache.Ignite.Core.Tests\Cache\BinarizableTestException.cs" Link="Cache\BinarizableTestException.cs" />
     <Compile Include="..\Apache.Ignite.Core.Tests\Cache\CacheAbstractTest.cs" Link="Cache\CacheAbstractTest.cs" />
     <Compile Include="..\Apache.Ignite.Core.Tests\Cache\CacheAbstractTransactionalTest.cs" Link="Cache\CacheAbstractTransactionalTest.cs" />
+    <Compile Include="..\Apache.Ignite.Core.Tests\Cache\CacheConfigurationTest.cs" Link="Cache\CacheConfigurationTest.cs" />
     <Compile Include="..\Apache.Ignite.Core.Tests\Cache\CachePartitionedTest.cs" Link="Cache\CachePartitionedTest.cs" />
     <Compile Include="..\Apache.Ignite.Core.Tests\Cache\CacheTestAsyncWrapper.cs" Link="Cache\CacheTestAsyncWrapper.cs" />
     <Compile Include="..\Apache.Ignite.Core.Tests\Cache\CacheTestKey.cs" Link="Cache\CacheTestKey.cs" />
@@ -86,6 +87,7 @@
     <Compile Include="..\Apache.Ignite.Core.Tests\Client\Cache\CacheTestAsync.cs" Link="ThinClient\Cache\CacheTestAsync.cs" />
     <Compile Include="..\Apache.Ignite.Core.Tests\Client\Cache\CacheClientAsyncWrapper.cs" Link="ThinClient\Cache\CacheClientAsyncWrapper.cs" />
     <Compile Include="..\Apache.Ignite.Core.Tests\Client\Cache\CacheTestKeepBinary.cs" Link="ThinClient\Cache\CacheTestKeepBinary.cs" />
+    <Compile Include="..\Apache.Ignite.Core.Tests\Client\Cache\CreateCacheTest.cs" Link="ThinClient\Cache\CreateCacheTest.cs" />
     <Compile Include="..\Apache.Ignite.Core.Tests\Client\Cache\EmptyObject.cs" Link="ThinClient\Cache\EmptyObject.cs" />
     <Compile Include="..\Apache.Ignite.Core.Tests\Client\Cache\Person.cs" Link="ThinClient\Cache\Person.cs" />
     <Compile Include="..\Apache.Ignite.Core.Tests\Client\Cache\ScanQueryTest.cs" Link="ThinClient\Cache\ScanQueryTest.cs" />
     <Content Include="..\Apache.Ignite.Core.Tests\Config\cache-binarizables.xml" Link="Config\cache-binarizables.xml">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </Content>
+    <Content Include="..\Apache.Ignite.Core.Tests\Config\cache-default.xml" Link="Config\cache-default.xml">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </Content>
     <Content Include="..\Apache.Ignite.Core.Tests\Config\cache-query.xml" Link="Config\cache-query.xml">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </Content>
index 256c245..536cb18 100644 (file)
@@ -19,6 +19,7 @@ namespace Apache.Ignite.Core.Tests.Cache
 {
     using System;
     using System.Collections.Generic;
+    using System.IO;
     using System.Linq;
     using Apache.Ignite.Core.Binary;
     using Apache.Ignite.Core.Cache.Affinity;
@@ -92,7 +93,7 @@ namespace Apache.Ignite.Core.Tests.Cache
                 },
 #pragma warning restore 618
                 DataStorageConfiguration = null,
-                SpringConfigUrl = "Config\\cache-default.xml"
+                SpringConfigUrl = Path.Combine("Config", "cache-default.xml")
             };
 
             _ignite = Ignition.Start(cfg);
index 41770b8..903b038 100644 (file)
@@ -112,11 +112,11 @@ namespace Apache.Ignite.Core.Tests.Client.Cache
             var clientCfg = new CacheClientConfiguration(
                 CacheConfigurationTest.GetCustomCacheConfiguration("z"), true);
 
-            AssertClientConfigsAreEqual(clientCfg, new CacheClientConfiguration(clientCfg));
+            ClientTestBase.AssertClientConfigsAreEqual(clientCfg, new CacheClientConfiguration(clientCfg));
 
             // Convert to server cfg.
             var serverCfg = clientCfg.ToCacheConfiguration();
-            AssertClientConfigsAreEqual(clientCfg, new CacheClientConfiguration(serverCfg, false));
+            ClientTestBase.AssertClientConfigsAreEqual(clientCfg, new CacheClientConfiguration(serverCfg, false));
         }
 
         /// <summary>
@@ -129,14 +129,14 @@ namespace Apache.Ignite.Core.Tests.Client.Cache
             var clientCfg = new CacheClientConfiguration();
             var defCfg = new CacheClientConfiguration(new CacheConfiguration(), false);
 
-            AssertClientConfigsAreEqual(defCfg, clientCfg);
+            ClientTestBase.AssertClientConfigsAreEqual(defCfg, clientCfg);
 
             // Name.
             clientCfg = new CacheClientConfiguration("foo");
             Assert.AreEqual("foo", clientCfg.Name);
 
             clientCfg.Name = null;
-            AssertClientConfigsAreEqual(defCfg, clientCfg);
+            ClientTestBase.AssertClientConfigsAreEqual(defCfg, clientCfg);
 
             // Query entities.
             clientCfg = new CacheClientConfiguration("bar", typeof(QueryPerson));
@@ -168,24 +168,7 @@ namespace Apache.Ignite.Core.Tests.Client.Cache
         {
             var clientCfg = new CacheClientConfiguration(cfg, false);
 
-            AssertClientConfigsAreEqual(clientCfg, SerializeDeserialize(clientCfg));
-        }
-
-        /// <summary>
-        /// Asserts the client configs are equal.
-        /// </summary>
-        public static void AssertClientConfigsAreEqual(CacheClientConfiguration cfg, CacheClientConfiguration cfg2)
-        {
-            if (cfg2.QueryEntities != null)
-            {
-                // Remove identical aliases which are added during config roundtrip.
-                foreach (var e in cfg2.QueryEntities)
-                {
-                    e.Aliases = e.Aliases.Where(x => x.Alias != x.FullName).ToArray();
-                }
-            }
-
-            AssertExtensions.ReflectionEqual(cfg, cfg2);
+            ClientTestBase.AssertClientConfigsAreEqual(clientCfg, SerializeDeserialize(clientCfg));
         }
 
         /// <summary>
@@ -195,7 +178,7 @@ namespace Apache.Ignite.Core.Tests.Client.Cache
         {
             using (var stream = new BinaryHeapStream(128))
             {
-                ClientCacheConfigurationSerializer.Write(stream, cfg);
+                ClientCacheConfigurationSerializer.Write(stream, cfg, true);
                 stream.Seek(0, SeekOrigin.Begin);
                 return new CacheClientConfiguration(stream);
             }
index 94ae6cd..92804be 100644 (file)
@@ -22,6 +22,10 @@ namespace Apache.Ignite.Core.Tests.Client.Cache
     using Apache.Ignite.Core.Client;
     using Apache.Ignite.Core.Client.Cache;
     using Apache.Ignite.Core.Configuration;
+#if !NETCOREAPP2_0
+    using Apache.Ignite.Core.Impl.Client.Cache;
+    using Apache.Ignite.Core.Impl.Client;
+#endif
     using Apache.Ignite.Core.Tests.Cache;
     using NUnit.Framework;
 
@@ -145,9 +149,43 @@ namespace Apache.Ignite.Core.Tests.Client.Cache
             cfg = GetFullCacheConfiguration("b");
 
             cache = Client.CreateCache<int, int>(cfg);
-            ClientCacheConfigurationTest.AssertClientConfigsAreEqual(cfg, cache.GetConfiguration());
+            AssertClientConfigsAreEqual(cfg, cache.GetConfiguration());
         }
 
+#if !NETCOREAPP2_0
+        /// <summary>
+        /// Tests cache creation from partial configuration.
+        /// </summary>
+        [Test]
+        public void TestCreateFromPartialConfiguration()
+        {
+            // Default config.
+            var cfg = new CacheClientConfiguration("a") {Backups = 7};
+            var client = (IgniteClient) Client;
+
+            // Create cache directly through a socket with only some config properties provided.
+            client.Socket.DoOutInOp<object>(ClientOp.CacheCreateWithConfiguration, s =>
+            {
+                var w = client.Marshaller.StartMarshal(s);
+
+                w.WriteInt(2 + 2 + 6 + 2 + 4);  // config length in bytes.
+
+                w.WriteShort(2);  // 2 properties.
+                
+                w.WriteShort(3);  // backups opcode.
+                w.WriteInt(cfg.Backups);
+
+                w.WriteShort(0);  // name opcode.
+                w.WriteString(cfg.Name);
+
+            }, null);
+            
+            var cache = new CacheClient<int, int>(client, cfg.Name);
+
+            AssertExtensions.ReflectionEqual(cfg, cache.GetConfiguration());
+        }
+#endif
+
         /// <summary>
         /// Tests cache creation from configuration.
         /// </summary>
@@ -168,7 +206,7 @@ namespace Apache.Ignite.Core.Tests.Client.Cache
             cfg = GetFullCacheConfiguration("b");
 
             cache = Client.GetOrCreateCache<int, int>(cfg);
-            ClientCacheConfigurationTest.AssertClientConfigsAreEqual(cfg, cache.GetConfiguration());
+            AssertClientConfigsAreEqual(cfg, cache.GetConfiguration());
         }
 
         /// <summary>
index 78d571b..9fea52c 100644 (file)
@@ -18,6 +18,7 @@
 namespace Apache.Ignite.Core.Tests.Client
 {
     using System;
+    using System.Linq;
     using System.Net;
     using Apache.Ignite.Core.Binary;
     using Apache.Ignite.Core.Cache;
@@ -190,5 +191,22 @@ namespace Apache.Ignite.Core.Tests.Client
         {
             return ToBinary(new Person(id) { DateTime = DateTime.MinValue.ToUniversalTime() });
         }
+
+        /// <summary>
+        /// Asserts the client configs are equal.
+        /// </summary>
+        public static void AssertClientConfigsAreEqual(CacheClientConfiguration cfg, CacheClientConfiguration cfg2)
+        {
+            if (cfg2.QueryEntities != null)
+            {
+                // Remove identical aliases which are added during config roundtrip.
+                foreach (var e in cfg2.QueryEntities)
+                {
+                    e.Aliases = e.Aliases.Where(x => x.Alias != x.FullName).ToArray();
+                }
+            }
+
+            AssertExtensions.ReflectionEqual(cfg, cfg2);
+        }
     }
 }
index 21ca247..1c1874f 100644 (file)
@@ -65,7 +65,6 @@ namespace Apache.Ignite.Core.Client.Cache
             CopyOnRead = CacheConfiguration.DefaultCopyOnRead;
             WriteSynchronizationMode = CacheConfiguration.DefaultWriteSynchronizationMode;
             EagerTtl = CacheConfiguration.DefaultEagerTtl;
-            Invalidate = CacheConfiguration.DefaultInvalidate;
             LockTimeout = CacheConfiguration.DefaultLockTimeout;
             MaxConcurrentAsyncOperations = CacheConfiguration.DefaultMaxConcurrentAsyncOperations;
             ReadFromBackup = CacheConfiguration.DefaultReadFromBackup;
@@ -116,7 +115,7 @@ namespace Apache.Ignite.Core.Client.Cache
             {
                 using (var stream = IgniteManager.Memory.Allocate().GetStream())
                 {
-                    ClientCacheConfigurationSerializer.Write(stream, other);
+                    ClientCacheConfigurationSerializer.Write(stream, other, true);
 
                     stream.SynchronizeOutput();
                     stream.Seek(0, SeekOrigin.Begin);
@@ -240,12 +239,6 @@ namespace Apache.Ignite.Core.Client.Cache
         public TimeSpan LockTimeout { get; set; }
 
         /// <summary>
-        /// Invalidation flag. If true, values will be invalidated (nullified) upon commit in near cache.
-        /// </summary>
-        [DefaultValue(CacheConfiguration.DefaultInvalidate)]
-        public bool Invalidate { get; set; }
-
-        /// <summary>
         /// Gets or sets cache rebalance mode.
         /// </summary>
         [DefaultValue(CacheConfiguration.DefaultRebalanceMode)]
index a5b2403..aff2716 100644 (file)
@@ -61,7 +61,7 @@ namespace Apache.Ignite.Core.Configuration
         /// <summary>
         /// Default idle timeout.
         /// </summary>
-        public static TimeSpan DefaultIdleTimeout = TimeSpan.Zero;
+        public static readonly TimeSpan DefaultIdleTimeout = TimeSpan.Zero;
 
         /// <summary>
         /// Initializes a new instance of the <see cref="ClientConnectorConfiguration"/> class.
index 160d09f..b11b175 100644 (file)
@@ -32,6 +32,55 @@ namespace Apache.Ignite.Core.Impl.Client.Cache
     /// </summary>
     internal static class ClientCacheConfigurationSerializer
     {
+        /** Config property opcodes. */
+        private enum Op : short
+        {
+            // Name is required.
+            Name = 0,
+
+            // Most common properties.
+            CacheMode = 1,
+            AtomicityMode = 2,
+            Backups = 3,
+            WriteSynchronizationMode = 4,
+            CopyOnRead = 5,
+            ReadFromBackup = 6,
+
+            // Memory settings.
+            DataRegionName = 100,
+            OnheapCacheEnabled = 101,
+
+            // SQL.
+            QueryEntities = 200,
+            QueryParallelism = 201,
+            QueryDetailMetricsSize = 202,
+            SqlSchema = 203,
+            SqlIndexMaxInlineSize = 204,
+            SqlEscapeAll = 205,
+            MaxQueryIteratorsCount = 206,
+
+            // Rebalance.
+            RebalanceMode = 300,
+            RebalanceDelay = 301,
+            RebalanceTimeout = 302,
+            RebalanceBatchSize = 303,
+            RebalanceBatchesPrefetchCount = 304,
+            RebalanceOrder = 305,
+            RebalanceThrottle = 306,
+
+            // Advanced.
+            GroupName = 400,
+            KeyConfiguration = 401,
+            DefaultLockTimeout = 402,
+            MaxConcurrentAsyncOperations = 403,
+            PartitionLossPolicy = 404,
+            EagerTtl = 405, 
+            StatisticsEnabled = 406
+        }
+
+        /** Property count. */
+        private static readonly short PropertyCount = (short) Enum.GetValues(typeof(Op)).Length;
+        
         /// <summary>
         /// Copies one cache configuration to another.
         /// </summary>
@@ -48,7 +97,6 @@ namespace Apache.Ignite.Core.Impl.Client.Cache
             to.EagerTtl = from.EagerTtl;
             to.EnableStatistics = from.EnableStatistics;
             to.GroupName = from.GroupName;
-            to.Invalidate = from.Invalidate;
             to.LockTimeout = from.LockTimeout;
             to.MaxConcurrentAsyncOperations = from.MaxConcurrentAsyncOperations;
             to.MaxQueryIteratorsCount = from.MaxQueryIteratorsCount;
@@ -119,7 +167,6 @@ namespace Apache.Ignite.Core.Impl.Client.Cache
             to.EagerTtl = from.EagerTtl;
             to.EnableStatistics = from.EnableStatistics;
             to.GroupName = from.GroupName;
-            to.Invalidate = from.Invalidate;
             to.LockTimeout = from.LockTimeout;
             to.MaxConcurrentAsyncOperations = from.MaxConcurrentAsyncOperations;
             to.MaxQueryIteratorsCount = from.MaxQueryIteratorsCount;
@@ -148,7 +195,7 @@ namespace Apache.Ignite.Core.Impl.Client.Cache
         /// <summary>
         /// Writes the specified config.
         /// </summary>
-        public static void Write(IBinaryStream stream, CacheClientConfiguration cfg)
+        public static void Write(IBinaryStream stream, CacheClientConfiguration cfg, bool skipCodes = false)
         {
             Debug.Assert(stream != null);
             Debug.Assert(cfg != null);
@@ -158,43 +205,110 @@ namespace Apache.Ignite.Core.Impl.Client.Cache
             var pos = writer.Stream.Position;
             writer.WriteInt(0);  // Reserve for length.
 
+            if (!skipCodes)
+            {
+                writer.WriteShort(PropertyCount); // Property count.
+            }
+
+            var code = skipCodes
+                ? (Action<Op>) (o => { })
+                : o => writer.WriteShort((short) o);
+
+            code(Op.AtomicityMode);
             writer.WriteInt((int)cfg.AtomicityMode);
+            
+            code(Op.Backups);
             writer.WriteInt(cfg.Backups);
+            
+            code(Op.CacheMode);
             writer.WriteInt((int)cfg.CacheMode);
+            
+            code(Op.CopyOnRead);
             writer.WriteBoolean(cfg.CopyOnRead);
+            
+            code(Op.DataRegionName);
             writer.WriteString(cfg.DataRegionName);
+            
+            code(Op.EagerTtl);
             writer.WriteBoolean(cfg.EagerTtl);
+            
+            code(Op.StatisticsEnabled);
             writer.WriteBoolean(cfg.EnableStatistics);
+            
+            code(Op.GroupName);
             writer.WriteString(cfg.GroupName);
-            writer.WriteBoolean(cfg.Invalidate);
+            
+            code(Op.DefaultLockTimeout);
             writer.WriteTimeSpanAsLong(cfg.LockTimeout);
+
+            code(Op.MaxConcurrentAsyncOperations);
             writer.WriteInt(cfg.MaxConcurrentAsyncOperations);
+
+            code(Op.MaxQueryIteratorsCount);
             writer.WriteInt(cfg.MaxQueryIteratorsCount);
+
+            code(Op.Name);
             writer.WriteString(cfg.Name);
+            
+            code(Op.OnheapCacheEnabled);
             writer.WriteBoolean(cfg.OnheapCacheEnabled);
+            
+            code(Op.PartitionLossPolicy);
             writer.WriteInt((int)cfg.PartitionLossPolicy);
+            
+            code(Op.QueryDetailMetricsSize);
             writer.WriteInt(cfg.QueryDetailMetricsSize);
+            
+            code(Op.QueryParallelism);
             writer.WriteInt(cfg.QueryParallelism);
+            
+            code(Op.ReadFromBackup);
             writer.WriteBoolean(cfg.ReadFromBackup);
+            
+            code(Op.RebalanceBatchSize);
             writer.WriteInt(cfg.RebalanceBatchSize);
+            
+            code(Op.RebalanceBatchesPrefetchCount);
             writer.WriteLong(cfg.RebalanceBatchesPrefetchCount);
+            
+            code(Op.RebalanceDelay);
             writer.WriteTimeSpanAsLong(cfg.RebalanceDelay);
+            
+            code(Op.RebalanceMode);
             writer.WriteInt((int)cfg.RebalanceMode);
+            
+            code(Op.RebalanceOrder);
             writer.WriteInt(cfg.RebalanceOrder);
+            
+            code(Op.RebalanceThrottle);
             writer.WriteTimeSpanAsLong(cfg.RebalanceThrottle);
+            
+            code(Op.RebalanceTimeout);
             writer.WriteTimeSpanAsLong(cfg.RebalanceTimeout);
+            
+            code(Op.SqlEscapeAll);
             writer.WriteBoolean(cfg.SqlEscapeAll);
+            
+            code(Op.SqlIndexMaxInlineSize);
             writer.WriteInt(cfg.SqlIndexMaxInlineSize);
+            
+            code(Op.SqlSchema);
             writer.WriteString(cfg.SqlSchema);
+            
+            code(Op.WriteSynchronizationMode);
             writer.WriteInt((int)cfg.WriteSynchronizationMode);
 
+            code(Op.KeyConfiguration);
             writer.WriteCollectionRaw(cfg.KeyConfiguration);
+            
+            code(Op.QueryEntities);
             writer.WriteCollectionRaw(cfg.QueryEntities);
 
             // Write length (so that part of the config can be skipped).
             var len = writer.Stream.Position - pos - 4;
             writer.Stream.WriteInt(pos, len);
         }
+        
         /// <summary>
         /// Reads the config.
         /// </summary>
@@ -216,7 +330,6 @@ namespace Apache.Ignite.Core.Impl.Client.Cache
             cfg.EagerTtl = reader.ReadBoolean();
             cfg.EnableStatistics = reader.ReadBoolean();
             cfg.GroupName = reader.ReadString();
-            cfg.Invalidate = reader.ReadBoolean();
             cfg.LockTimeout = reader.ReadLongAsTimespan();
             cfg.MaxConcurrentAsyncOperations = reader.ReadInt();
             cfg.MaxQueryIteratorsCount = reader.ReadInt();