ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ptupit...@apache.org
Subject [1/2] ignite git commit: IGNITE-3512: .NET: Fixed a bug in BinaryBuilder causing type name to be lost.
Date Fri, 22 Jul 2016 12:44:20 GMT
Repository: ignite
Updated Branches:
  refs/heads/master ab4963a68 -> 2007cf859


IGNITE-3512: .NET: Fixed a bug in BinaryBuilder causing type name to be lost.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ce53491d
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ce53491d
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ce53491d

Branch: refs/heads/master
Commit: ce53491daa67639397582ab8ba53e15195af9cdb
Parents: 0f1a0cc
Author: Pavel Tupitsyn <ptupitsyn@apache.org>
Authored: Fri Jul 22 15:13:42 2016 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Fri Jul 22 15:13:42 2016 +0300

----------------------------------------------------------------------
 .../Binary/BinaryBuilderSelfTest.cs             | 57 +++++++++++++++++---
 .../Binary/BinarySelfTest.cs                    |  3 +-
 .../Impl/Binary/BinaryReader.cs                 | 18 +++----
 .../Impl/Binary/Marshaller.cs                   | 44 ++++++++++-----
 .../Binary/Structure/BinaryStructureTracker.cs  |  7 +--
 5 files changed, 93 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/ce53491d/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryBuilderSelfTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryBuilderSelfTest.cs
b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryBuilderSelfTest.cs
index 1b73022..40ecc1e 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryBuilderSelfTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryBuilderSelfTest.cs
@@ -25,8 +25,6 @@ namespace Apache.Ignite.Core.Tests.Binary
     using System.Collections.Generic;
     using System.Linq;
     using Apache.Ignite.Core.Binary;
-    using Apache.Ignite.Core.Discovery.Tcp;
-    using Apache.Ignite.Core.Discovery.Tcp.Static;
     using Apache.Ignite.Core.Impl;
     using Apache.Ignite.Core.Impl.Binary;
     using NUnit.Framework;
@@ -53,7 +51,7 @@ namespace Apache.Ignite.Core.Tests.Binary
         {
             TestUtils.KillProcesses();
 
-            var cfg = new IgniteConfiguration
+            var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
             {
                 BinaryConfiguration = new BinaryConfiguration
                 {
@@ -90,10 +88,7 @@ namespace Apache.Ignite.Core.Tests.Binary
                     DefaultIdMapper = new IdMapper(),
                     DefaultNameMapper = new NameMapper(),
                     CompactFooter = GetCompactFooter()
-                },
-                JvmClasspath = TestUtils.CreateTestClasspath(),
-                JvmOptions = TestUtils.TestJavaOptions(),
-                DiscoverySpi = TestUtils.GetStaticDiscovery()
+                }
             };
 
             _grid = (Ignite) Ignition.Start(cfg);
@@ -1458,6 +1453,54 @@ namespace Apache.Ignite.Core.Tests.Binary
             Assert.AreEqual(GetCompactFooter(), _marsh.CompactFooter);
         }
 
+        /// <summary>
+        /// Tests the binary mode on remote node.
+        /// </summary>
+        [Test]
+        public void TestRemoteBinaryMode()
+        {
+            var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
+            {
+                GridName = "grid2",
+                BinaryConfiguration = new BinaryConfiguration
+                {
+                    CompactFooter = GetCompactFooter()
+                }
+            };
+
+            using (var grid2 = Ignition.Start(cfg))
+            {
+                var cache1 = _grid.GetOrCreateCache<int, Primitives>("cache");
+                var cache2 = grid2.GetCache<int, object>("cache").WithKeepBinary<int,
IBinaryObject>();
+
+                // Exchange data
+                cache1[1] = new Primitives {FByte = 3};
+                var obj = cache2[1];
+
+                // Rebuild with no changes
+                cache2[2] = obj.ToBuilder().Build();
+                Assert.AreEqual(3, cache1[2].FByte);
+
+                // Rebuild with read
+                Assert.AreEqual(3, obj.GetField<byte>("FByte"));
+                cache2[3] = obj.ToBuilder().Build();
+                Assert.AreEqual(3, cache1[3].FByte);
+
+                // Modify and rebuild
+                cache2[4] = obj.ToBuilder().SetField("FShort", (short) 15).Build();
+                Assert.AreEqual(15, cache1[4].FShort);
+
+                // New binary type without a class
+                cache2[5] = grid2.GetBinary().GetBuilder("myNewType").SetField("foo", "bar").Build();
+
+                var cache1Bin = cache1.WithKeepBinary<int, IBinaryObject>();
+                var newObj = cache1Bin[5];
+                Assert.AreEqual("bar", newObj.GetField<string>("foo"));
+
+                cache1Bin[6] = newObj.ToBuilder().SetField("foo2", 3).Build();
+                Assert.AreEqual(3, cache2[6].GetField<int>("foo2"));
+            }
+        }
     }
 
     /// <summary>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ce53491d/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs
