You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by il...@apache.org on 2019/02/28 11:23:25 UTC

[ignite] branch master updated: IGNITE-10925 Serialization compatibility fix for CacheMetricsSnapshot - Fixes #6201.

This is an automated email from the ASF dual-hosted git repository.

ilyak pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 51c34fc  IGNITE-10925 Serialization compatibility fix for CacheMetricsSnapshot - Fixes #6201.
51c34fc is described below

commit 51c34fc63e2a367566e680830bc4a9aa8aa34dc9
Author: mstepachev <ma...@gmail.com>
AuthorDate: Thu Feb 28 14:22:50 2019 +0300

    IGNITE-10925 Serialization compatibility fix for CacheMetricsSnapshot - Fixes #6201.
    
    Signed-off-by: Ilya Kasnacheev <il...@gmail.com>
---
 .../optimized/OptimizedObjectOutputStream.java     |  2 +-
 .../processors/cache/CacheMetricsSnapshot.java     | 37 +++++----
 ...rMetricsSnapshotSerializeCompatibilityTest.java | 90 ++++++++++++++++++++++
 .../ignite/testsuites/IgniteUtilSelfTestSuite.java |  2 +
 4 files changed, 113 insertions(+), 18 deletions(-)

diff --git a/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectOutputStream.java
index 2e41a34..1e191ec 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectOutputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectOutputStream.java
@@ -63,7 +63,7 @@ import static org.apache.ignite.internal.marshaller.optimized.OptimizedMarshalle
 /**
  * Optimized object output stream.
  */
