ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yzhda...@apache.org
Subject [07/13] ignite git commit: ignite-db - copyMemory
Date Fri, 29 Apr 2016 17:01:54 GMT
ignite-db - copyMemory


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

Branch: refs/heads/ignite-db-x-gg-11124
Commit: bbd4e9ff04e5fb00344f51573779fb151d502264
Parents: 3abcfc1
Author: S.Vladykin <svladykin@gridgain.com>
Authored: Thu Apr 28 08:08:46 2016 +0300
Committer: S.Vladykin <svladykin@gridgain.com>
Committed: Thu Apr 28 08:08:46 2016 +0300

----------------------------------------------------------------------
 .../cache/database/tree/io/BPlusInnerIO.java     | 13 +++++--------
 .../cache/database/tree/io/BPlusLeafIO.java      | 10 ++--------
 .../cache/database/tree/io/DataPageIO.java       | 12 ++++--------
 .../cache/database/tree/util/PageHandler.java    | 19 +++++++++++++++++++
 4 files changed, 30 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/bbd4e9ff/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusInnerIO.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusInnerIO.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusInnerIO.java
index 60c8f58..3e13179 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusInnerIO.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusInnerIO.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.cache.database.tree.io;
 
 import java.nio.ByteBuffer;
 import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler;
 
 /**
  * Abstract IO routines for B+Tree inner pages.
@@ -96,11 +97,10 @@ public abstract class BPlusInnerIO<L> extends BPlusIO<L> {
         boolean cpLeft) throws IgniteCheckedException {
         assert srcIdx != dstIdx || src != dst;
 
+        cnt *= itemSize + 8; // From items to bytes.
+
         if (dstIdx > srcIdx) {
-            for (int i = cnt - 1; i >= 0; i--) {
-                dst.putLong(offset(dstIdx + i, SHIFT_RIGHT), src.getLong(offset(srcIdx +
i, SHIFT_RIGHT)));
-                store(dst, dstIdx + i, this, src, srcIdx + i); // TODO optimize with copy
by itemSize
-            }
+            PageHandler.copyMemory(src, dst, offset(srcIdx), offset(dstIdx), cnt);
 
             if (cpLeft)
                 dst.putLong(offset(dstIdx, SHIFT_LEFT), src.getLong(offset(srcIdx, SHIFT_LEFT)));
@@ -109,10 +109,7 @@ public abstract class BPlusInnerIO<L> extends BPlusIO<L>
{
             if (cpLeft)
                 dst.putLong(offset(dstIdx, SHIFT_LEFT), src.getLong(offset(srcIdx, SHIFT_LEFT)));
 
-            for (int i = 0; i < cnt; i++) {
-                dst.putLong(offset(dstIdx + i, SHIFT_RIGHT), src.getLong(offset(srcIdx +
i, SHIFT_RIGHT)));
-                store(dst, dstIdx + i, this, src, srcIdx + i); // TODO optimize with copy
by itemSize
-            }
+            PageHandler.copyMemory(src, dst, offset(srcIdx), offset(dstIdx), cnt);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/bbd4e9ff/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusLeafIO.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusLeafIO.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusLeafIO.java
index 1b86ef9..5a8f851 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusLeafIO.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusLeafIO.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.cache.database.tree.io;
 
 import java.nio.ByteBuffer;
 import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler;
 
 /**
  * Abstract IO routines for B+Tree leaf pages.
@@ -43,14 +44,7 @@ public abstract class BPlusLeafIO<L> extends BPlusIO<L> {
         boolean cpLeft) throws IgniteCheckedException {
         assert srcIdx != dstIdx || src != dst;
 
-        if (dstIdx > srcIdx) {
-            for (int i = cnt - 1; i >= 0; i--)
-                store(dst, dstIdx + i, this, src, srcIdx + i); // TODO optimize with copy
by itemSize
-        }
-        else {
-            for (int i = 0; i < cnt; i++)
-                store(dst, dstIdx + i, this, src, srcIdx + i); // TODO optimize with copy
by itemSize
-        }
+        PageHandler.copyMemory(src, dst, offset(srcIdx), offset(dstIdx), cnt * itemSize);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/bbd4e9ff/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPageIO.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPageIO.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPageIO.java
index a5efb5d..50a1c71 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPageIO.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPageIO.java
@@ -23,6 +23,7 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
 
 /**
@@ -652,15 +653,10 @@ public class DataPageIO extends PageIO {
      */
     private static void moveBytes(ByteBuffer buf, int off, int cnt, int step) {
         assert step != 0: step;
+        assert off + step >= 0;
+        assert off + step + cnt < buf.capacity();
 
-        if (step > 0) {
-            for (int i = off + cnt - 1; i >= 0; i--)
-                buf.put(i + step, buf.get(i));
-        }
-        else {
-            for (int i = off, end = off + cnt; i < end; i++)
-                buf.put(i + step, buf.get(i));
-        }
+        PageHandler.copyMemory(buf, buf, off, off + step, cnt);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/bbd4e9ff/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageHandler.java
index f70d13d..d2cf58b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageHandler.java
@@ -20,6 +20,8 @@ package org.apache.ignite.internal.processors.cache.database.tree.util;
 import java.nio.ByteBuffer;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.pagemem.Page;
+import org.apache.ignite.internal.util.GridUnsafe;
+import sun.nio.ch.DirectBuffer;
 
 /**
  * Page handler. Can do {@link #readPage(Page, PageHandler, Object, int)}
@@ -102,4 +104,21 @@ public abstract class PageHandler<X> {
 
         return res;
     }
+
+    /**
+     * @param src Source.
+     * @param dst Destination.
+     * @param srcOff Source offset in bytes.
+     * @param dstOff Destination offset in bytes.
+     * @param cnt Bytes count to copy.
+     */
+    public static void copyMemory(ByteBuffer src, ByteBuffer dst, long srcOff, long dstOff,
long cnt) {
+        assert src.isDirect();
+        assert dst.isDirect();
+
+        long srcPtr = ((DirectBuffer)src).address() + srcOff;
+        long dstPtr = ((DirectBuffer)dst).address() + dstOff;
+
+        GridUnsafe.copyMemory(srcPtr, dstPtr, cnt);
+    }
 }


Mime
View raw message