ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agoncha...@apache.org
Subject [16/21] ignite git commit: Backward compatibility WIP
Date Tue, 15 Aug 2017 16:05:22 GMT
Backward compatibility WIP


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

Branch: refs/heads/ignite-5872
Commit: 6da469c0173d57f5fe7231708c254e4512e71a51
Parents: 61a98af
Author: Alexey Goncharuk <alexey.goncharuk@gmail.com>
Authored: Tue Aug 15 14:45:05 2017 +0300
Committer: Alexey Goncharuk <alexey.goncharuk@gmail.com>
Committed: Tue Aug 15 14:45:05 2017 +0300

----------------------------------------------------------------------
 .../preloader/GridDhtPartitionsFullMessage.java | 43 ++++++++------
 .../IgniteDhtPartitionCountersMap.java          | 14 +++--
 .../IgniteDhtPartitionCountersPrimitiveMap.java | 62 ++++++++++++++++++++
 3 files changed, 96 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/6da469c0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsFullMessage.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsFullMessage.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsFullMessage.java
index 5f415e2..4e04f19 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsFullMessage.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsFullMessage.java
@@ -62,7 +62,7 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
     /** Partitions update counters. */
     @GridToStringInclude
     @GridDirectTransient
-    private IgniteDhtPartitionCountersMap partCntrs;
+    private IgniteDhtPartitionCountersPrimitiveMap primPartCntrs;
 
     /** Serialized partitions counters. */
     private byte[] partCntrsBytes;
@@ -98,6 +98,9 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
     @GridDirectTransient
     private transient boolean compress;
 
+    /** */
+    private transient boolean compatibilityMode;
+
     /**
      * Required by {@link Externalizable}.
      */
