You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2015/11/02 18:21:58 UTC

[10/29] ignite git commit: Revert accidental changes for IGNITE-1835

Revert accidental changes for IGNITE-1835


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

Branch: refs/heads/ignite-950-new
Commit: fd640d7a86bea60fec65d807dd46757ee0093848
Parents: a96af3c
Author: Pavel Tupitsyn <pt...@gridgain.com>
Authored: Mon Nov 2 16:35:12 2015 +0300
Committer: Pavel Tupitsyn <pt...@gridgain.com>
Committed: Mon Nov 2 16:35:12 2015 +0300

----------------------------------------------------------------------
 .../Apache.Ignite.Core.csproj                   |   1 -
 .../Impl/Portable/PortableBuilderImpl.cs        |  30 +++---
 .../Impl/Portable/PortableObjectSchemaField.cs  |   7 +-
 .../Impl/Portable/PortableObjectSchemaHolder.cs | 101 -------------------
 .../Impl/Portable/PortableUtils.cs              |  12 +--
 .../Impl/Portable/PortableWriterImpl.cs         |  25 +++--
 6 files changed, 43 insertions(+), 133 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/fd640d7a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
index d782aec..ffe5d9f 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
@@ -258,7 +258,6 @@
     <Compile Include="Impl\Portable\PortableObjectHeader.cs" />
     <Compile Include="Impl\Portable\PortableObjectSchema.cs" />
     <Compile Include="Impl\Portable\PortableObjectSchemaField.cs" />
-    <Compile Include="Impl\Portable\PortableObjectSchemaHolder.cs" />
     <Compile Include="Impl\Portable\PortableReaderExtensions.cs" />
     <Compile Include="Impl\Portable\PortableReaderHandleDictionary.cs" />
     <Compile Include="Impl\Portable\PortableReaderImpl.cs" />

http://git-wip-us.apache.org/repos/asf/ignite/blob/fd640d7a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableBuilderImpl.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableBuilderImpl.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableBuilderImpl.cs
index f18f4f5..08a1d00 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableBuilderImpl.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableBuilderImpl.cs
@@ -23,6 +23,7 @@ namespace Apache.Ignite.Core.Impl.Portable
     using System.Diagnostics;
     using System.IO;
     using Apache.Ignite.Core.Common;
+    using Apache.Ignite.Core.Impl.Common;
     using Apache.Ignite.Core.Impl.Portable.IO;
     using Apache.Ignite.Core.Impl.Portable.Metadata;
     using Apache.Ignite.Core.Portable;
@@ -568,7 +569,7 @@ namespace Apache.Ignite.Core.Impl.Portable
         /// <param name="hash">New hash.</param>
         /// <param name="vals">Values to be replaced.</param>
         /// <returns>Mutated object.</returns>
-        private void Mutate0(Context ctx, PortableHeapStream inStream, IPortableStream outStream,
+        private unsafe void Mutate0(Context ctx, PortableHeapStream inStream, IPortableStream outStream,
             bool changeHash, int hash, IDictionary<int, PortableBuilderField> vals)
         {
             int inStartPos = inStream.Position;
@@ -625,7 +626,10 @@ namespace Apache.Ignite.Core.Impl.Portable
                         // New object, write in full form.
                         var inSchema = inHeader.ReadSchema(inStream, inStartPos);
 
-                        PortableObjectSchemaHolder.Current.PushSchema();
+                        var outSchemaLen = vals.Count + (inSchema == null ? 0 : inSchema.Length);
+                        var outSchema = outSchemaLen > 0 
+                            ? new ResizeableArray<PortableObjectSchemaField>(outSchemaLen)
+                            : null;
 
                         // Skip header as it is not known at this point.
                         outStream.Seek(PortableObjectHeader.Size, SeekOrigin.Current);
@@ -642,7 +646,7 @@ namespace Apache.Ignite.Core.Impl.Portable
                                     continue;
 
                                 // ReSharper disable once PossibleNullReferenceException (can't be null)
-                                PortableObjectSchemaHolder.Current.Push(inField.Id, outStream.Position - outStartPos);
+                                outSchema.Add(new PortableObjectSchemaField(inField.Id, outStream.Position - outStartPos));
 
                                 if (!fieldFound)
                                     fieldFound = _parent._cache != null &&
@@ -671,11 +675,14 @@ namespace Apache.Ignite.Core.Impl.Portable
                                 continue;
 
                             // ReSharper disable once PossibleNullReferenceException (can't be null)
-                            PortableObjectSchemaHolder.Current.Push(valEntry.Key, outStream.Position - outStartPos);
+                            outSchema.Add(new PortableObjectSchemaField(valEntry.Key, outStream.Position - outStartPos));
 
                             WriteField(ctx, valEntry.Value);
                         }
 
+                        if (outSchema != null && outSchema.Count == 0)
+                            outSchema = null;
+
                         // Write raw data.
                         int outRawOff = outStream.Position - outStartPos;
 
@@ -688,25 +695,24 @@ namespace Apache.Ignite.Core.Impl.Portable
                         // Write schema
                         int outSchemaOff = outRawOff;
 
-                        int schemaPos = outStream.Position;
-
-                        int outSchemaId;
-                        var hasSchema = PortableObjectSchemaHolder.Current.WriteAndPop(outStream, out outSchemaId);
-
-                        if (hasSchema)
+                        if (outSchema != null)
                         {
-                            outSchemaOff = schemaPos - outStartPos;
+                            outSchemaOff = outStream.Position - outStartPos;
+
+                            PortableObjectSchemaField.WriteArray(outSchema.Array, outStream, outSchema.Count);
 
                             if (inRawLen > 0)
                                 outStream.WriteInt(outRawOff);
                         }
 
+                        var outSchemaId = PortableUtils.GetSchemaId(outSchema);
+
                         var outLen = outStream.Position - outStartPos;
 
                         var outHash = changeHash ? hash : inHeader.HashCode;
 
                         var outHeader = new PortableObjectHeader(inHeader.IsUserType, inHeader.TypeId, outHash, 
-                            outLen, outSchemaId, outSchemaOff, !hasSchema);
+                            outLen, outSchemaId, outSchemaOff, outSchema == null);
 
                         PortableObjectHeader.Write(outHeader, outStream, outStartPos);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/fd640d7a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableObjectSchemaField.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableObjectSchemaField.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableObjectSchemaField.cs
