IGNITE-1282: WIP on optos.

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

Branch: refs/heads/ignite-1282-opto
Commit: 11f7d097da6c83b1dac8427e8294b098d98db898
Parents: 9da45ed
Author: vozerov-gridgain <voze...@gridgain.com>
Authored: Wed Oct 7 11:31:38 2015 +0300
Committer: vozerov-gridgain <voze...@gridgain.com>
Committed: Wed Oct 7 11:31:38 2015 +0300

----------------------------------------------------------------------
 .../Portable/PortableWriteBenchmark.cs          |  2 +-
 .../Impl/Portable/PortableMarshaller.cs         |  1 +
 .../Impl/Portable/PortableWriterImpl.cs         | 73 +++++++++-----------
 3 files changed, 35 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/11f7d097/modules/platforms/dotnet/Apache.Ignite.Benchmarks/Portable/PortableWriteBenchmark.cs
----------------------------------------------------------------------
diff --git 
a/modules/platforms/dotnet/Apache.Ignite.Benchmarks/Portable/PortableWriteBenchmark.cs
 
b/modules/platforms/dotnet/Apache.Ignite.Benchmarks/Portable/PortableWriteBenchmark.cs
index 9fcfa46..5638195 100644
--- 
a/modules/platforms/dotnet/Apache.Ignite.Benchmarks/Portable/PortableWriteBenchmark.cs
+++ 
b/modules/platforms/dotnet/Apache.Ignite.Benchmarks/Portable/PortableWriteBenchmark.cs
@@ -46,7 +46,7 @@ namespace Apache.Ignite.Benchmarks.Portable
             {
                 TypeConfigurations = new List<PortableTypeConfiguration>
                 {
-                    new PortableTypeConfiguration(typeof (Address)) 
{MetadataEnabled = false}
+                    new PortableTypeConfiguration(typeof (Address)) 
{MetadataEnabled = true}
                 }
             });
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/11f7d097/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableMarshaller.cs
----------------------------------------------------------------------
diff --git 
a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableMarshaller.cs
 
b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableMarshaller.cs
index c7a0b7b..c7262e1 100644
--- 
a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableMarshaller.cs
+++ 
b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableMarshaller.cs
@@ -309,6 +309,7 @@ namespace Apache.Ignite.Core.Impl.Portable
 
                 return new PortableHashsetMetadataHandler(ids, newType);
             }
+
             return null;
         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/11f7d097/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 6a0917a..9727377 100644
--- 
a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableWriterImpl.cs
+++ 
b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableWriterImpl.cs
@@ -57,9 +57,6 @@ namespace Apache.Ignite.Core.Impl.Portable
 
         /** Current mapper. */
         private IPortableIdMapper _curMapper;
-
-        /** Current metadata handler. */
-        private IPortableMetadataHandler _curMetaHnd;
         
         /** Current raw position. */
         private long _curRawPos;
@@ -67,7 +64,6 @@ namespace Apache.Ignite.Core.Impl.Portable
         private PortableTypeStructure _curTypeStruct;
         private int _curPathIdx;
         private int _curActionIdx;
-        private bool _curNewStruct;
         private List<PortableTypeStructureUpdate> _curUpdates; 
         
         /** Whether we are currently detaching an object. */
@@ -1308,26 +1304,22 @@ namespace Apache.Ignite.Core.Impl.Portable
                 int oldTypeId = _curTypeId;
                 IPortableNameMapper oldConverter = _curConverter;
                 IPortableIdMapper oldMapper = _curMapper;
-                IPortableMetadataHandler oldMetaHnd = _curMetaHnd;
                 long oldRawPos = _curRawPos;
                 
                 PortableTypeStructure oldTypeStruct = _curTypeStruct;
                 int oldPathIdx = _curPathIdx;
                 int oldActionIdx = _curActionIdx;
-                bool oldNewStruct = _curNewStruct;
                 var oldUpdates = _curUpdates;
 
                 // Push new frame.
                 _curTypeId = desc.TypeId;
                 _curConverter = desc.NameConverter;
                 _curMapper = desc.Mapper;
-                _curMetaHnd = desc.MetadataEnabled ? 
_marsh.MetadataHandler(desc) : null;
                 _curRawPos = 0;
 
                 _curTypeStruct = desc.TypeStructure;
                 _curPathIdx = 0;
                 _curActionIdx = 0;