-class OptimizedObjectOutputStream extends ObjectOutputStream {
+public class OptimizedObjectOutputStream extends ObjectOutputStream {
     /** */
     private final GridHandleTable handles = new GridHandleTable(10, 3.00f);
 
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsSnapshot.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsSnapshot.java
index 22df3fe..48f9764 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsSnapshot.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsSnapshot.java
@@ -23,6 +23,7 @@ import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.util.Collection;
 import org.apache.ignite.cache.CacheMetrics;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedObjectOutputStream;
 import org.apache.ignite.internal.util.typedef.internal.S;
 
 /**
@@ -1077,23 +1078,25 @@ public class CacheMetricsSnapshot implements CacheMetrics, Externalizable {
         out.writeLong(rebalancingBytesRate);
         out.writeLong(rebalancingKeysRate);
 
-        out.writeLong(rebalancedKeys);
-        out.writeLong(estimatedRebalancingKeys);
-        out.writeLong(rebalanceStartTime);
-        out.writeLong(rebalanceFinishTime);
-        out.writeLong(rebalanceClearingPartitionsLeft);
-
-        out.writeLong(entryProcessorPuts);
-        out.writeFloat(entryProcessorAverageInvocationTime);
-        out.writeLong(entryProcessorInvocations);
-        out.writeFloat(entryProcessorMaxInvocationTime);
-        out.writeFloat(entryProcessorMinInvocationTime);
-        out.writeLong(entryProcessorReadOnlyInvocations);
-        out.writeFloat(entryProcessorHitPercentage);
-        out.writeLong(entryProcessorHits);
-        out.writeLong(entryProcessorMisses);
-        out.writeFloat(entryProcessorMissPercentage);
-        out.writeLong(entryProcessorRemovals);
+        if (!(out instanceof OptimizedObjectOutputStream)) {
+            out.writeLong(rebalancedKeys);
+            out.writeLong(estimatedRebalancingKeys);
+            out.writeLong(rebalanceStartTime);
+            out.writeLong(rebalanceFinishTime);
+            out.writeLong(rebalanceClearingPartitionsLeft);
+
+            out.writeLong(entryProcessorPuts);
+            out.writeFloat(entryProcessorAverageInvocationTime);
+            out.writeLong(entryProcessorInvocations);
+            out.writeFloat(entryProcessorMaxInvocationTime);
+            out.writeFloat(entryProcessorMinInvocationTime);
+            out.writeLong(entryProcessorReadOnlyInvocations);
+            out.writeFloat(entryProcessorHitPercentage);
+            out.writeLong(entryProcessorHits);
+            out.writeLong(entryProcessorMisses);
+            out.writeFloat(entryProcessorMissPercentage);
+            out.writeLong(entryProcessorRemovals);
+        }
     }
 
     /** {@inheritDoc} */
diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/ClusterMetricsSnapshotSerializeCompatibilityTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/ClusterMetricsSnapshotSerializeCompatibilityTest.java
new file mode 100644
index 0000000..1e45af4
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/ClusterMetricsSnapshotSerializeCompatibilityTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.
+ */
+
+package org.apache.ignite.spi.discovery;
+
+import java.util.HashMap;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.internal.processors.cache.CacheMetricsSnapshot;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.MarshallerContextTestImpl;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/** */
+public class ClusterMetricsSnapshotSerializeCompatibilityTest extends GridCommonAbstractTest {
+    /** */
+    public ClusterMetricsSnapshotSerializeCompatibilityTest() {
+        super(false /*don't start grid*/);
+    }
+
+    /** Marshaller. */
+    private OptimizedMarshaller marshaller = marshaller();
+
+    /** */
+    @Test
+    public void testSerializationAndDeserialization() throws IgniteCheckedException {
+        HashMap<Integer, CacheMetricsSnapshot> metrics = new HashMap<>();
+
+        metrics.put(1, createMetricsWithBorderMarker());
+
+        metrics.put(2, createMetricsWithBorderMarker());
+
+        byte[] zipMarshal = U.zip(U.marshal(marshaller, metrics));
+
+        HashMap<Integer, CacheMetricsSnapshot> unmarshalMetrics = U.unmarshalZip(marshaller, zipMarshal, null);
+
+        assertTrue(isMetricsEquals(metrics.get(1), unmarshalMetrics.get(1)));
+
+        assertTrue(isMetricsEquals(metrics.get(2), unmarshalMetrics.get(2)));
+    }
+
+    /**
+     * @return Test metrics.
+     */
+    private CacheMetricsSnapshot createMetricsWithBorderMarker() {
+        CacheMetricsSnapshot metrics = new CacheMetricsSnapshot();
+
+        GridTestUtils.setFieldValue(metrics, "rebalancingKeysRate", 1234);
+        GridTestUtils.setFieldValue(metrics, "reads", 3232);
+
+        return metrics;
+    }
+
+    /**
+     * @param obj Object.
+     * @param obj1 Object 1.
+     */
+    private boolean isMetricsEquals(CacheMetricsSnapshot obj, CacheMetricsSnapshot obj1) {
+        return obj.getRebalancingKeysRate() == obj1.getRebalancingKeysRate() && obj.getCacheGets() == obj1.getCacheGets();
+    }
+
+    /**
+     * @return Marshaller.
+     */
+    private OptimizedMarshaller marshaller() {
+        U.clearClassCache();
+
+        OptimizedMarshaller marsh = new OptimizedMarshaller();
+
+        marsh.setContext(new MarshallerContextTestImpl());
+
+        return marsh;
+    }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java
index d444132..d620363 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java
@@ -39,6 +39,7 @@ import org.apache.ignite.internal.util.tostring.GridToStringBuilderSelfTest;
 import org.apache.ignite.internal.util.tostring.IncludeSensitiveAtomicTest;
 import org.apache.ignite.internal.util.tostring.IncludeSensitiveTransactionalTest;
 import org.apache.ignite.lang.GridByteArrayListSelfTest;
+import org.apache.ignite.spi.discovery.ClusterMetricsSnapshotSerializeCompatibilityTest;
 import org.apache.ignite.spi.discovery.ClusterMetricsSnapshotSerializeSelfTest;
 import org.apache.ignite.thread.GridThreadPoolExecutorServiceSelfTest;
 import org.apache.ignite.thread.GridThreadTest;
@@ -103,6 +104,7 @@ import org.junit.runners.Suite;
 
     // Metrics.
     ClusterMetricsSnapshotSerializeSelfTest.class,
+    ClusterMetricsSnapshotSerializeCompatibilityTest.class,
 
     // Unsafe.
     GridUnsafeMemorySelfTest.class,