ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [1/8] ignite git commit: GC pressure
Date Wed, 05 Apr 2017 14:59:07 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-4811-no-start-ver [created] 64959753f


http://git-wip-us.apache.org/repos/asf/ignite/blob/37eed342/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java
index 06999cb..2586696 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java
@@ -21,7 +21,6 @@ import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.List;
 import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.pagemem.Page;
 import org.apache.ignite.internal.pagemem.PageMemory;
 import org.apache.ignite.internal.pagemem.PageUtils;
 import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager;
@@ -62,7 +61,7 @@ import org.apache.ignite.internal.processors.cache.database.tree.util.PageLockLi
  *
  * 7. It is almost always preferable to read or write (especially write) page contents using
  *    static methods on {@link PageHandler}. To just initialize new page use
- *    {@link PageHandler#initPage(PageMemory, Page, PageLockListener, PageIO, IgniteWriteAheadLogManager)}
+ *    {@link PageHandler#initPage(PageMemory, int, long, PageIO, IgniteWriteAheadLogManager, PageLockListener)}
  *    method with needed IO instance.
  */
 public abstract class PageIO {

http://git-wip-us.apache.org/repos/asf/ignite/blob/37eed342/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseListImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseListImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseListImpl.java
index ce8266a..1c6c8d5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseListImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseListImpl.java
@@ -65,7 +65,7 @@ public class ReuseListImpl extends PagesList implements ReuseList {
 
     /** {@inheritDoc} */
     @Override public void addForRecycle(ReuseBag bag) throws IgniteCheckedException {
-        put(bag, null, 0, 0);
+        put(bag, 0, 0, 0, 0);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/37eed342/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 97b5a04..f660686 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
@@ -19,7 +19,6 @@ 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.pagemem.PageMemory;
 import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager;
 import org.apache.ignite.internal.pagemem.wal.record.delta.InitNewPageRecord;
@@ -34,38 +33,62 @@ import static java.lang.Boolean.TRUE;
  */
 public abstract class PageHandler<X, R> {
     /** */
-    private static final PageHandler<Void, Boolean> NOOP = new PageHandler<Void, Boolean>() {
-        @Override public Boolean run(Page page, PageIO io, long pageAddr, Void arg, int intArg)
-            throws IgniteCheckedException {
-            return TRUE;
+    private static final PageHandler<Void, Boolean> NO_OP = new PageHandler<Void, Boolean>() {
+        @Override
+        public Boolean run(int cacheId, long pageId, long page, long pageAddr, PageIO io, Boolean walPlc,
+            Void arg,
+            int intArg) throws IgniteCheckedException {
+            return Boolean.TRUE;
         }
     };
 
     /**
-     * @param page Page.
-     * @param io IO.
+     * @param cacheId Cache ID.
+     * @param pageId Page ID.
+     * @param page Page absolute pointer.
      * @param pageAddr Page address.
+     * @param io IO.
+     * @param walPlc Full page WAL record policy.
      * @param arg Argument.
      * @param intArg Argument of type {@code int}.
      * @return Result.
      * @throws IgniteCheckedException If failed.
      */
-    public abstract R run(Page page, PageIO io, long pageAddr, X arg, int intArg)
+    public abstract R run(
+        int cacheId,
+        long pageId,
+        long page,
+        long pageAddr,
+        PageIO io,
+        Boolean walPlc,
+        X arg,
+        int intArg)
         throws IgniteCheckedException;
 
     /**
-     * @param page Page.
+     * @param cacheId Cache ID.
+     * @param pageId Page ID.
+     * @param page Page pointer.
+     * @param pageAddr Page address.
      * @param arg Argument.
      * @param intArg Argument of type {@code int}.
      * @return {@code true} If release.
      */
-    public boolean releaseAfterWrite(Page page, X arg, int intArg) {
+    public boolean releaseAfterWrite(
+        int cacheId,
+        long pageId,
+        long page,
+        long pageAddr,
+        X arg,
+        int intArg) {
         return true;
     }
 
     /**
-     * @param page Page.
-     * @param lockLsnr Lock listener.
+     * @param pageMem Page memory.
+     * @param cacheId Cache ID.
+     * @param pageId Page ID.
+     * @param lsnr Lock listener.
      * @param h Handler.
      * @param arg Argument.
      * @param intArg Argument of type {@code int}.
@@ -74,32 +97,40 @@ public abstract class PageHandler<X, R> {
      * @throws IgniteCheckedException If failed.
      */
     public static <X, R> R readPage(
-        Page page,
-        PageLockListener lockLsnr,
+        PageMemory pageMem,
+        int cacheId,
+        long pageId,
+        PageLockListener lsnr,
         PageHandler<X, R> h,
         X arg,
         int intArg,
         R lockFailed
     ) throws IgniteCheckedException {
-        long pageAddr = readLock(page, lockLsnr);
-
-        if (pageAddr == 0L)
-            return lockFailed;
-
+        long page = pageMem.acquirePage(cacheId, pageId);
         try {
-            PageIO io = PageIO.getPageIO(pageAddr);
-
-            return h.run(page, io, pageAddr, arg, intArg);
+            long pageAddr = readLock(pageMem, cacheId, pageId, page, lsnr);
+
+            if (pageAddr == 0L)
+                return lockFailed;
+            try {
+                PageIO io = PageIO.getPageIO(pageAddr);
+                return h.run(cacheId, pageId, page, pageAddr, io, null, arg, intArg);
+            }
+            finally {
+                readUnlock(pageMem, cacheId, pageId, page, pageAddr, lsnr);
+            }
         }
         finally {
-            readUnlock(page, pageAddr, lockLsnr);
+            pageMem.releasePage(cacheId, pageId, page);
         }
     }
 
     /**
      * @param pageMem Page memory.
-     * @param page Page.
-     * @param lockLsnr Lock listener.
+     * @param cacheId Cache ID.
+     * @param pageId Page ID.
+     * @param page Page pointer.
+     * @param lsnr Lock listener.
      * @param h Handler.
      * @param arg Argument.
      * @param intArg Argument of type {@code int}.
@@ -107,98 +138,177 @@ public abstract class PageHandler<X, R> {
      * @return Handler result.
      * @throws IgniteCheckedException If failed.
      */
-    public static <X, R> R writePage(
+    public static <X, R> R readPage(
         PageMemory pageMem,
-        Page page,
-        PageLockListener lockLsnr,
+        int cacheId,
+        long pageId,
+        long page,
+        PageLockListener lsnr,
         PageHandler<X, R> h,
         X arg,
         int intArg,
         R lockFailed
     ) throws IgniteCheckedException {
-        return writePage(pageMem, page, lockLsnr, h, null, null, arg, intArg, lockFailed);
+        long pageAddr = readLock(pageMem, cacheId, pageId, page, lsnr);
+
+        if (pageAddr == 0L)
+            return lockFailed;
+        try {
+            PageIO io = PageIO.getPageIO(pageAddr);
+            return h.run(cacheId, pageId, page, pageAddr, io, null, arg, intArg);
+        }
+        finally {
+            readUnlock(pageMem, cacheId, pageId, page, pageAddr, lsnr);
+        }
     }
 
     /**
      * @param pageMem Page memory.
-     * @param page Page.
-     * @param lockLsnr Lock listener.
-     * @param init IO for new page initialization or {@code null} if it is an existing page.
-     * @param wal WAL manager.
-     * @throws IgniteCheckedException If failed.
+     * @param cacheId Cache ID.
+     * @param pageId Page ID.
+     * @param page Page pointer.
+     * @param lsnr Lock listener.
+     * @return Page address.
      */
-    public static void initPage(
+    public static long readLock(
         PageMemory pageMem,
-        Page page,
-        PageLockListener lockLsnr,
-        PageIO init,
-        IgniteWriteAheadLogManager wal
-    ) throws IgniteCheckedException {
-        Boolean res = writePage(pageMem, page, lockLsnr, NOOP, init, wal, null, 0, FALSE);
+        int cacheId,
+        long pageId,
+        long page,
+        PageLockListener lsnr) {
+        boolean notifyLsnr = lsnr != null;
 
-        assert res == TRUE : res; // It must be newly allocated page, can't be recycled.
-    }
+        if(notifyLsnr)
+            lsnr.onBeforeReadLock(cacheId, pageId, page);
 
-    /**
-     * @param page Page.
-     * @param lockLsnr Lock listener.
-     * @return Page address or {@code 0} if failed to lock due to recycling.
-     */
-    public static long readLock(Page page, PageLockListener lockLsnr) {
-        lockLsnr.onBeforeReadLock(page);
-
-        long pageAddr = page.getForReadPointer();
+        long pageAddr = pageMem.readLock(cacheId, pageId, page);
 
-        lockLsnr.onReadLock(page, pageAddr);
+        if(notifyLsnr)
+            lsnr.onReadLock(cacheId, pageId, page, pageAddr);
 
         return pageAddr;
     }
 
     /**
-     * @param page Page.
-     * @param pageAddr Page address.
-     * @param lockLsnr Lock listener.
+     * @param pageMem Page memory.
+     * @param cacheId Cache ID.
+     * @param pageId Page ID.
+     * @param page Page pointer.
+     * @param pageAddr Page address (for-write pointer)
+     * @param lsnr Lock listener.
      */
-    public static void readUnlock(Page page, long pageAddr, PageLockListener lockLsnr) {
-        lockLsnr.onReadUnlock(page, pageAddr);
+    public static void readUnlock(
+        PageMemory pageMem,
+        int cacheId,
+        long pageId,
+        long page,
+        long pageAddr,
+        PageLockListener lsnr) {
+        if(lsnr != null)
+            lsnr.onReadUnlock(cacheId, pageId, page, pageAddr);
 
-        page.releaseRead();
+        pageMem.readUnlock(cacheId, pageId, page);
     }
 
     /**
-     * @param page Page.
-     * @param lockLsnr Lock listener.
-     * @param tryLock Only try to lock without waiting.
-     * @return Page address or {@code 0} if failed to lock due to recycling.
+     * @param pageMem Page memory.
+     * @param cacheId Cache ID.
+     * @param pageId Page ID.
+     * @param init IO for new page initialization.
+     * @param wal Write ahead log.
+     * @param lsnr Lock listener.
+     * @throws IgniteCheckedException If failed.
      */
-    public static long writeLock(Page page, PageLockListener lockLsnr, boolean tryLock) {
-        lockLsnr.onBeforeWriteLock(page);
-
-        long pageAddr = tryLock ? page.tryGetForWritePointer() : page.getForWritePointer();
-
-        lockLsnr.onWriteLock(page, pageAddr);
+    public static void initPage(
+        PageMemory pageMem,
+        int cacheId,
+        long pageId,
+        PageIO init,
+        IgniteWriteAheadLogManager wal,
+        PageLockListener lsnr
+    ) throws IgniteCheckedException {
+        Boolean res = writePage(pageMem, cacheId, pageId, lsnr, PageHandler.NO_OP, init, wal, null, null, 0, FALSE);
 
-        return pageAddr;
+        assert res != FALSE;
     }
 
     /**
-     * @param page Page.
-     * @param buf Page buffer.
-     * @param lockLsnr Lock listener.
-     * @param dirty Page is dirty.
+     * @param pageMem Page memory.
+     * @param cacheId Cache ID.
+     * @param pageId Page ID.
+     * @param lsnr Lock listener.
+     * @param h Handler.
+     * @param init IO for new page initialization or {@code null} if it is an existing page.
+     * @param wal Write ahead log.
+     * @param walPlc Full page WAL record policy.
+     * @param arg Argument.
+     * @param intArg Argument of type {@code int}.
+     * @param lockFailed Result in case of lock failure due to page recycling.
+     * @return Handler result.
+     * @throws IgniteCheckedException If failed.
      */
-    public static void writeUnlock(Page page, long buf, PageLockListener lockLsnr, boolean dirty) {
-        lockLsnr.onWriteUnlock(page, buf);
+    public static <X, R> R writePage(
+        PageMemory pageMem,
+        int cacheId,
+        long pageId,
+        PageLockListener lsnr,
+        PageHandler<X, R> h,
+        PageIO init,
+        IgniteWriteAheadLogManager wal,
+        Boolean walPlc,
+        X arg,
+        int intArg,
+        R lockFailed
+    ) throws IgniteCheckedException {
+        boolean releaseAfterWrite = true;
+        long page = pageMem.acquirePage(cacheId, pageId);
+        try {
+            long pageAddr = writeLock(pageMem, cacheId, pageId, page, lsnr, false);
 
-        page.releaseWrite(dirty);
+            if (pageAddr == 0L)
+                return lockFailed;
+
+            boolean ok = false;
+
+            try {
+                if (init != null) {
+                    // It is a new page and we have to initialize it.
+                    doInitPage(pageMem, cacheId, pageId, page, pageAddr, init, wal);
+                    walPlc = FALSE;
+                }
+                else {
+                    init = PageIO.getPageIO(pageAddr);
+                }
+
+                R res = h.run(cacheId, pageId, page, pageAddr, init, walPlc, arg, intArg);
+
+                ok = true;
+
+                return res;
+            }
+            finally {
+                assert PageIO.getCrc(pageAddr) == 0; //TODO GG-11480
+
+                if (releaseAfterWrite = h.releaseAfterWrite(cacheId, pageId, page, pageAddr, arg, intArg))
+                    writeUnlock(pageMem, cacheId, pageId, page, pageAddr, lsnr, walPlc, ok);
+            }
+        }
+        finally {
+            if(releaseAfterWrite)
+                pageMem.releasePage(cacheId, pageId, page);
+        }
     }
 
     /**
-     * @param page Page.
-     * @param lockLsnr Lock listener.
+     * @param pageMem Page memory.
+     * @param cacheId Cache ID.
+     * @param pageId Page ID.
+     * @param page Page pointer.
+     * @param lsnr Lock listener.
      * @param h Handler.
      * @param init IO for new page initialization or {@code null} if it is an existing page.
-     * @param wal WAL manager.
+     * @param wal Write ahead log.
+     * @param walPlc Full page WAL record policy.
      * @param arg Argument.
      * @param intArg Argument of type {@code int}.
      * @param lockFailed Result in case of lock failure due to page recycling.
@@ -207,47 +317,108 @@ public abstract class PageHandler<X, R> {
      */
     public static <X, R> R writePage(
         PageMemory pageMem,
-        Page page,
-        PageLockListener lockLsnr,
+        int cacheId,
+        long pageId,
+        long page,
+        PageLockListener lsnr,
         PageHandler<X, R> h,
         PageIO init,
         IgniteWriteAheadLogManager wal,
+        Boolean walPlc,
         X arg,
         int intArg,
         R lockFailed
     ) throws IgniteCheckedException {
-        long pageAddr = writeLock(page, lockLsnr, false);
+        long pageAddr = writeLock(pageMem, cacheId, pageId, page, lsnr, false);
 
         if (pageAddr == 0L)
             return lockFailed;
 
-        R res;
-
         boolean ok = false;
 
         try {
-            if (init != null) // It is a new page and we have to initialize it.
-                doInitPage(pageMem, page, pageAddr, init, wal);
-            else
+            if (init != null) {
+                // It is a new page and we have to initialize it.
+                doInitPage(pageMem, cacheId, pageId, page, pageAddr, init, wal);
+                walPlc = FALSE;
+            }
+            else {
                 init = PageIO.getPageIO(pageAddr);
+            }
 
-            res = h.run(page, init, pageAddr, arg, intArg);
+            R res = h.run(cacheId, pageId, page, pageAddr, init, walPlc, arg, intArg);
 
             ok = true;
+
+            return res;
         }
         finally {
             assert PageIO.getCrc(pageAddr) == 0; //TODO GG-11480
 
-            if (h.releaseAfterWrite(page, arg, intArg))
-                writeUnlock(page, pageAddr, lockLsnr, ok);
+            if (h.releaseAfterWrite(cacheId, pageId, page, pageAddr, arg, intArg))
+                writeUnlock(pageMem, cacheId, pageId, page, pageAddr, lsnr, walPlc, ok);
         }
+    }
 
-        return res;
+    /**
+     * @param pageMem Page memory.
+     * @param cacheId Cache ID.
+     * @param pageId Page ID.
+     * @param page Page pointer.
+     * @param pageAddr Page address.
+     * @param lsnr Lock listener.
+     * @param walPlc Full page WAL record policy.
+     * @param dirty Page is dirty.
+     */
+    public static void writeUnlock(
+        PageMemory pageMem,
+        int cacheId,
+        long pageId,
+        long page,
+        long pageAddr,
+        PageLockListener lsnr,
+        Boolean walPlc,
+        boolean dirty) {
+        if(lsnr != null)
+            lsnr.onWriteUnlock(cacheId, pageId, page, pageAddr);
+
+        pageMem.writeUnlock(cacheId, pageId, page, walPlc, dirty);
+    }
+
+    /**
+     * @param pageMem Page memory.
+     * @param cacheId Cache ID.
+     * @param pageId Page ID.
+     * @param page Page pointer.
+     * @param lsnr Lock listener.
+     * @param tryLock Only try to lock without waiting.
+     * @return Page address or {@code 0} if failed to lock due to recycling.
+     */
+    public static long writeLock(
+        PageMemory pageMem,
+        int cacheId,
+        long pageId,
+        long page,
+        PageLockListener lsnr,
+        boolean tryLock) {
+        boolean notifyLsnr = lsnr != null;
+
+        if(notifyLsnr)
+            lsnr.onBeforeWriteLock(cacheId, pageId, page);
+
+        long pageAddr = tryLock ? pageMem.tryWriteLock(cacheId, pageId, page) : pageMem.writeLock(cacheId, pageId, page);
+
+        if(notifyLsnr)
+            lsnr.onWriteLock(cacheId, pageId, page, pageAddr);
+
+        return pageAddr;
     }
 
     /**
      * @param pageMem Page memory.
-     * @param page Page.
+     * @param cacheId Cache ID.
+     * @param pageId Page ID.
+     * @param page Page pointer.
      * @param pageAddr Page address.
      * @param init Initial IO.
      * @param wal Write ahead log.
@@ -255,35 +426,43 @@ public abstract class PageHandler<X, R> {
      */
     private static void doInitPage(
         PageMemory pageMem,
-        Page page,
+        int cacheId,
+        long pageId,
+        long page,
         long pageAddr,
         PageIO init,
-        IgniteWriteAheadLogManager wal
-    ) throws IgniteCheckedException {
-        assert PageIO.getCrc(pageAddr) == 0; //TODO GG-11480
+        IgniteWriteAheadLogManager wal) throws IgniteCheckedException {
 
-        long pageId = page.id();
+        assert PageIO.getCrc(pageAddr) == 0; //TODO GG-11480
 
         init.initNewPage(pageAddr, pageId, pageMem.pageSize());
 
         // Here we should never write full page, because it is known to be new.
-        page.fullPageWalRecordPolicy(FALSE);
-
-        if (isWalDeltaRecordNeeded(wal, page))
-            wal.log(new InitNewPageRecord(page.fullId().cacheId(), page.id(),
+        if (isWalDeltaRecordNeeded(pageMem, cacheId, pageId, page, wal, FALSE))
+            wal.log(new InitNewPageRecord(cacheId, pageId,
                 init.getType(), init.getVersion(), pageId));
     }
 
     /**
+     * @param pageMem Page memory.
+     * @param cacheId Cache ID.
+     * @param pageId Page ID.
+     * @param page Page pointer.
      * @param wal Write ahead log.
-     * @param page Page.
+     * @param walPlc Full page WAL record policy.
      * @return {@code true} If we need to make a delta WAL record for the change in this page.
      */
-    public static boolean isWalDeltaRecordNeeded(IgniteWriteAheadLogManager wal, Page page) {
+    public static boolean isWalDeltaRecordNeeded(
+        PageMemory pageMem,
+        int cacheId,
+        long pageId,
+        long page,
+        IgniteWriteAheadLogManager wal,
+        Boolean walPlc) {
         // If the page is clean, then it is either newly allocated or just after checkpoint.
         // In both cases we have to write full page contents to WAL.
-        return wal != null && !wal.isAlwaysWriteFullPages() && page.fullPageWalRecordPolicy() != TRUE &&
-            (page.fullPageWalRecordPolicy() == FALSE || page.isDirty());
+        return wal != null && !wal.isAlwaysWriteFullPages() && walPlc != TRUE &&
+            (walPlc == FALSE || pageMem.isDirty(cacheId, pageId, page));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/37eed342/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageLockListener.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageLockListener.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageLockListener.java
index 07cdd43..904d217 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageLockListener.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageLockListener.java
@@ -17,43 +17,53 @@
 
 package org.apache.ignite.internal.processors.cache.database.tree.util;
 
-import org.apache.ignite.internal.pagemem.Page;
-
 /**
  * Page lock listener.
  */
 public interface PageLockListener {
     /**
-     * @param page Page.
+     * @param cacheId Cache ID.
+     * @param pageId Page ID.
+     * @param page Page pointer.
      */
-    public void onBeforeWriteLock(Page page);
+    public void onBeforeWriteLock(int cacheId, long pageId, long page);
 
     /**
-     * @param page Page.
-     * @param pageAddr Page address or {@code 0} if attempt to lock failed.
+     * @param cacheId Cache ID.
+     * @param pageId Page ID.
+     * @param page Page pointer.
+     * @param pageAddr Page address.
      */
-    public void onWriteLock(Page page, long pageAddr);
+    public void onWriteLock(int cacheId, long pageId, long page, long pageAddr);
 
     /**
-     * @param page Page.
+     * @param cacheId Cache ID.
+     * @param pageId Page ID.
+     * @param page Page pointer.
      * @param pageAddr Page address.
      */
-    public void onWriteUnlock(Page page, long pageAddr);
+    public void onWriteUnlock(int cacheId, long pageId, long page, long pageAddr);
 
     /**
-     * @param page Page.
+     * @param cacheId Cache ID.
+     * @param pageId Page ID.
+     * @param page Page pointer.
      */
-    public void onBeforeReadLock(Page page);
+    public void onBeforeReadLock(int cacheId, long pageId, long page);
 
     /**
-     * @param page Page.
-     * @param pageAddr Page address or {@code 0} if attempt to lock failed.
+     * @param cacheId Cache ID.
+     * @param pageId Page ID.
+     * @param page Page pointer.
+     * @param pageAddr Page address.
      */
-    public void onReadLock(Page page, long pageAddr);
+    public void onReadLock(int cacheId, long pageId, long page, long pageAddr);
 
     /**
-     * @param page Page.
+     * @param cacheId Cache ID.
+     * @param pageId Page ID.
+     * @param page Page pointer.
      * @param pageAddr Page address.
      */
-    public void onReadUnlock(Page page, long pageAddr);
+    public void onReadUnlock(int cacheId, long pageId, long page, long pageAddr);
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/37eed342/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
index bc1c584..a63cf1f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
@@ -2882,7 +2882,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
      * @param locked Locked entries.
      * @param topVer Topology version.
      */
-    private void unlockEntries(Collection<GridDhtCacheEntry> locked, AffinityTopologyVersion topVer) {
+    private void unlockEntries(List<GridDhtCacheEntry> locked, AffinityTopologyVersion topVer) {
         // Process deleted entries before locks release.
         assert ctx.deferredDelete() : this;
 
@@ -2890,8 +2890,11 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
         // Enqueue entries while holding locks.
         Collection<KeyCacheObject> skip = null;
 
+        int size = locked.size();
+
         try {
-            for (GridCacheMapEntry entry : locked) {
+            for (int i = 0; i < size; i++) {
+                GridCacheMapEntry entry = locked.get(i);
                 if (entry != null && entry.deleted()) {
                     if (skip == null)
                         skip = U.newHashSet(locked.size());
@@ -2904,27 +2907,30 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
             // At least RuntimeException can be thrown by the code above when GridCacheContext is cleaned and there is
             // an attempt to use cleaned resources.
             // That's why releasing locks in the finally block..
-            for (GridCacheMapEntry entry : locked) {
+            for (int i = 0; i < size; i++) {
+                GridCacheMapEntry entry = locked.get(i);
                 if (entry != null)
                     GridUnsafe.monitorExit(entry);
             }
         }
 
         // Try evict partitions.
-        for (GridDhtCacheEntry entry : locked) {
+        for (int i = 0; i < size; i++) {
+            GridDhtCacheEntry entry = locked.get(i);
             if (entry != null)
                 entry.onUnlock();
         }
 
         ctx.shared().database().checkpointReadUnlock();
 
-        if (skip != null && skip.size() == locked.size())
+        if (skip != null && skip.size() == size)
             // Optimization.
             return;
 
         // Must touch all entries since update may have deleted entries.
         // Eviction manager will remove empty entries.
-        for (GridCacheMapEntry entry : locked) {
+        for (int i = 0; i < size; i++) {
+            GridCacheMapEntry entry = locked.get(i);
             if (entry != null && (skip == null || !skip.contains(entry.key())))
                 ctx.evicts().touch(entry, topVer);
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/37eed342/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionManager.java
index 5a8904f..fe5f562 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionManager.java
@@ -38,6 +38,9 @@ import static org.apache.ignite.events.EventType.EVT_NODE_METRICS_UPDATED;
  * caches.
  */
 public class GridCacheVersionManager extends GridCacheSharedManagerAdapter {
+    /** */
+    public static final GridCacheVersion EVICT_VER = new GridCacheVersion(Integer.MAX_VALUE, 0, 0, 0);
+
     /** Timestamp used as base time for cache topology version (January 1, 2014). */
     public static final long TOP_VER_BASE_TIME = 1388520000000L;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/37eed342/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockDeltaSnapshot.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockDeltaSnapshot.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockDeltaSnapshot.java
index 1e675b6..36f2902 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockDeltaSnapshot.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockDeltaSnapshot.java
@@ -91,7 +91,7 @@ public class GridClockDeltaSnapshot {
      * @return Map of collected deltas.
      */
     public Map<UUID, Long> deltas() {
-        return Collections.unmodifiableMap(deltas);
+        return deltas;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/37eed342/modules/core/src/test/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoLoadSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoLoadSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoLoadSelfTest.java
index ec62c9b..8362ace 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoLoadSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoLoadSelfTest.java
@@ -26,7 +26,6 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.mem.DirectMemoryProvider;
 import org.apache.ignite.internal.mem.file.MappedFileMemoryProvider;
 import org.apache.ignite.internal.pagemem.FullPageId;
-import org.apache.ignite.internal.pagemem.Page;
 import org.apache.ignite.internal.pagemem.PageIdAllocator;
 import org.apache.ignite.internal.pagemem.PageIdUtils;
 import org.apache.ignite.internal.pagemem.PageMemory;
@@ -59,30 +58,31 @@ public class PageMemoryNoLoadSelfTest extends GridCommonAbstractTest {
             FullPageId fullId1 = allocatePage(mem);
             FullPageId fullId2 = allocatePage(mem);
 
-            Page page1 = mem.page(fullId1.cacheId(), fullId1.pageId());
+            long page1 = mem.acquirePage(fullId1.cacheId(), fullId1.pageId());
 
             try {
-                Page page2 = mem.page(fullId2.cacheId(), fullId2.pageId());
+                long page2 = mem.acquirePage(fullId2.cacheId(), fullId2.pageId());
 
-                info("Allocated pages [page1=" + page1 + ", page2=" + page2 + ']');
+                info("Allocated pages [page1Id=" + fullId1.pageId() + ", page1=" + page1 +
+                    ", page2Id=" + fullId2.pageId() + ", page2=" + page2 + ']');
 
                 try {
-                    writePage(page1, 1);
-                    writePage(page2, 2);
+                    writePage(mem, fullId1.pageId(), page1, 1);
+                    writePage(mem, fullId2.pageId(), page2, 2);
 
-                    readPage(page1, 1);
-                    readPage(page2, 2);
+                    readPage(mem, fullId1.pageId(), page1, 1);
+                    readPage(mem, fullId2.pageId(), page2, 2);
 
                     // Check read after read.
-                    readPage(page1, 1);
-                    readPage(page2, 2);
+                    readPage(mem, fullId1.pageId(), page1, 1);
+                    readPage(mem, fullId2.pageId(), page2, 2);
                 }
                 finally {
-                    mem.releasePage(page2);
+                    mem.releasePage(fullId2.cacheId(), fullId2.pageId(), page2);
                 }
             }
             finally {
-                mem.releasePage(page1);
+                mem.releasePage(fullId1.cacheId(), fullId1.pageId(), page1);
             }
         }
         finally {
@@ -108,32 +108,32 @@ public class PageMemoryNoLoadSelfTest extends GridCommonAbstractTest {
 
                 pages.add(fullId);
 
-                Page page = mem.page(fullId.cacheId(), fullId.pageId());
+                long page = mem.acquirePage(fullId.cacheId(), fullId.pageId());
 
                 try {
                     if (i % 64 == 0)
-                        info("Writing page [idx=" + i + ", page=" + page + ']');
+                        info("Writing page [idx=" + i + ", pageId=" + fullId.pageId() + ", page=" + page + ']');
 
-                    writePage(page, i + 1);
+                    writePage(mem, fullId.pageId(), page, i + 1);
                 }
                 finally {
-                    mem.releasePage(page);
+                    mem.releasePage(fullId.cacheId(), fullId.pageId(), page);
                 }
             }
 
             for (int i = 0; i < pagesCnt; i++) {
                 FullPageId fullId = pages.get(i);
 
-                Page page = mem.page(fullId.cacheId(), fullId.pageId());
+                long page = mem.acquirePage(fullId.cacheId(), fullId.pageId());
 
                 try {
                     if (i % 64 == 0)
-                        info("Reading page [idx=" + i + ", page=" + page + ']');
+                        info("Reading page [idx=" + i + ", pageId=" + fullId.pageId() + ", page=" + page + ']');
 
-                    readPage(page, i + 1);
+                    readPage(mem, fullId.pageId(), page, i + 1);
                 }
                 finally {
-                    mem.releasePage(page);
+                    mem.releasePage(fullId.cacheId(), fullId.pageId(), page);
                 }
             }
         }
@@ -188,70 +188,82 @@ public class PageMemoryNoLoadSelfTest extends GridCommonAbstractTest {
 
             // Check that initial pages are accessible.
             for (FullPageId id : old) {
-                try (Page page = mem.page(id.cacheId(), id.pageId())) {
-                    long buf = page.getForWritePointer();
+                long pageApsPtr = mem.acquirePage(id.cacheId(), id.pageId());
+                try {
+                    long pageAddr = mem.writeLock(id.cacheId(), id.pageId(), pageApsPtr);
 
-                    assertNotNull(buf);
+                    assertNotNull(pageAddr);
 
                     try {
                         long updId = PageIdUtils.rotatePageId(id.pageId());
 
-                        PageIO.setPageId(buf, updId);
+                        PageIO.setPageId(pageAddr, updId);
 
                         updated.add(new FullPageId(updId, id.cacheId()));
                     }
                     finally {
-                        page.releaseWrite(true);
+                        mem.writeUnlock(id.cacheId(), id.pageId(), pageApsPtr, null, true);
                     }
                 }
+                finally {
+                    mem.releasePage(id.cacheId(), id.pageId(), pageApsPtr);
+                }
             }
 
             // Check that updated pages are inaccessible using old IDs.
             for (FullPageId id : old) {
-                try (Page page = mem.page(id.cacheId(), id.pageId())) {
-                    long pageAddr = page.getForWritePointer();
+                long pageApsPtr = mem.acquirePage(id.cacheId(), id.pageId());
+                try {
+                    long pageAddr = mem.writeLock(id.cacheId(), id.pageId(), pageApsPtr);
 
                     if (pageAddr != 0L) {
-                        page.releaseWrite(false);
+                        mem.writeUnlock(id.cacheId(), id.pageId(), pageApsPtr, null, false);
 
                         fail("Was able to acquire page write lock.");
                     }
 
-                    pageAddr = page.getForReadPointer();
+                    mem.readLock(id.cacheId(), id.pageId(), pageApsPtr);
 
                     if (pageAddr != 0) {
-                        page.releaseRead();
+                        mem.readUnlock(id.cacheId(), id.pageId(), pageApsPtr);
 
                         fail("Was able to acquire page read lock.");
                     }
                 }
+                finally {
+                    mem.releasePage(id.cacheId(), id.pageId(), pageApsPtr);
+                }
             }
 
             // Check that updated pages are accessible using new IDs.
             for (FullPageId id : updated) {
-                try (Page page = mem.page(id.cacheId(), id.pageId())) {
-                    long buf = page.getForWritePointer();
+                long pageApsPtr = mem.acquirePage(id.cacheId(), id.pageId());
+                try {
+                    long pageAddr = mem.writeLock(id.cacheId(), id.pageId(), pageApsPtr);
 
-                    assertNotNull(buf);
+                    assertNotSame(0L, pageAddr);
 
                     try {
-                        assertEquals(id.pageId(), PageIO.getPageId(buf));
+                        assertEquals(id.pageId(), PageIO.getPageId(pageAddr));
                     }
                     finally {
-                        page.releaseWrite(false);
+                        mem.writeUnlock(id.cacheId(), id.pageId(), pageApsPtr, null, false);
                     }
 
-                    buf = page.getForReadPointer();
+                    pageAddr = mem.readLock(id.cacheId(), id.pageId(), pageApsPtr);
 
-                    assertNotNull(buf);
+                    assertNotSame(0L, pageAddr);
 
                     try {
-                        assertEquals(id.pageId(), PageIO.getPageId(buf));
+                        assertEquals(id.pageId(), PageIO.getPageId(pageAddr));
                     }
                     finally {
-                        page.releaseRead();
+                        mem.readUnlock(id.cacheId(), id.pageId(), pageApsPtr);
                     }
                 }
+                finally {
+                    mem.releasePage(id.cacheId(), id.pageId(), pageApsPtr);
+                }
             }
         }
         finally {
@@ -261,6 +273,7 @@ public class PageMemoryNoLoadSelfTest extends GridCommonAbstractTest {
 
     /**
      * @return Page memory implementation.
+     * @throws Exception If failed.
      */
     protected PageMemory memory() throws Exception {
         File memDir = U.resolveWorkDirectory(U.defaultWorkDirectory(), "pagemem", false);
@@ -277,31 +290,35 @@ public class PageMemoryNoLoadSelfTest extends GridCommonAbstractTest {
     }
 
     /**
-     * @param page Page to write.
+     * @param mem Page memory.
+     * @param pageId Page ID.
+     * @param page Page pointer.
      * @param val Value to write.
      */
-    private void writePage(Page page, int val) {
-        long bytes = page.getForWritePointer();
+    private void writePage(PageMemory mem, long pageId, long page, int val) {
+        long pageAddr = mem.writeLock(-1, pageId, page);
 
         try {
-            PageIO.setPageId(bytes, page.id());
+            PageIO.setPageId(pageAddr, pageId);
 
             for (int i = PageIO.COMMON_HEADER_END; i < PAGE_SIZE; i++)
-                PageUtils.putByte(bytes, i, (byte)val);
+                PageUtils.putByte(pageAddr, i, (byte)val);
         }
         finally {
-            page.releaseWrite(true);
+            mem.writeUnlock(-1, pageId, page, null, true);
         }
     }
 
     /**
-     * @param page Page to read.
+     * @param mem Page memory.
+     * @param pageId Page ID.
+     * @param page Page pointer.
      * @param expVal Expected value.
      */
-    private void readPage(Page page, int expVal) {
+    private void readPage(PageMemory mem, long pageId, long page, int expVal) {
         expVal &= 0xFF;
 
-        long pageAddr = page.getForReadPointer();
+        long pageAddr = mem.readLock(-1, pageId, page);
 
         assert(pageAddr != 0);
 
@@ -313,13 +330,14 @@ public class PageMemoryNoLoadSelfTest extends GridCommonAbstractTest {
             }
         }
         finally {
-            page.releaseRead();
+            mem.readUnlock(-1, pageId, page);
         }
     }
 
     /**
      * @param mem Memory.
      * @return Page.
+     * @throws IgniteCheckedException If failed.
      */
     public static FullPageId allocatePage(PageIdAllocator mem) throws IgniteCheckedException {
         return new FullPageId(mem.allocatePage(-1, 1, PageIdAllocator.FLAG_DATA), -1);

http://git-wip-us.apache.org/repos/asf/ignite/blob/37eed342/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeReuseSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeReuseSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeReuseSelfTest.java
index 5f38bb0..e5375f7 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeReuseSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeReuseSelfTest.java
@@ -20,7 +20,6 @@ package org.apache.ignite.internal.processors.database;
 import java.util.HashSet;
 import java.util.Set;
 import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.pagemem.Page;
 import org.apache.ignite.internal.pagemem.PageMemory;
 import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager;
 import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO;
@@ -85,44 +84,44 @@ public class BPlusTreeReuseSelfTest extends BPlusTreeSelfTest {
         }
 
         /** {@inheritDoc} */
-        @Override public void onBeforeReadLock(Page page) {
+        @Override public void onBeforeReadLock(int cacheId, long pageId, long page) {
             // No-op.
         }
 
         /** {@inheritDoc} */
-        @Override public void onReadLock(Page page, long pageAddr) {
-            checkPageId(page, pageAddr);
+        @Override public void onReadLock(int cacheId, long pageId, long page, long pageAddr) {
+            checkPageId(pageId, pageAddr);
 
-            assertTrue(readLocks.get().add(page.id()));
+            assertTrue(readLocks.get().add(pageId));
         }
 
         /** {@inheritDoc} */
-        @Override public void onReadUnlock(Page page, long pageAddr) {
-            checkPageId(page, pageAddr);
+        @Override public void onReadUnlock(int cacheId, long pageId, long page, long pageAddr) {
+            checkPageId(pageId, pageAddr);
 
-            assertTrue(readLocks.get().remove(page.id()));
+            assertTrue(readLocks.get().remove(pageId));
         }
 
         /** {@inheritDoc} */
-        @Override public void onBeforeWriteLock(Page page) {
+        @Override public void onBeforeWriteLock(int cacheId, long pageId, long page) {
             // No-op.
         }
 
         /** {@inheritDoc} */
-        @Override public void onWriteLock(Page page, long pageAddr) {
+        @Override public void onWriteLock(int cacheId, long pageId, long page, long pageAddr) {
             if (pageAddr == 0L)
                 return; // Failed to lock.
 
-            checkPageId(page, pageAddr);
+            checkPageId(pageId, pageAddr);
 
-            assertTrue(writeLocks.get().add(page.id()));
+            assertTrue(writeLocks.get().add(pageId));
         }
 
         /** {@inheritDoc} */
-        @Override public void onWriteUnlock(Page page, long pageAddr) {
-            assertEquals(effectivePageId(page.id()), effectivePageId(PageIO.getPageId(pageAddr)));
+        @Override public void onWriteUnlock(int cacheId, long pageId, long page, long pageAddr) {
+            assertEquals(effectivePageId(pageId), effectivePageId(PageIO.getPageId(pageAddr)));
 
-            assertTrue(writeLocks.get().remove(page.id()));
+            assertTrue(writeLocks.get().remove(pageId));
         }
 
         static boolean checkNoLocks() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/37eed342/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java
index 9a90c1d..4c6fe4c 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java
@@ -34,7 +34,6 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider;
 import org.apache.ignite.internal.pagemem.FullPageId;
-import org.apache.ignite.internal.pagemem.Page;
 import org.apache.ignite.internal.pagemem.PageIdAllocator;
 import org.apache.ignite.internal.pagemem.PageMemory;
 import org.apache.ignite.internal.pagemem.PageUtils;
@@ -152,27 +151,30 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
     @Override protected void afterTest() throws Exception {
         rnd = null;
 
-        if (reuseList != null) {
-            long size = reuseList.recycledPagesCount();
-
-            assertTrue("Reuse size: " + size, size < 7000);
-        }
+        try {
+            if (reuseList != null) {
+                long size = reuseList.recycledPagesCount();
 
-        for (int i = 0; i < 10; i++) {
-            if (acquiredPages() != 0) {
-                System.out.println("!!!");
-                U.sleep(10);
+                assertTrue("Reuse size: " + size, size < 7000);
             }
-        }
 
-        assertEquals(0, acquiredPages());
+            for (int i = 0; i < 10; i++) {
+                if (acquiredPages() != 0) {
+                    System.out.println("!!!");
+                    U.sleep(10);
+                }
+            }
 
-        pageMem.stop();
+            assertEquals(0, acquiredPages());
+        }
+        finally {
+            pageMem.stop();
 
-        MAX_PER_PAGE = 0;
-        PUT_INC = 1;
-        RMV_INC = -1;
-        CNT = 10;
+            MAX_PER_PAGE = 0;
+            PUT_INC = 1;
+            RMV_INC = -1;
+            CNT = 10;
+        }
     }
 
     /**
@@ -1381,15 +1383,15 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
     }
 
     /**
-     * @param page Page.
+     * @param pageId Page ID.
      * @param pageAddr Page address.
      */
-    public static void checkPageId(Page page, long pageAddr) {
-        long pageId = PageIO.getPageId(pageAddr);
+    public static void checkPageId(long pageId, long pageAddr) {
+        long actual = PageIO.getPageId(pageAddr);
 
         // Page ID must be 0L for newly allocated page, for reused page effective ID must remain the same.
-        if (pageId != 0L && page.id() != pageId)
-            throw new IllegalStateException("Page ID: " + U.hexLong(pageId));
+        if (actual != 0L && pageId != actual)
+            throw new IllegalStateException("Page ID: " + U.hexLong(actual));
     }
 
     /**
@@ -1493,74 +1495,74 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
         }
 
         /** {@inheritDoc} */
-        @Override public void onBeforeReadLock(Page page) {
+        @Override public void onBeforeReadLock(int cacheId, long pageId, long page) {
 //            X.println("  onBeforeReadLock: " + U.hexLong(page.id()));
 //
 //            U.dumpStack();
 
-            assertNull(beforeReadLock.put(threadId(), page.id()));
+            assertNull(beforeReadLock.put(threadId(), pageId));
         }
 
         /** {@inheritDoc} */
-        @Override public void onReadLock(Page page, long pageAddr) {
+        @Override public void onReadLock(int cacheId, long pageId, long page, long pageAddr) {
 //            X.println("  onReadLock: " + U.hexLong(page.id()));
 
             if (pageAddr != 0L) {
-                long pageId = PageIO.getPageId(pageAddr);
+                long actual = PageIO.getPageId(pageAddr);
 
-                checkPageId(page, pageAddr);
+                checkPageId(pageId, pageAddr);
 
-                assertNull(locks(true).put(page.id(), pageId));
+                assertNull(locks(true).put(pageId, actual));
             }
 
-            assertEquals(Long.valueOf(page.id()), beforeReadLock.remove(threadId()));
+            assertEquals(Long.valueOf(pageId), beforeReadLock.remove(threadId()));
         }
 
         /** {@inheritDoc} */
-        @Override public void onReadUnlock(Page page, long pageAddr) {
+        @Override public void onReadUnlock(int cacheId, long pageId, long page, long pageAddr) {
 //            X.println("  onReadUnlock: " + U.hexLong(page.id()));
 
-            checkPageId(page, pageAddr);
+            checkPageId(pageId, pageAddr);
 
-            long pageId = PageIO.getPageId(pageAddr);
+            long actual = PageIO.getPageId(pageAddr);
 
-            assertEquals(Long.valueOf(pageId), locks(true).remove(page.id()));
+            assertEquals(Long.valueOf(actual), locks(true).remove(pageId));
         }
 
         /** {@inheritDoc} */
-        @Override public void onBeforeWriteLock(Page page) {
+        @Override public void onBeforeWriteLock(int cacheId, long pageId, long page) {
 //            X.println("  onBeforeWriteLock: " + U.hexLong(page.id()));
 
-            assertNull(beforeWriteLock.put(threadId(), page.id()));
+            assertNull(beforeWriteLock.put(threadId(), pageId));
         }
 
         /** {@inheritDoc} */
-        @Override public void onWriteLock(Page page, long pageAddr) {
+        @Override public void onWriteLock(int cacheId, long pageId, long page, long pageAddr) {
 //            X.println("  onWriteLock: " + U.hexLong(page.id()));
 //
 //            U.dumpStack();
 
             if (pageAddr != 0L) {
-                checkPageId(page, pageAddr);
+                checkPageId(pageId, pageAddr);
 
-                long pageId = PageIO.getPageId(pageAddr);
+                long actual = PageIO.getPageId(pageAddr);
 
-                if (pageId == 0L)
-                    pageId = page.id(); // It is a newly allocated page.
+                if (actual == 0L)
+                    actual = pageId; // It is a newly allocated page.
 
-                assertNull(locks(false).put(page.id(), pageId));
+                assertNull(locks(false).put(pageId, actual));
             }
 
-            assertEquals(Long.valueOf(page.id()), beforeWriteLock.remove(threadId()));
+            assertEquals(Long.valueOf(pageId), beforeWriteLock.remove(threadId()));
         }
 
         /** {@inheritDoc} */
-        @Override public void onWriteUnlock(Page page, long pageAddr) {
+        @Override public void onWriteUnlock(int cacheId, long pageId, long page, long pageAddr) {
 //            X.println("  onWriteUnlock: " + U.hexLong(page.id()));
 
-            assertEquals(effectivePageId(page.id()), effectivePageId(PageIO.getPageId(pageAddr)));
+            assertEquals(effectivePageId(pageId), effectivePageId(PageIO.getPageId(pageAddr)));
 
-            assertEquals(Long.valueOf(page.id()), locks(false).remove(page.id()));
+            assertEquals(Long.valueOf(pageId), locks(false).remove(pageId));
         }
 
         /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/37eed342/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java
index 842f035..d7f5b29 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java
@@ -21,7 +21,6 @@ import java.util.Comparator;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicLong;
 import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.pagemem.Page;
 import org.apache.ignite.internal.pagemem.PageMemory;
 import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager;
 import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree;
@@ -136,10 +135,11 @@ public abstract class H2Tree extends BPlusTree<SearchRow, GridH2Row> {
      * @throws IgniteCheckedException If failed.
      */
     private int getMetaInlineSize() throws IgniteCheckedException {
-        try (Page meta = page(metaPageId)) {
-            long pageAddr = readLock(meta); // Meta can't be removed.
+        final long metaPage = acquirePage(metaPageId);
+        try {
+            long pageAddr = readLock(metaPageId, metaPage); // Meta can't be removed.
 
-            assert pageAddr != 0 : "Failed to read lock meta page [page=" + meta + ", metaPageId=" +
+            assert pageAddr != 0 : "Failed to read lock meta page [metaPageId=" +
                 U.hexLong(metaPageId) + ']';
 
             try {
@@ -148,9 +148,12 @@ public abstract class H2Tree extends BPlusTree<SearchRow, GridH2Row> {
                 return io.getInlineSize(pageAddr);
             }
             finally {
-                readUnlock(meta, pageAddr);
+                readUnlock(metaPageId, metaPage, pageAddr);
             }
         }
+        finally {
+            releasePage(metaPageId, metaPage);
+        }
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/37eed342/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/database/InlineIndexHelperTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/database/InlineIndexHelperTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/database/InlineIndexHelperTest.java
index bcbca1a..2e6ec34 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/database/InlineIndexHelperTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/database/InlineIndexHelperTest.java
@@ -25,8 +25,6 @@ import java.util.UUID;
 import junit.framework.TestCase;
 import org.apache.commons.io.Charsets;
 import org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider;
-import org.apache.ignite.internal.pagemem.FullPageId;
-import org.apache.ignite.internal.pagemem.Page;
 import org.apache.ignite.internal.pagemem.PageIdAllocator;
 import org.apache.ignite.internal.pagemem.PageMemory;
 import org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl;
@@ -144,12 +142,14 @@ public class InlineIndexHelperTest extends TestCase {
             false);
 
         pageMem.start();
-        Page page = null;
+
+        long pageId = 0L;
+        long page = 0L;
 
         try {
-            FullPageId fullId = new FullPageId(pageMem.allocatePage(CACHE_ID, 1, PageIdAllocator.FLAG_DATA), CACHE_ID);
-            page = pageMem.page(fullId.cacheId(), fullId.pageId());
-            long pageAddr = page.getForReadPointer();
+            pageId = pageMem.allocatePage(CACHE_ID, 1, PageIdAllocator.FLAG_DATA);
+            page = pageMem.acquirePage(CACHE_ID, pageId);
+            long pageAddr = pageMem.readLock(CACHE_ID, pageId, page);
 
             int off = 0;
 
@@ -167,8 +167,8 @@ public class InlineIndexHelperTest extends TestCase {
             assertEquals("aaa", ih.get(pageAddr, off, 3 + 5).getString());
         }
         finally {
-            if (page != null)
-                pageMem.releasePage(page);
+            if (page != 0L)
+                pageMem.releasePage(CACHE_ID, pageId, page);
             pageMem.stop();
         }
     }
@@ -187,12 +187,14 @@ public class InlineIndexHelperTest extends TestCase {
             false);
 
         pageMem.start();
-        Page page = null;
+
+        long pageId = 0L;
+        long page = 0L;
 
         try {
-            FullPageId fullId = new FullPageId(pageMem.allocatePage(CACHE_ID, 1, PageIdAllocator.FLAG_DATA), CACHE_ID);
-            page = pageMem.page(fullId.cacheId(), fullId.pageId());
-            long pageAddr = page.getForReadPointer();
+            pageId = pageMem.allocatePage(CACHE_ID, 1, PageIdAllocator.FLAG_DATA);
+            page = pageMem.acquirePage(CACHE_ID, pageId);
+            long pageAddr = pageMem.readLock(CACHE_ID, pageId, page);
 
             int off = 0;
 
@@ -211,8 +213,8 @@ public class InlineIndexHelperTest extends TestCase {
             assertTrue(Arrays.equals(new byte[] {1, 2, 3, 4, 5}, ih.get(pageAddr, off, 3 + 5).getBytes()));
         }
         finally {
-            if (page != null)
-                pageMem.releasePage(page);
+            if (page != 0L)
+                pageMem.releasePage(CACHE_ID, pageId, page);
             pageMem.stop();
         }
     }
@@ -306,12 +308,14 @@ public class InlineIndexHelperTest extends TestCase {
             false);
 
         pageMem.start();
-        Page page = null;
+
+        long pageId = 0L;
+        long page = 0L;
 
         try {
-            FullPageId fullId = new FullPageId(pageMem.allocatePage(CACHE_ID, 1, PageIdAllocator.FLAG_DATA), CACHE_ID);
-            page = pageMem.page(fullId.cacheId(), fullId.pageId());
-            long pageAddr = page.getForReadPointer();
+            pageId = pageMem.allocatePage(CACHE_ID, 1, PageIdAllocator.FLAG_DATA);
+            page = pageMem.acquirePage(CACHE_ID, pageId);
+            long pageAddr = pageMem.readLock(CACHE_ID, pageId, page);
 
             int off = 0;
             int max = 255;
@@ -329,8 +333,8 @@ public class InlineIndexHelperTest extends TestCase {
             assertEquals(v2.getObject(), v22.getObject());
         }
         finally {
-            if (page != null)
-                pageMem.releasePage(page);
+            if (page != 0L)
+                pageMem.releasePage(CACHE_ID, pageId, page);
             pageMem.stop();
         }
     }


Mime
View raw message