-                _curNewStruct = false;
                 _curUpdates = null;
 
                 // Write object fields.
@@ -1343,30 +1335,34 @@ namespace Apache.Ignite.Core.Impl.Portable
                 else
                     _stream.WriteInt(pos + 14, len);
 
-                // 13. Collect metadata.
-                if (_curMetaHnd != null)
+                // 13. Apply structure updates if any.
+                if (_curUpdates != null)
                 {
-                    IDictionary<string, int> meta = 
_curMetaHnd.OnObjectWriteFinished();
+                    desc.UpdateStrcuture(_curTypeStruct, _curPathIdx, 
_curUpdates);
+
+                    IPortableMetadataHandler metaHnd = 
_marsh.MetadataHandler(desc);
+
+                    if (metaHnd != null)
+                    {
+                        foreach (var u in _curUpdates)
+                            metaHnd.OnFieldWrite(u.FieldId, u.FieldName, 
u.FieldType);
+
+                        IDictionary<string, int> meta = 
metaHnd.OnObjectWriteFinished();
 
-                    if (meta != null)
-                        SaveMetadata(_curTypeId, desc.TypeName, 
desc.AffinityKeyFieldName, meta);
+                        if (meta != null)
+                            SaveMetadata(_curTypeId, desc.TypeName, 
desc.AffinityKeyFieldName, meta);
+                    }
                 }
 
-                // 14. Apply structure updates 
-                if (_curUpdates != null)
-                    desc.UpdateStrcuture(_curTypeStruct, _curPathIdx, 
_curUpdates);
-                
                 // Restore old frame.
                 _curTypeId = oldTypeId;
                 _curConverter = oldConverter;
                 _curMapper = oldMapper;
-                _curMetaHnd = oldMetaHnd;
                 _curRawPos = oldRawPos;
 
                 _curTypeStruct = oldTypeStruct;
                 _curPathIdx = oldPathIdx;
                 _curActionIdx = oldActionIdx;
-                _curNewStruct = oldNewStruct;
                 _curUpdates = oldUpdates;
             }
             else
@@ -1628,36 +1624,33 @@ namespace Apache.Ignite.Core.Impl.Portable
 
             int fieldId;
 
-            if (!_curNewStruct)
+            if (_curUpdates == null)
             {
                 fieldId = _curTypeStruct.GetFieldId(fieldName, fieldTypeId, 
ref _curPathIdx, actionIdx);
 
                 if (fieldId == 0)
-                {
-                    _curNewStruct = true;
-
-                    fieldId = PU.FieldId(_curTypeId, fieldName, _curConverter, 
_curMapper);
-
-                    if (_curUpdates == null)
-                        _curUpdates = new List<PortableTypeStructureUpdate>();
-
-                    _curUpdates.Add(new PortableTypeStructureUpdate(fieldName, 
fieldId, fieldTypeId, actionIdx));
-                }
+                    fieldId = GetNewFieldId(fieldName, fieldTypeId, actionIdx);
             }
             else
-            {
-                fieldId = PU.FieldId(_curTypeId, fieldName, _curConverter, 
_curMapper);
+                fieldId = GetNewFieldId(fieldName, fieldTypeId, actionIdx);
 
-                if (_curUpdates == null)
-                    _curUpdates = new List<PortableTypeStructureUpdate>();
+            _stream.WriteInt(fieldId);
+        }
 
-                _curUpdates.Add(new PortableTypeStructureUpdate(fieldName, 
fieldId, fieldTypeId, actionIdx));
-            }
+        /// <summary>
+        /// Get ID for the new field and save structure update.
+        /// </summary>
+        /// <returns>Field ID.</returns>
+        private int GetNewFieldId(string fieldName, byte fieldTypeId, int 
actionIdx)
+        {
+            int fieldId = PU.FieldId(_curTypeId, fieldName, _curConverter, 
_curMapper);
 
-            _stream.WriteInt(fieldId);
-            
-            if (_curMetaHnd != null)
-                _curMetaHnd.OnFieldWrite(fieldId, fieldName, fieldTypeId);
+            if (_curUpdates == null)
+                _curUpdates = new List<PortableTypeStructureUpdate>();
+
+            _curUpdates.Add(new PortableTypeStructureUpdate(fieldName, 
fieldId, fieldTypeId, actionIdx));
+
+            return fieldId;
         }
 
         /// <summary>

Reply via email to