index 41e327b..0b21631 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinarySelfTest.cs
@@ -1230,8 +1230,7 @@ namespace Apache.Ignite.Core.Tests.Binary
 
             if (detached)
             {
-                var reader = new BinaryReader(marsh, new Dictionary<long, IBinaryTypeDescriptor>(),
-                    new BinaryHeapStream(bytes), BinaryMode.ForceBinary, null);
+                var reader = new BinaryReader(marsh, new BinaryHeapStream(bytes), BinaryMode.ForceBinary,
null);
 
                 reader.DetachNext();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/ce53491d/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs
index 1403410..7159274 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs
@@ -36,9 +36,6 @@ namespace Apache.Ignite.Core.Impl.Binary
         /** Marshaller. */
         private readonly Marshaller _marsh;
 
-        /** Type descriptors. */
-        private readonly IDictionary<long, IBinaryTypeDescriptor> _descs;
-
         /** Parent builder. */
         private readonly BinaryObjectBuilder _builder;
 
@@ -73,19 +70,16 @@ namespace Apache.Ignite.Core.Impl.Binary
         /// Constructor.
         /// </summary>
         /// <param name="marsh">Marshaller.</param>
-        /// <param name="descs">Descriptors.</param>
         /// <param name="stream">Input stream.</param>
         /// <param name="mode">The mode.</param>
         /// <param name="builder">Builder.</param>
         public BinaryReader
             (Marshaller marsh,
-            IDictionary<long, IBinaryTypeDescriptor> descs, 
             IBinaryStream stream, 
             BinaryMode mode,
             BinaryObjectBuilder builder)
         {
             _marsh = marsh;
-            _descs = descs;
             _mode = mode;
             _builder = builder;
 
@@ -697,15 +691,17 @@ namespace Apache.Ignite.Core.Impl.Binary
                 else
                 {
                     // Find descriptor.
-                    IBinaryTypeDescriptor desc;
-
-                    if (!_descs.TryGetValue(BinaryUtils.TypeKey(hdr.IsUserType, hdr.TypeId),
out desc))
-                        throw new BinaryObjectException("Unknown type ID: " + hdr.TypeId);
+                    var desc = _marsh.GetDescriptor(hdr.IsUserType, hdr.TypeId);
 
                     // Instantiate object. 
                     if (desc.Type == null)
+                    {
+                        if (desc is BinarySurrogateTypeDescriptor)
+                            throw new BinaryObjectException("Unknown type ID: " + hdr.TypeId);
+
                         throw new BinaryObjectException("No matching type found for object
[typeId=" +
-                                                    desc.TypeId + ", typeName=" + desc.TypeName
+ ']');
+                                                        desc.TypeId + ", typeName=" + desc.TypeName
+ ']');
+                    }
 
                     // Preserve old frame.
                     var oldHdr = _curHdr;

http://git-wip-us.apache.org/repos/asf/ignite/blob/ce53491d/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs
index 473fdf8..48a0c72 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs
@@ -50,8 +50,8 @@ namespace Apache.Ignite.Core.Impl.Binary
             new Dictionary<string, IBinaryTypeDescriptor>();
 
         /** ID to descriptor map. */
-        private readonly IDictionary<long, IBinaryTypeDescriptor> _idToDesc =
-            new Dictionary<long, IBinaryTypeDescriptor>();
+        private readonly CopyOnWriteConcurrentDictionary<long, IBinaryTypeDescriptor>
_idToDesc =
+            new CopyOnWriteConcurrentDictionary<long, IBinaryTypeDescriptor>();
 
         /** Cached metadatas. */
         private volatile IDictionary<int, BinaryTypeHolder> _metas =
@@ -239,7 +239,7 @@ namespace Apache.Ignite.Core.Impl.Binary
         /// </returns>
         public T Unmarshal<T>(IBinaryStream stream, BinaryMode mode, BinaryObjectBuilder
builder)
         {
-            return new BinaryReader(this, _idToDesc, stream, mode, builder).Deserialize<T>();
+            return new BinaryReader(this, stream, mode, builder).Deserialize<T>();
         }
 
         /// <summary>
@@ -252,8 +252,7 @@ namespace Apache.Ignite.Core.Impl.Binary
         /// </returns>
         public BinaryReader StartUnmarshal(IBinaryStream stream, bool keepBinary)
         {
-            return new BinaryReader(this, _idToDesc, stream,
-                keepBinary ? BinaryMode.KeepBinary : BinaryMode.Deserialize, null);
+            return new BinaryReader(this, stream, keepBinary ? BinaryMode.KeepBinary : BinaryMode.Deserialize,
null);
         }
 
         /// <summary>
@@ -264,7 +263,7 @@ namespace Apache.Ignite.Core.Impl.Binary
         /// <returns>Reader.</returns>
         public BinaryReader StartUnmarshal(IBinaryStream stream, BinaryMode mode = BinaryMode.Deserialize)
         {
-            return new BinaryReader(this, _idToDesc, stream, mode, null);
+            return new BinaryReader(this, stream, mode, null);
         }
         
         /// <summary>
@@ -387,17 +386,36 @@ namespace Apache.Ignite.Core.Impl.Binary
         }
 
         /// <summary>
-        /// 
+        /// Gets descriptor for a type id.
         /// </summary>
-        /// <param name="userType"></param>
-        /// <param name="typeId"></param>
-        /// <returns></returns>
+        /// <param name="userType">User type flag.</param>
+        /// <param name="typeId">Type id.</param>
+        /// <returns>Descriptor.</returns>
         public IBinaryTypeDescriptor GetDescriptor(bool userType, int typeId)
         {
             IBinaryTypeDescriptor desc;
 
-            return _idToDesc.TryGetValue(BinaryUtils.TypeKey(userType, typeId), out desc)
? desc :
-                userType ? new BinarySurrogateTypeDescriptor(_cfg, typeId) : null;
+            var typeKey = BinaryUtils.TypeKey(userType, typeId);
+
+            if (_idToDesc.TryGetValue(typeKey, out desc))
+                return desc;
+
+            if (!userType)
+                return null;
+
+            var meta = GetBinaryType(typeId);
+
+            if (meta != BinaryType.Empty)
+            {
+                desc = new BinaryFullTypeDescriptor(null, meta.TypeId, meta.TypeName, true,
null, null, null, false, 
+                    meta.AffinityKeyFieldName, meta.IsEnum);
+
+                _idToDesc.GetOrAdd(typeKey, _ => desc);
+
+                return desc;
+            }
+
+            return new BinarySurrogateTypeDescriptor(_cfg, typeId);
         }
 
         /// <summary>
@@ -534,7 +552,7 @@ namespace Apache.Ignite.Core.Impl.Binary
             if (userType)
                 _typeNameToDesc[typeName] = descriptor;
 
-            _idToDesc[typeKey] = descriptor;            
+            _idToDesc.GetOrAdd(typeKey, _ => descriptor);
         }
 
         /// <summary>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ce53491d/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Structure/BinaryStructureTracker.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Structure/BinaryStructureTracker.cs
b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Structure/BinaryStructureTracker.cs
index af1b050..8f44e00 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Structure/BinaryStructureTracker.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Structure/BinaryStructureTracker.cs
@@ -108,10 +108,11 @@ namespace Apache.Ignite.Core.Impl.Binary.Structure
                     foreach (var u in _curStructUpdates)
                         metaHnd.OnFieldWrite(u.FieldId, u.FieldName, u.FieldType);
 
-                    var meta = metaHnd.OnObjectWriteFinished();
+                    var fields = metaHnd.OnObjectWriteFinished();
 
-                    if (meta != null)
-                        writer.SaveMetadata(_desc, meta);
+                    // A new schema may be added, but no new fields. 
+                    // In this case, we should still call SaveMetadata even if fields are
null
+                    writer.SaveMetadata(_desc, fields);
                 }
             }
         }


Mime
View raw message