ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [11/12] ignite git commit: gg-11810
Date Mon, 16 Jan 2017 14:12:10 GMT
gg-11810


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

Branch: refs/heads/ignite-gg-11810-1
Commit: 173f3d6f1ab5105cced0fa1ece2f10f054fd110b
Parents: d4ccd89
Author: sboikov <sboikov@gridgain.com>
Authored: Mon Jan 16 17:06:44 2017 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Mon Jan 16 17:06:44 2017 +0300

----------------------------------------------------------------------
 .../ignite/internal/pagemem/PageMemory.java     |   4 -
 .../pagemem/impl/PageMemoryNoStoreImpl.java     |  17 ---
 .../cache/IgniteCacheOffheapManagerImpl.java    |  48 ++++-----
 .../cache/database/CacheDataRowAdapter.java     |  54 +++++-----
 .../cache/database/DataStructure.java           |   8 --
 .../cache/database/tree/BPlusTree.java          | 104 +++++++++----------
 .../cache/database/tree/util/PageHandler.java   |  23 ----
 7 files changed, 100 insertions(+), 158 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/173f3d6f/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageMemory.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageMemory.java
b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageMemory.java
index f90e718..cfee19f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageMemory.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageMemory.java
@@ -38,10 +38,6 @@ public interface PageMemory extends LifecycleAware, PageIdAllocator {
      */
     public Page page(int cacheId, long pageId) throws IgniteCheckedException;
 
-    public long readLockPage0(int cacheId, long pageId);
-
-    public void readUnlockPage0(long pageAddr);
-
     /**
      * @see #page(int, long)
      * Will not read page from file if it is not present in memory.

http://git-wip-us.apache.org/repos/asf/ignite/blob/173f3d6f/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoStoreImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoStoreImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoStoreImpl.java
index fd0ae75..41e401d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoStoreImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoStoreImpl.java
@@ -365,23 +365,6 @@ public class PageMemoryNoStoreImpl implements PageMemory {
         return rwLock.readLock(absPtr + LOCK_OFFSET, tag);
     }
 
-    @Override public long readLockPage0(int cacheId, long pageId) {
-        int pageIdx = PageIdUtils.pageIndex(pageId);
-
-        Segment seg = segment(pageIdx);
-
-        long absPtr = seg.absolute(pageIdx);
-
-        if (readLockPage(absPtr, PageIdUtils.tag(pageId)))
-            return absPtr + PageMemoryNoStoreImpl.PAGE_OVERHEAD;
-
-        return 0;
-    }
-
-    @Override public void readUnlockPage0(long pageAddr) {
-        readUnlockPage(pageAddr - PAGE_OVERHEAD);
-    }
-
     /**
      * @param absPtr Page absolute address.
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/173f3d6f/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java
index c0c3ea1..45cef13 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java
@@ -1205,41 +1205,41 @@ public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter
imple
 
             PageMemory pageMem = cctx.shared().database().pageMemory();
 
-//            try (Page page = page(pageId(link))) {
-//            }
-            long pageAddr = pageMem.readLockPage0(0, pageId(link)); // Non-empty data page
must not be recycled.
+            try (Page page = page(pageId(link))) {
+                long pageAddr = page.getForReadPointer(); // Non-empty data page must not
be recycled.
 
-            assert pageAddr != 0L : link;
+                assert pageAddr != 0L : link;
 
-            try {
-                DataPageIO io = DataPageIO.VERSIONS.forPage(pageAddr);
+                try {
+                    DataPageIO io = DataPageIO.VERSIONS.forPage(pageAddr);
 
-                DataPagePayload data = io.readPayload(pageAddr,
-                    itemId(link),
-                    pageMem.pageSize());
+                    DataPagePayload data = io.readPayload(pageAddr,
+                        itemId(link),
+                        pageMem.pageSize());
 
-                if (data.nextLink() == 0) {
-                    long addr = pageAddr + data.offset();
+                    if (data.nextLink() == 0) {
+                        long addr = pageAddr + data.offset();
 
-                    int len = PageUtils.getInt(addr, 0);
+                        int len = PageUtils.getInt(addr, 0);
 
-                    int size = Math.min(bytes.length, len);
+                        int size = Math.min(bytes.length, len);
 
-                    addr += 5; // Skip length and type byte.
+                        addr += 5; // Skip length and type byte.
 
-                    for (int i = 0; i < size; i++) {
-                        byte b1 = PageUtils.getByte(addr, i);
-                        byte b2 = bytes[i];
+                        for (int i = 0; i < size; i++) {
+                            byte b1 = PageUtils.getByte(addr, i);
+                            byte b2 = bytes[i];
 
-                        if (b1 != b2)
-                            return b1 > b2 ? 1 : -1;
-                    }
+                            if (b1 != b2)
+                                return b1 > b2 ? 1 : -1;
+                        }
 
-                    return Integer.compare(len, bytes.length);
+                        return Integer.compare(len, bytes.length);
+                    }
+                }
+                finally {
+                    page.releaseRead();
                 }
-            }
-            finally {
-                pageMem.readUnlockPage0(pageAddr);
             }
 
             // TODO GG-11768.

http://git-wip-us.apache.org/repos/asf/ignite/blob/173f3d6f/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java
index 3e215d5..5288aad 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java
@@ -93,45 +93,45 @@ public class CacheDataRowAdapter implements CacheDataRow {
         do {
             PageMemory pageMem = cctx.shared().database().pageMemory();
 
-            long pageAddr = pageMem.readLockPage0(0, pageId(nextLink)); // Non-empty data
page must not be recycled.
+            try (Page page = page(pageId(nextLink), cctx)) {
+                long pageAddr = page.getForReadPointer(); // Non-empty data page must not
be recycled.
 
-            assert pageAddr != 0L : nextLink;
+                assert pageAddr != 0L : nextLink;
 
-            try {
-                DataPageIO io = DataPageIO.VERSIONS.forPage(pageAddr);
+                try {
+                    DataPageIO io = DataPageIO.VERSIONS.forPage(pageAddr);
 
-                DataPagePayload data = io.readPayload(pageAddr,
-                    itemId(nextLink),
-                    pageMem.pageSize());
+                    DataPagePayload data = io.readPayload(pageAddr,
+                        itemId(nextLink),
+                        pageMem.pageSize());
 
-                nextLink = data.nextLink();
+                    nextLink = data.nextLink();
 
-                if (first) {
-                    if (nextLink == 0) {
-                        // Fast path for a single page row.
-                        readFullRow(coctx, pageAddr + data.offset(), keyOnly);
+                    if (first) {
+                        if (nextLink == 0) {
+                            // Fast path for a single page row.
+                            readFullRow(coctx, pageAddr + data.offset(), keyOnly);
 
-                        return;
-                    }
+                            return;
+                        }
 
-                    first = false;
-                }
+                        first = false;
+                    }
 
-                ByteBuffer buf = pageMem.pageBuffer(pageAddr);
+                    ByteBuffer buf = pageMem.pageBuffer(pageAddr);
 
-                buf.position(data.offset());
-                buf.limit(data.offset() + data.payloadSize());
+                    buf.position(data.offset());
+                    buf.limit(data.offset() + data.payloadSize());
 
-                incomplete = readFragment(coctx, buf, keyOnly, incomplete);
+                    incomplete = readFragment(coctx, buf, keyOnly, incomplete);
 
-                if (keyOnly && key != null)
-                    return;
-            }
-            finally {
-                pageMem.readUnlockPage0(pageAddr);
+                    if (keyOnly && key != null)
+                        return;
+                }
+                finally {
+                    page.releaseRead();
+                }
             }
-//            try (Page page = page(pageId(nextLink), cctx)) {
-//            }
         }
         while(nextLink != 0);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/173f3d6f/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/DataStructure.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/DataStructure.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/DataStructure.java
index 1ca38da..f47a697 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/DataStructure.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/DataStructure.java
@@ -162,14 +162,6 @@ public abstract class DataStructure implements PageLockListener {
         return PageHandler.readLock(page, this);
     }
 
-    protected final long readLock0(long pageId) {
-        return pageMem.readLockPage0(0, pageId);
-    }
-
-    protected final void readUnlock0(long pageAddr) {
-        pageMem.readUnlockPage0(pageAddr);
-    }
-
     /**
      * @param page Page.
      * @param buf Buffer.

http://git-wip-us.apache.org/repos/asf/ignite/blob/173f3d6f/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java
index 82d3ae6..7cf829e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java
@@ -746,23 +746,15 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
             firstPageId = getFirstPageId(meta, 0); // Level 0 is always at the bottom.
         }
 
-//        try (Page first = page(firstPageId)) {
-//            long pageAddr = readLock(first); // We always merge pages backwards, the first
page is never removed.
-//
-//            try {
-//                cursor.init(pageAddr, io(pageAddr), 0);
-//            }
-//            finally {
-//                readUnlock(first, pageAddr);
-//            }
-//        }
-        long pageAddr = readLock0(firstPageId); // We always merge pages backwards, the first
page is never removed.
+        try (Page first = page(firstPageId)) {
+            long pageAddr = readLock(first); // We always merge pages backwards, the first
page is never removed.
 
-        try {
-            cursor.init(pageAddr, io(pageAddr), 0);
-        }
-        finally {
-            readUnlock0(pageAddr);
+            try {
+                cursor.init(pageAddr, io(pageAddr), 0);
+            }
+            finally {
+                readUnlock(first, pageAddr);
+            }
         }
 
         return cursor;
@@ -864,7 +856,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
      */
     private Result findDown(final Get g, final long pageId, final long fwdId, final int lvl)
         throws IgniteCheckedException {
-        //Page page = page(pageId);
+        Page page = page(pageId);
 
         try {
             for (;;) {
@@ -872,7 +864,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
                 g.pageId = pageId;
                 g.fwdId = fwdId;
 
-                Result res = readPage(pageMem, pageId, search, g, lvl, RETRY);
+                Result res = readPage(page, this, search, g, lvl, RETRY);
 
                 switch (res) {
                     case GO_DOWN:
@@ -906,8 +898,8 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
             }
         }
         finally {
-//            if (g.canRelease(page, lvl))
-//                page.close();
+            if (g.canRelease(page, lvl))
+                page.close();
         }
     }
 
@@ -1029,26 +1021,28 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
      * @throws IgniteCheckedException If failed.
      */
     private L getGreatestRowInSubTree(long pageId) throws IgniteCheckedException {
-        long pageAddr = readLock0(pageId); // No correctness guaranties.
+        try (Page page = page(pageId)) {
+            long pageAddr = readLock(page); // No correctness guaranties.
 
-        try {
-            BPlusIO<L> io = io(pageAddr);
+            try {
+                BPlusIO<L> io = io(pageAddr);
 
-            int cnt = io.getCount(pageAddr);
+                int cnt = io.getCount(pageAddr);
 
-            if (io.isLeaf()) {
-                if (cnt <= 0) // This code is called only if the tree is not empty, so
we can't see empty leaf.
-                    fail("Invalid leaf count: " + cnt + " " + U.hexLong(pageId));
+                if (io.isLeaf()) {
+                    if (cnt <= 0) // This code is called only if the tree is not empty,
so we can't see empty leaf.
+                        fail("Invalid leaf count: " + cnt + " " + U.hexLong(pageId));
 
-                return io.getLookupRow(this, pageAddr, cnt - 1);
-            }
+                    return io.getLookupRow(this, pageAddr, cnt - 1);
+                }
 
-            long rightId = inner(io).getLeft(pageAddr, cnt);// The same as getRight(cnt -
1), but good for routing pages.
+                long rightId = inner(io).getLeft(pageAddr, cnt);// The same as getRight(cnt
- 1), but good for routing pages.
 
-            return getGreatestRowInSubTree(rightId);
-        }
-        finally {
-            readUnlock0(pageAddr);
+                return getGreatestRowInSubTree(rightId);
+            }
+            finally {
+                readUnlock(page, pageAddr);
+            }
         }
     }
 
@@ -1391,7 +1385,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
                 r.fwdId = fwdId;
                 r.backId = backId;
 
-                Result res = readPage(pageMem, pageId, search, r, lvl, RETRY);
+                Result res = readPage(page, this, search, r, lvl, RETRY);
 
                 switch (res) {
                     case GO_DOWN_X:
@@ -1790,12 +1784,10 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
      * @return Operation result.
      */
     private Result askNeighbor(long pageId, Get g, boolean back) throws IgniteCheckedException
{
-        return readPage(pageMem, pageId, askNeighbor, g,
-            back ? TRUE.ordinal() : FALSE.ordinal(), RETRY);
-//        try (Page page = page(pageId)) {
-//            return readPage(page, this, askNeighbor, g,
-//                back ? TRUE.ordinal() : FALSE.ordinal(), RETRY);
-//        }
+        try (Page page = page(pageId)) {
+            return readPage(page, this, askNeighbor, g,
+                back ? TRUE.ordinal() : FALSE.ordinal(), RETRY);
+        }
     }
 
     /**
@@ -1818,7 +1810,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
                 p.pageId = pageId;
                 p.fwdId = fwdId;
 
-                Result res = readPage(pageMem, pageId, search, p, lvl, RETRY);
+                Result res = readPage(page, this, search, p, lvl, RETRY);
 
                 switch (res) {
                     case GO_DOWN:
@@ -3679,22 +3671,24 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
                     return false; // Done.
                 }
 
-                long pageAddr = readLock0(nextPageId); // Doing explicit null check.
+                try (Page next = page(nextPageId)) {
+                    long pageAddr = readLock(next); // Doing explicit null check.
 
-                // If concurrent merge occurred we have to reinitialize cursor from the last
returned row.
-                if (pageAddr == 0L)
-                    break;
+                    // If concurrent merge occurred we have to reinitialize cursor from the
last returned row.
+                    if (pageAddr == 0L)
+                        break;
 
-                try {
-                    BPlusIO<L> io = io(pageAddr);
+                    try {
+                        BPlusIO<L> io = io(pageAddr);
 
-                    if (fillFromBuffer(pageAddr, io, 0, io.getCount(pageAddr)))
-                        return true;
+                        if (fillFromBuffer(pageAddr, io, 0, io.getCount(pageAddr)))
+                            return true;
 
-                    // Continue fetching forward.
-                }
-                finally {
-                    readUnlock0(pageAddr);
+                        // Continue fetching forward.
+                    }
+                    finally {
+                        readUnlock(next, pageAddr);
+                    }
                 }
             }
 
@@ -3730,7 +3724,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
         @SuppressWarnings("unchecked")
         @Override public final Result run(Page page, PageIO iox, long pageAddr, G g, int
lvl)
             throws IgniteCheckedException {
-//            assert PageIO.getPageId(pageAddr) == page.id();
+            assert PageIO.getPageId(pageAddr) == page.id();
 
             // If we've passed the check for correct page ID, we can safely cast.
             BPlusIO<L> io = (BPlusIO<L>)iox;

http://git-wip-us.apache.org/repos/asf/ignite/blob/173f3d6f/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 8efe619..97b5a04 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
@@ -96,29 +96,6 @@ public abstract class PageHandler<X, R> {
         }
     }
 
-    public static <X, R> R readPage(
-        PageMemory pageMem,
-        long pageId,
-        PageHandler<X, R> h,
-        X arg,
-        int intArg,
-        R lockFailed
-    ) throws IgniteCheckedException {
-        long pageAddr = pageMem.readLockPage0(0, pageId);
-
-        if (pageAddr == 0L)
-            return lockFailed;
-
-        try {
-            PageIO io = PageIO.getPageIO(pageAddr);
-
-            return h.run(null, io, pageAddr, arg, intArg);
-        }
-        finally {
-            pageMem.readUnlockPage0(pageAddr);
-        }
-    }
-
     /**
      * @param pageMem Page memory.
      * @param page Page.


Mime
View raw message