ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject ignite git commit: WIP.
Date Wed, 01 Jun 2016 17:49:09 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-3228-1 7155ffbde -> 4309a7c43


WIP.


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

Branch: refs/heads/ignite-3228-1
Commit: 4309a7c439f89d3864aec6460ec8d648b1d99099
Parents: 7155ffb
Author: thatcoach <ppozerov@list.ru>
Authored: Wed Jun 1 20:48:58 2016 +0300
Committer: thatcoach <ppozerov@list.ru>
Committed: Wed Jun 1 20:48:58 2016 +0300

----------------------------------------------------------------------
 .../shuffle/collections/HadoopMultimapBase.java | 38 ++++++++++++++++++--
 1 file changed, 35 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/4309a7c4/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/shuffle/collections/HadoopMultimapBase.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/shuffle/collections/HadoopMultimapBase.java
b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/shuffle/collections/HadoopMultimapBase.java
index 2a56884..cbd8971 100644
--- a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/shuffle/collections/HadoopMultimapBase.java
+++ b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/shuffle/collections/HadoopMultimapBase.java
@@ -223,9 +223,11 @@ public abstract class HadoopMultimapBase implements HadoopMultimap {
         private long allocateNextPage(long requestedSize) {
             int writtenSize = writtenSize();
 
-            long newPageSize = ((writtenSize + requestedSize) % pageSize + 1) * pageSize;
+            long newPageSize = nextPageSize(writtenSize + requestedSize);
             long newPagePtr = mem.allocate(newPageSize);
 
+            System.out.println("ALLOCATED: " + newPageSize);
+
             HadoopOffheapBuffer b = out.buffer();
 
             b.set(newPagePtr, newPageSize);
@@ -245,13 +247,43 @@ public abstract class HadoopMultimapBase implements HadoopMultimap {
 
             if (oldPage != null)
                 allPages.add(oldPage);
-            // TODO: Must deallocate at this point.
-//                deallocate(oldPage);
 
             return b.move(requestedSize);
         }
 
         /**
+         * Get next page size.
+         *
+         * @param required Required amount of data.
+         * @return Next page size.
+         */
+        private long nextPageSize(long required) {
+            long pages = (required / pageSize) + 1;
+
+            long pagesPow2 = nextPowerOfTwo(pages);
+
+            return pagesPow2 * pageSize;
+        }
+
+        /**
+         * Get next power of two which greater or equal to the given number. Naive implementation.
+         *
+         * @param val Number
+         * @return Nearest pow2.
+         */
+        private long nextPowerOfTwo(long val) {
+            long res = 1;
+
+            while (res < val)
+                res = res << 1;
+
+            if (res < 0)
+                throw new IllegalArgumentException("Value is too big to find positive pow2:
" + val);
+
+            return res;
+        }
+
+        /**
          * @return Fixed pointer.
          */
         private long fixAlignment() {


Mime
View raw message