@@ -109,14 +112,17 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
      * @param id Exchange ID.
      * @param lastVer Last version.
      * @param topVer Topology version. For messages not related to exchange may be {@link
AffinityTopologyVersion#NONE}.
-     * @param partHistSuppliers
-     * @param partsToReload
+     * @param partHistSuppliers Partition history suppliers.
+     * @param partsToReload Partitions to reload.
      */
-    public GridDhtPartitionsFullMessage(@Nullable GridDhtPartitionExchangeId id,
+    public GridDhtPartitionsFullMessage(
+        @Nullable GridDhtPartitionExchangeId id,
         @Nullable GridCacheVersion lastVer,
         @NotNull AffinityTopologyVersion topVer,
         @Nullable IgniteDhtPartitionHistorySuppliersMap partHistSuppliers,
-        @Nullable IgniteDhtPartitionsToReloadMap partsToReload) {
+        @Nullable IgniteDhtPartitionsToReloadMap partsToReload,
+        boolean compatibilityMode
+    ) {
         super(id, lastVer);
 
         assert id == null || topVer.equals(id.topologyVersion());
@@ -124,6 +130,7 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
         this.topVer = topVer;
         this.partHistSuppliers = partHistSuppliers;
         this.partsToReload = partsToReload;
+        this.compatibilityMode = compatibilityMode;
     }
 
     /** {@inheritDoc} */
@@ -187,10 +194,10 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
      * @param cntrMap Partition update counters.
      */
     public void addPartitionUpdateCounters(int grpId, CachePartitionFullCountersMap cntrMap)
{
-        if (partCntrs == null)
-            partCntrs = new IgniteDhtPartitionCountersMap();
+        if (primPartCntrs == null)
+            primPartCntrs = new IgniteDhtPartitionCountersPrimitiveMap();
 
-        partCntrs.putIfAbsent(grpId, cntrMap);
+        primPartCntrs.putIfAbsent(grpId, cntrMap);
     }
 
     /**
@@ -198,7 +205,7 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
      * @return Partition update counters.
      */
     public CachePartitionFullCountersMap partitionUpdateCounters(int grpId) {
-        return partCntrs == null ? null : partCntrs.get(grpId);
+        return primPartCntrs == null ? null : primPartCntrs.get(grpId);
     }
 
     /**
@@ -237,7 +244,7 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
         super.prepareMarshal(ctx);
 
         boolean marshal = (parts != null && partsBytes == null) ||
-            (partCntrs != null && partCntrsBytes == null) ||
+            (primPartCntrs != null && partCntrsBytes == null) ||
             (partHistSuppliers != null && partHistSuppliersBytes == null) ||
             (partsToReload != null && partsToReloadBytes == null) ||
             (errs != null && errsBytes == null);
@@ -252,8 +259,8 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
             if (parts != null && partsBytes == null)
                 partsBytes0 = U.marshal(ctx, parts);
 
-            if (partCntrs != null && partCntrsBytes == null)
-                partCntrsBytes0 = U.marshal(ctx, partCntrs);
+            if (primPartCntrs != null && partCntrsBytes == null)
+                partCntrsBytes0 = U.marshal(ctx, compatibilityMode ? convertToOld(primPartCntrs)
: primPartCntrs);
 
             if (partHistSuppliers != null && partHistSuppliersBytes == null)
                 partHistSuppliersBytes0 = U.marshal(ctx, partHistSuppliers);
@@ -350,11 +357,13 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
         if (parts == null)
             parts = new HashMap<>();
 
-        if (partCntrsBytes != null && partCntrs == null) {
+        if (partCntrsBytes != null && primPartCntrs == null) {
             if (compressed())
-                partCntrs = U.unmarshalZip(ctx.marshaller(), partCntrsBytes, U.resolveClassLoader(ldr,
ctx.gridConfig()));
+                primPartCntrs = convertToNew(
+                    U.unmarshalZip(ctx.marshaller(), partCntrsBytes, U.resolveClassLoader(ldr,
ctx.gridConfig())));
             else
-                partCntrs = U.unmarshal(ctx, partCntrsBytes, U.resolveClassLoader(ldr, ctx.gridConfig()));
+                primPartCntrs = convertToNew(
+                    U.unmarshal(ctx, partCntrsBytes, U.resolveClassLoader(ldr, ctx.gridConfig())));
         }
 
         if (partHistSuppliersBytes != null && partHistSuppliers == null) {
@@ -371,8 +380,8 @@ public class GridDhtPartitionsFullMessage extends GridDhtPartitionsAbstractMessa
                 partsToReload = U.unmarshal(ctx, partsToReloadBytes, U.resolveClassLoader(ldr,
ctx.gridConfig()));
         }
 
-        if (partCntrs == null)
-            partCntrs = new IgniteDhtPartitionCountersMap();
+        if (primPartCntrs == null)
+            primPartCntrs = new IgniteDhtPartitionCountersPrimitiveMap();
 
         if (errsBytes != null && errs == null) {
             if (compressed())

http://git-wip-us.apache.org/repos/asf/ignite/blob/6da469c0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionCountersMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionCountersMap.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionCountersMap.java
index 75cfb37..9db80ae 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionCountersMap.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionCountersMap.java
@@ -19,8 +19,10 @@
 package org.apache.ignite.internal.processors.cache.distributed.dht.preloader;
 
 import java.io.Serializable;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import org.apache.ignite.internal.util.typedef.T2;
 
 /**
  * Partition counters map.
@@ -30,13 +32,13 @@ public class IgniteDhtPartitionCountersMap implements Serializable {
     private static final long serialVersionUID = 0L;
 
     /** */
-    private Map<Integer, CachePartitionFullCountersMap> map;
+    private Map<Integer, Map<Integer, T2<Long, Long>>> map;
 
     /**
      * @param cacheId Cache ID.
      * @param cntrMap Counters map.
      */
-    public synchronized void putIfAbsent(int cacheId, CachePartitionFullCountersMap cntrMap)
{
+    public synchronized void putIfAbsent(int cacheId, Map<Integer, T2<Long, Long>>
cntrMap) {
         if (map == null)
             map = new HashMap<>();
 
@@ -48,14 +50,14 @@ public class IgniteDhtPartitionCountersMap implements Serializable {
      * @param cacheId Cache ID.
      * @return Counters map.
      */
-    public synchronized CachePartitionFullCountersMap get(int cacheId) {
+    public synchronized Map<Integer, T2<Long, Long>> get(int cacheId) {
         if (map == null)
-            return null;
+            map = new HashMap<>();
 
-        CachePartitionFullCountersMap cntrMap = map.get(cacheId);
+        Map<Integer, T2<Long, Long>> cntrMap = map.get(cacheId);
 
         if (cntrMap == null)
-            return null;
+            return Collections.emptyMap();
 
         return cntrMap;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/6da469c0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionCountersPrimitiveMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionCountersPrimitiveMap.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionCountersPrimitiveMap.java
new file mode 100644
index 0000000..af9be7f
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionCountersPrimitiveMap.java
@@ -0,0 +1,62 @@
+/*
+ * 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.internal.processors.cache.distributed.dht.preloader;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Partition counters map.
+ */
+public class IgniteDhtPartitionCountersPrimitiveMap implements Serializable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** */
+    private Map<Integer, CachePartitionFullCountersMap> map;
+
+    /**
+     * @param cacheId Cache ID.
+     * @param cntrMap Counters map.
+     */
+    public synchronized void putIfAbsent(int cacheId, CachePartitionFullCountersMap cntrMap)
{
+        if (map == null)
+            map = new HashMap<>();
+
+        if (!map.containsKey(cacheId))
+            map.put(cacheId, cntrMap);
+    }
+
+    /**
+     * @param cacheId Cache ID.
+     * @return Counters map.
+     */
+    public synchronized CachePartitionFullCountersMap get(int cacheId) {
+        if (map == null)
+            return null;
+
+        CachePartitionFullCountersMap cntrMap = map.get(cacheId);
+
+        if (cntrMap == null)
+            return null;
+
+        return cntrMap;
+    }
+}


Mime
View raw message