index 36bbf39..48fd9c1 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableObjectSchemaField.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableObjectSchemaField.cs
@@ -53,9 +53,8 @@ namespace Apache.Ignite.Core.Impl.Portable
         /// </summary>
         /// <param name="fields">Fields.</param>
         /// <param name="stream">Stream.</param>
-        /// <param name="start">Start index.</param>
         /// <param name="count">Field count to write.</param>
-        public static unsafe void WriteArray(PortableObjectSchemaField[] fields, IPortableStream stream, int start, int count)
+        public static unsafe void WriteArray(PortableObjectSchemaField[] fields, IPortableStream stream, int count)
         {
             Debug.Assert(fields != null);
             Debug.Assert(stream != null);
@@ -63,14 +62,14 @@ namespace Apache.Ignite.Core.Impl.Portable
 
             if (BitConverter.IsLittleEndian)
             {
-                fixed (PortableObjectSchemaField* ptr = &fields[start])
+                fixed (PortableObjectSchemaField* ptr = &fields[0])
                 {
                     stream.Write((byte*) ptr, count * Size);
                 }
             }
             else
             {
-                for (int i = start; i < count + start; i++)
+                for (int i = 0; i < count; i++)
                 {
                     var field = fields[i];
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/fd640d7a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableObjectSchemaHolder.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableObjectSchemaHolder.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableObjectSchemaHolder.cs
deleted file mode 100644
index d909efa..0000000
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableObjectSchemaHolder.cs
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-namespace Apache.Ignite.Core.Impl.Portable
-{
-    using System;
-    using System.Collections.Generic;
-    using System.Threading;
-    using Apache.Ignite.Core.Impl.Portable.IO;
-
-    /// <summary>
-    /// Shared schema holder.
-    /// </summary>
-    internal class PortableObjectSchemaHolder
-    {
-        /** Current schema. */
-        private static readonly ThreadLocal<PortableObjectSchemaHolder> CurrentHolder =
-            new ThreadLocal<PortableObjectSchemaHolder>(() => new PortableObjectSchemaHolder());
-
-        /** Fields. */
-        private PortableObjectSchemaField[] _fields = new PortableObjectSchemaField[16];
-
-        /** Offsets for different schemas. */
-        private readonly Stack<int> _offsets = new Stack<int>();
-
-        /** Current field index. */
-        private int _idx;
-
-        /// <summary>
-        /// Gets the schema holder for the current thread.
-        /// </summary>
-        public static PortableObjectSchemaHolder Current
-        {
-            get { return CurrentHolder.Value; }
-        }
-
-        /// <summary>
-        /// Adds a field to the holder.
-        /// </summary>
-        /// <param name="id">The identifier.</param>
-        /// <param name="offset">The offset.</param>
-        public void Push(int id, int offset)
-        {
-            if (_idx == _fields.Length)
-                Array.Resize(ref _fields, _fields.Length * 2);
-
-            _fields[_idx] = new PortableObjectSchemaField(id, offset);
-
-            _idx++;
-        }
-
-        /// <summary>
-        /// Marks the start of a new schema.
-        /// </summary>
-        public void PushSchema()
-        {
-            _offsets.Push(_idx);
-        }
-
-        /// <summary>
-        /// Writes collected schema to the stream and pops it.
-        /// </summary>
-        /// <param name="stream">The stream.</param>
-        /// <param name="schemaId">The schema identifier.</param>
-        /// <returns>True if current schema was non empty; false otherwise.</returns>
-        public bool WriteAndPop(IPortableStream stream, out int schemaId)
-        {
-            var offset = _offsets.Pop();
-            var count = _idx - offset;
-
-            if (count > 0)
-            {
-                PortableObjectSchemaField.WriteArray(_fields, stream, offset, count);
-
-                schemaId = PortableUtils.GetSchemaId(_fields, offset, count);
-
-                _idx -= count;
-
-                return true;
-            }
-
-            schemaId = PortableUtils.GetSchemaId(null, 0, 0);
-
-            return false;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/fd640d7a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableUtils.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableUtils.cs
index 46c5707..a0657b2 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableUtils.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableUtils.cs
@@ -1771,20 +1771,20 @@ namespace Apache.Ignite.Core.Impl.Portable
         /// Gets the schema id as a Fnv1 hash.
         /// </summary>
         /// <param name="schema">The schema.</param>
-        /// <param name="start">Start index.</param>
-        /// <param name="count">Count.</param>
         /// <returns>
         /// Schema id.
         /// </returns>
-        public static int GetSchemaId(PortableObjectSchemaField[] schema, int start, int count)
+        public static int GetSchemaId(ResizeableArray<PortableObjectSchemaField> schema)
         {
             var hash = Fnv1Hash.Basis;
 
-            if (schema == null || schema.Length == 0)
+            if (schema == null || schema.Count == 0)
                 return hash;
 
-            for (int i = start; i < count; i++)
-                hash = Fnv1Hash.Update(hash, schema[i].Id);
+            var arr = schema.Array;
+
+            for (int i = 0; i < schema.Count; i++)
+                hash = Fnv1Hash.Update(hash, arr[i].Id);
 
             return hash;
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/fd640d7a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableWriterImpl.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableWriterImpl.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableWriterImpl.cs
index 069555f..e17449d 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableWriterImpl.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableWriterImpl.cs
@@ -21,6 +21,7 @@ namespace Apache.Ignite.Core.Impl.Portable
     using System.Collections;
     using System.Collections.Generic;
     using System.IO;
+    using Apache.Ignite.Core.Impl.Common;
     using Apache.Ignite.Core.Impl.Portable.IO;
     using Apache.Ignite.Core.Impl.Portable.Metadata;
     using Apache.Ignite.Core.Impl.Portable.Structure;
@@ -69,6 +70,10 @@ namespace Apache.Ignite.Core.Impl.Portable
         /** Current type structure tracker, */
         private PortableStructureTracker _curStruct;
 
+        /** Current schema. */
+        private ResizeableArray<PortableObjectSchemaField> _curSchema;
+
+
         /// <summary>
         /// Gets the marshaller.
         /// </summary>
@@ -1069,6 +1074,7 @@ namespace Apache.Ignite.Core.Impl.Portable
                 var oldPos = _curPos;
                 
                 var oldStruct = _curStruct;
+                var oldSchema = _curSchema;
 
                 // Push new frame.
                 _curTypeId = desc.TypeId;
@@ -1078,19 +1084,17 @@ namespace Apache.Ignite.Core.Impl.Portable
                 _curPos = pos;
 
                 _curStruct = new PortableStructureTracker(desc, desc.WriterTypeStructure);
-                PortableObjectSchemaHolder.Current.PushSchema();
+                _curSchema = null;
 
                 // Write object fields.
                 desc.Serializer.WritePortable(obj, this);
 
                 // Write schema
-                var schemaOffset = _stream.Position - pos;
+                var hasSchema = _curSchema != null;
+                var schemaOffset = hasSchema ? _stream.Position - pos : PortableObjectHeader.Size;
 
-                int schemaId;
-                var hasSchema = PortableObjectSchemaHolder.Current.WriteAndPop(_stream, out schemaId);
-
-                if (!hasSchema)
-                    schemaOffset = PortableObjectHeader.Size;
+                if (hasSchema)
+                    PortableObjectSchemaField.WriteArray(_curSchema.Array, _stream, _curSchema.Count);
 
                 // Calculate and write header.
                 if (hasSchema && _curRawPos > 0)
@@ -1099,7 +1103,7 @@ namespace Apache.Ignite.Core.Impl.Portable
                 var len = _stream.Position - pos;
 
                 var header = new PortableObjectHeader(desc.UserType, desc.TypeId, obj.GetHashCode(), len,
-                    schemaId, schemaOffset, !hasSchema);
+                    PU.GetSchemaId(_curSchema), schemaOffset, !hasSchema);
 
                 PortableObjectHeader.Write(header, _stream, pos);
 
@@ -1116,6 +1120,7 @@ namespace Apache.Ignite.Core.Impl.Portable
                 _curPos = oldPos;
 
                 _curStruct = oldStruct;
+                _curSchema = oldSchema;
             }
             else
             {
@@ -1367,7 +1372,9 @@ namespace Apache.Ignite.Core.Impl.Portable
 
             var fieldId = _curStruct.GetFieldId(fieldName, fieldTypeId);
 
-            PortableObjectSchemaHolder.Current.Push(fieldId, _stream.Position - _curPos);
+            _curSchema = _curSchema ?? new ResizeableArray<PortableObjectSchemaField>(4);
+
+            _curSchema.Add(new PortableObjectSchemaField(fieldId, _stream.Position - _curPos));
         }
 
         /// <summary>