ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agoncha...@apache.org
Subject [46/50] [abbrv] incubator-ignite git commit: # more optimal partition map serialization
Date Fri, 13 Feb 2015 20:28:44 GMT
# more optimal partition map serialization


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

Branch: refs/heads/ignite-52
Commit: 0542134d9a6569e07b1c2dd35917bd9d09d571ea
Parents: 2df53b6
Author: sboikov <semen.boikov@inria.fr>
Authored: Fri Feb 13 19:27:10 2015 +0300
Committer: sboikov <semen.boikov@inria.fr>
Committed: Fri Feb 13 19:27:10 2015 +0300

----------------------------------------------------------------------
 .../dht/preloader/GridDhtPartitionFullMap.java  |  2 +-
 .../dht/preloader/GridDhtPartitionMap.java      | 98 +++++++++++++++++++-
 2 files changed, 94 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0542134d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionFullMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionFullMap.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionFullMap.java
index c75cbdd..2a513ca 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionFullMap.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionFullMap.java
@@ -75,7 +75,7 @@ public class GridDhtPartitionFullMap extends HashMap<UUID, GridDhtPartitionMap>
             GridDhtPartitionMap part = e.getValue();
 
             if (onlyActive)
-                put(e.getKey(), new GridDhtPartitionMap(part.nodeId(), part.updateSequence(),
part, true));
+                put(e.getKey(), new GridDhtPartitionMap(part.nodeId(), part.updateSequence(),
part.map(), true));
             else
                 put(e.getKey(), part);
         }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0542134d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionMap.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionMap.java
index 8e6be93..9108ee4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionMap.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionMap.java
@@ -26,8 +26,7 @@ import java.util.*;
 /**
  * Partition map.
  */
-public class GridDhtPartitionMap extends HashMap<Integer, GridDhtPartitionState>
-    implements Comparable<GridDhtPartitionMap>, Externalizable {
+public class GridDhtPartitionMap implements Comparable<GridDhtPartitionMap>, Externalizable
{
     /** */
     private static final long serialVersionUID = 0L;
 
@@ -37,6 +36,9 @@ public class GridDhtPartitionMap extends HashMap<Integer, GridDhtPartitionState>
     /** Update sequence number. */
     private long updateSeq;
 
+    /** */
+    private Map<Integer, GridDhtPartitionState> map;
+
     /**
      * @param nodeId Node ID.
      * @param updateSeq Update sequence number.
@@ -47,6 +49,8 @@ public class GridDhtPartitionMap extends HashMap<Integer, GridDhtPartitionState>
 
         this.nodeId = nodeId;
         this.updateSeq = updateSeq;
+
+        map = new HashMap<>();
     }
 
     /**
@@ -62,11 +66,13 @@ public class GridDhtPartitionMap extends HashMap<Integer, GridDhtPartitionState>
         this.nodeId = nodeId;
         this.updateSeq = updateSeq;
 
+        map = U.newHashMap(m.size());
+
         for (Map.Entry<Integer, GridDhtPartitionState> e : m.entrySet()) {
             GridDhtPartitionState state = e.getValue();
 
             if (!onlyActive || state.active())
-                put(e.getKey(), state);
+                map.put(e.getKey(), state);
         }
     }
 
@@ -78,6 +84,58 @@ public class GridDhtPartitionMap extends HashMap<Integer, GridDhtPartitionState>
     }
 
     /**
+     * @param part Partition.
+     * @param state Partition state.
+     */
+    public void put(Integer part, GridDhtPartitionState state) {
+        map.put(part, state);
+    }
+
+    /**
+     * @param part Partition.
+     * @return Partition state.
+     */
+    public GridDhtPartitionState get(Integer part) {
+        return map.get(part);
+    }
+
+    /**
+     * @param part Partition.
+     * @return {@code True} if contains given partition.
+     */
+    public boolean containsKey(Integer part) {
+        return map.containsKey(part);
+    }
+
+    /**
+     * @return Entries.
+     */
+    public Set<Map.Entry<Integer, GridDhtPartitionState>> entrySet() {
+        return map.entrySet();
+    }
+
+    /**
+     * @return Map size.
+     */
+    public int size() {
+        return map.size();
+    }
+
+    /**
+     * @return Partitions.
+     */
+    public Set<Integer> keySet() {
+        return map.keySet();
+    }
+
+    /**
+     * @return Underlying map.
+     */
+    public Map<Integer, GridDhtPartitionState> map() {
+        return map;
+    }
+
+    /**
      * @return Node ID.
      */
     public UUID nodeId() {
@@ -118,7 +176,26 @@ public class GridDhtPartitionMap extends HashMap<Integer, GridDhtPartitionState>
 
         out.writeLong(updateSeq);
 
-        U.writeMap(out, this);
+        int size = map.size();
+
+        out.writeInt(size);
+
+        int i = 0;
+
+        for (Map.Entry<Integer, GridDhtPartitionState> entry : map.entrySet()) {
+            int ordinal = entry.getValue().ordinal();
+
+            assert ordinal == (ordinal & 0x3);
+            assert entry.getKey() == (entry.getKey() & 0x3FFF);
+
+            int coded = (ordinal << 14) | entry.getKey();
+
+            out.writeShort((short)coded);
+
+            i++;
+        }
+
+        assert i == size;
     }
 
     /** {@inheritDoc} */
@@ -127,7 +204,18 @@ public class GridDhtPartitionMap extends HashMap<Integer, GridDhtPartitionState>
 
         updateSeq = in.readLong();
 
-        putAll(U.<Integer, GridDhtPartitionState>readMap(in));
+        int size = in.readInt();
+
+        map = U.newHashMap(size);
+
+        for (int i = 0; i < size; i++) {
+            int entry = in.readShort() & 0xFFFF;
+
+            int part = entry & 0x3FFF;
+            int ordinal = entry >> 14;
+
+            map.put(part, GridDhtPartitionState.fromOrdinal(ordinal));
+        }
     }
 
     /** {@inheritDoc} */


Mime
View raw message