Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 163F1200CC2 for ; Wed, 5 Jul 2017 13:23:47 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 1506C162FDB; Wed, 5 Jul 2017 11:23:47 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 9BAF4162FD7 for ; Wed, 5 Jul 2017 13:23:45 +0200 (CEST) Received: (qmail 66508 invoked by uid 500); 5 Jul 2017 11:23:44 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 66432 invoked by uid 99); 5 Jul 2017 11:23:44 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Jul 2017 11:23:44 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1E90AF54E0; Wed, 5 Jul 2017 11:23:44 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.apache.org Date: Wed, 05 Jul 2017 11:23:53 -0000 Message-Id: In-Reply-To: <7145d01ca7e244358d65e4e6d64b02cc@git.apache.org> References: <7145d01ca7e244358d65e4e6d64b02cc@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [11/33] ignite git commit: IGNITE-5629 .NET: CacheConfiguration copy constructor archived-at: Wed, 05 Jul 2017 11:23:47 -0000 IGNITE-5629 .NET: CacheConfiguration copy constructor Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/b69f53e0 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/b69f53e0 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/b69f53e0 Branch: refs/heads/ignite-2.1.2-exchange Commit: b69f53e0ccf9d3da42a99d4423fb3d8bdd60a7bb Parents: 6c9d222 Author: Pavel Tupitsyn Authored: Tue Jul 4 17:42:31 2017 +0300 Committer: Pavel Tupitsyn Committed: Tue Jul 4 17:42:31 2017 +0300 ---------------------------------------------------------------------- .../utils/PlatformConfigurationUtils.java | 8 ++- .../Cache/CacheConfigurationTest.cs | 21 ++++++ .../Cache/Configuration/CacheConfiguration.cs | 75 ++++++++++++++++++-- .../Apache.Ignite.Core/IgniteConfiguration.cs | 7 +- 4 files changed, 99 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/b69f53e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java index 23106ba..92db41a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java @@ -885,8 +885,10 @@ public class PlatformConfigurationUtils { writer.writeInt(cnt); for (CachePluginConfiguration cfg : plugins) { - if (cfg instanceof PlatformCachePluginConfiguration) - writer.writeObject(((PlatformCachePluginConfiguration)cfg).nativeCfg()); + if (cfg instanceof PlatformCachePluginConfiguration) { + writer.writeBoolean(false); // Pure platform plugin. + writer.writeObject(((PlatformCachePluginConfiguration) cfg).nativeCfg()); + } } } } @@ -1317,6 +1319,8 @@ public class PlatformConfigurationUtils { private static void readCachePluginConfiguration(CacheConfiguration cfg, BinaryRawReader in) { int plugCfgFactoryId = in.readInt(); + in.readInt(); // skip size. + PlatformCachePluginConfigurationClosure plugCfg = cachePluginConfiguration(plugCfgFactoryId); plugCfg.apply(cfg, in); http://git-wip-us.apache.org/repos/asf/ignite/blob/b69f53e0/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs index 1f6dbcf..435e65f 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs @@ -190,6 +190,27 @@ namespace Apache.Ignite.Core.Tests.Cache } /// + /// Tests the copy constructor. + /// + [Test] + public void TestCopyConstructor() + { + foreach (var cfg in new[] + {new CacheConfiguration(), GetCustomCacheConfiguration(), GetCustomCacheConfiguration2()}) + { + // Check direct copy. + AssertConfigsAreEqual(cfg, cfg); + AssertConfigsAreEqual(cfg, new CacheConfiguration(cfg)); + + // Check copy via Ignite config. + var igniteCfg = new IgniteConfiguration {CacheConfiguration = new[] {cfg}}; + var igniteCfgCopy = new IgniteConfiguration(igniteCfg); + + AssertConfigsAreEqual(cfg, igniteCfgCopy.CacheConfiguration.Single()); + } + } + + /// /// Asserts the configuration is default. /// private static void AssertConfigIsDefault(CacheConfiguration cfg) http://git-wip-us.apache.org/repos/asf/ignite/blob/b69f53e0/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs index ec0ac40..f5a5179 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs @@ -25,6 +25,7 @@ namespace Apache.Ignite.Core.Cache.Configuration using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; + using System.IO; using System.Linq; using Apache.Ignite.Core.Binary; using Apache.Ignite.Core.Cache; @@ -34,11 +35,14 @@ namespace Apache.Ignite.Core.Cache.Configuration using Apache.Ignite.Core.Cache.Expiry; using Apache.Ignite.Core.Cache.Store; using Apache.Ignite.Core.Common; + using Apache.Ignite.Core.Impl; using Apache.Ignite.Core.Impl.Binary; using Apache.Ignite.Core.Impl.Cache.Affinity; using Apache.Ignite.Core.Impl.Cache.Expiry; using Apache.Ignite.Core.Log; using Apache.Ignite.Core.Plugin.Cache; + using BinaryReader = Apache.Ignite.Core.Impl.Binary.BinaryReader; + using BinaryWriter = Apache.Ignite.Core.Impl.Binary.BinaryWriter; /// /// Defines grid cache configuration. @@ -199,10 +203,43 @@ namespace Apache.Ignite.Core.Cache.Configuration } /// + /// Initializes a new instance of the class, + /// performing a deep copy of specified cache configuration. + /// + /// The other configuration to perfrom deep copy from. + public CacheConfiguration(CacheConfiguration other) + { + if (other != null) + { + using (var stream = IgniteManager.Memory.Allocate().GetStream()) + { + other.Write(BinaryUtils.Marshaller.StartMarshal(stream)); + + stream.SynchronizeOutput(); + stream.Seek(0, SeekOrigin.Begin); + + Read(BinaryUtils.Marshaller.StartUnmarshal(stream)); + } + + // Plugins should be copied directly. + PluginConfigurations = other.PluginConfigurations; + } + } + + /// /// Initializes a new instance of the class. /// /// The reader. - internal CacheConfiguration(IBinaryRawReader reader) + internal CacheConfiguration(BinaryReader reader) + { + Read(reader); + } + + /// + /// Reads data into this instance from the specified reader. + /// + /// The reader. + private void Read(BinaryReader reader) { // Make sure system marshaller is used. Debug.Assert(((BinaryReader) reader).Marshaller == BinaryUtils.Marshaller); @@ -244,7 +281,9 @@ namespace Apache.Ignite.Core.Cache.Configuration CacheStoreFactory = reader.ReadObject>(); var count = reader.ReadInt(); - QueryEntities = count == 0 ? null : Enumerable.Range(0, count).Select(x => new QueryEntity(reader)).ToList(); + QueryEntities = count == 0 + ? null + : Enumerable.Range(0, count).Select(x => new QueryEntity(reader)).ToList(); NearConfiguration = reader.ReadBoolean() ? new NearCacheConfiguration(reader) : null; @@ -253,19 +292,35 @@ namespace Apache.Ignite.Core.Cache.Configuration ExpiryPolicyFactory = ExpiryPolicySerializer.ReadPolicyFactory(reader); count = reader.ReadInt(); - PluginConfigurations = count == 0 - ? null - : Enumerable.Range(0, count).Select(x => reader.ReadObject()).ToList(); + + if (count > 0) + { + PluginConfigurations = new List(count); + for (int i = 0; i < count; i++) + { + if (reader.ReadBoolean()) + { + // FactoryId-based plugin: skip. + var size = reader.ReadInt(); + reader.Stream.Seek(size, SeekOrigin.Current); + } + else + { + // Pure .NET plugin. + PluginConfigurations.Add(reader.ReadObject()); + } + } + } } /// /// Writes this instance to the specified writer. /// /// The writer. - internal void Write(IBinaryRawWriter writer) + internal void Write(BinaryWriter writer) { // Make sure system marshaller is used. - Debug.Assert(((BinaryWriter) writer).Marshaller == BinaryUtils.Marshaller); + Debug.Assert(writer.Marshaller == BinaryUtils.Marshaller); writer.WriteInt((int) AtomicityMode); writer.WriteInt(Backups); @@ -344,7 +399,13 @@ namespace Apache.Ignite.Core.Cache.Configuration { writer.WriteBoolean(true); writer.WriteInt(cachePlugin.CachePluginConfigurationClosureFactoryId.Value); + + int pos = writer.Stream.Position; + writer.WriteInt(0); // Reserve size. + cachePlugin.WriteBinary(writer); + + writer.Stream.WriteInt(pos, writer.Stream.Position - pos); // Write size. } else { http://git-wip-us.apache.org/repos/asf/ignite/blob/b69f53e0/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs index 8173642..4419e2e 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs @@ -48,6 +48,7 @@ namespace Apache.Ignite.Core using Apache.Ignite.Core.PersistentStore; using Apache.Ignite.Core.Plugin; using Apache.Ignite.Core.Transactions; + using BinaryReader = Apache.Ignite.Core.Impl.Binary.BinaryReader; using BinaryWriter = Apache.Ignite.Core.Impl.Binary.BinaryWriter; /// @@ -242,7 +243,7 @@ namespace Apache.Ignite.Core /// /// The binary reader. /// The base configuration. - internal IgniteConfiguration(IBinaryRawReader binaryReader, IgniteConfiguration baseConfig) + internal IgniteConfiguration(BinaryReader binaryReader, IgniteConfiguration baseConfig) { Debug.Assert(binaryReader != null); Debug.Assert(baseConfig != null); @@ -509,7 +510,7 @@ namespace Apache.Ignite.Core /// Reads data from specified reader into current instance. /// /// The binary reader. - private void ReadCore(IBinaryRawReader r) + private void ReadCore(BinaryReader r) { // Simple properties _clientMode = r.ReadBooleanNullable(); @@ -630,7 +631,7 @@ namespace Apache.Ignite.Core /// Reads data from specified reader into current instance. /// /// The binary reader. - private void Read(IBinaryRawReader binaryReader) + private void Read(BinaryReader binaryReader) { ReadCore(binaryReader);