ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [09/50] [abbrv] ignite git commit: ignite-db-x - minor refactor
Date Mon, 10 Oct 2016 12:13:05 GMT
ignite-db-x -  minor refactor


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

Branch: refs/heads/ignite-gg-8-io2-selNow
Commit: f5dd4b0604e2bcf390d7c947d80eea2ec8199d82
Parents: 86925b1
Author: Sergi Vladykin <sergi.vladykin@gmail.com>
Authored: Mon Sep 26 22:27:51 2016 +0300
Committer: Sergi Vladykin <sergi.vladykin@gmail.com>
Committed: Mon Sep 26 22:27:51 2016 +0300

----------------------------------------------------------------------
 .../cache/database/DataStructure.java           | 18 ++-------
 .../cache/database/tree/util/PageHandler.java   | 41 ++++++++++++++------
 2 files changed, 34 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/f5dd4b06/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 4dd31e7..2242863 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
@@ -136,13 +136,7 @@ public abstract class DataStructure implements PageLockListener {
      * @return Buffer.
      */
     protected final ByteBuffer tryWriteLock(Page page) {
-        onBeforeWriteLock(page);
-
-        ByteBuffer buf = page.tryGetForWrite();
-
-        onWriteLock(page, buf);
-
-        return buf;
+        return PageHandler.writeLock(page, this, true);
     }
 
 
@@ -151,7 +145,7 @@ public abstract class DataStructure implements PageLockListener {
      * @return Buffer.
      */
     protected final ByteBuffer writeLock(Page page) {
-        return PageHandler.writeLock(page, this);
+        return PageHandler.writeLock(page, this, false);
     }
 
     /**
@@ -160,9 +154,7 @@ public abstract class DataStructure implements PageLockListener {
      * @param dirty Dirty page.
      */
     protected final void writeUnlock(Page page, ByteBuffer buf, boolean dirty) {
-        onWriteUnlock(page, buf);
-
-        page.releaseWrite(dirty);
+        PageHandler.writeUnlock(page, buf, this, dirty);
     }
 
     /**
@@ -178,9 +170,7 @@ public abstract class DataStructure implements PageLockListener {
      * @param buf Buffer.
      */
     protected final void readUnlock(Page page, ByteBuffer buf) {
-        onReadUnlock(page, buf);
-
-        page.releaseRead();
+        PageHandler.readUnlock(page, buf, this);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/f5dd4b06/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 8fbe1af..38a52c8 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
@@ -91,9 +91,7 @@ public abstract class PageHandler<X, R> {
             return h.run(page, io, buf, arg, intArg);
         }
         finally {
-            lockListener.onReadUnlock(page, buf);
-
-            page.releaseRead();
+            readUnlock(page, buf, lockListener);
         }
     }
 
@@ -151,13 +149,25 @@ public abstract class PageHandler<X, R> {
 
     /**
      * @param page Page.
+     * @param buf Page buffer.
+     * @param lockListener Lock listener.
+     */
+    public static void readUnlock(Page page, ByteBuffer buf, PageLockListener lockListener)
{
+        lockListener.onReadUnlock(page, buf);
+
+        page.releaseRead();
+    }
+
+    /**
+     * @param page Page.
      * @param lockListener Lock listener.
+     * @param tryLock Only try to lock without waiting.
      * @return Byte buffer or {@code null} if failed to lock due to recycling.
      */
-    public static ByteBuffer writeLock(Page page, PageLockListener lockListener) {
+    public static ByteBuffer writeLock(Page page, PageLockListener lockListener, boolean
tryLock) {
         lockListener.onBeforeWriteLock(page);
 
-        ByteBuffer buf = page.getForWrite();
+        ByteBuffer buf = tryLock ? page.tryGetForWrite() : page.getForWrite();
 
         lockListener.onWriteLock(page, buf);
 
@@ -166,6 +176,18 @@ public abstract class PageHandler<X, R> {
 
     /**
      * @param page Page.
+     * @param buf Page buffer.
+     * @param lockListener Lock listener.
+     * @param dirty Page is dirty.
+     */
+    public static void writeUnlock(Page page, ByteBuffer buf, PageLockListener lockListener,
boolean dirty) {
+        lockListener.onWriteUnlock(page, buf);
+
+        page.releaseWrite(dirty);
+    }
+
+    /**
+     * @param page Page.
      * @param lockListener Lock listener.
      * @param h Handler.
      * @param init IO for new page initialization or {@code null} if it is an existing page.
@@ -185,7 +207,7 @@ public abstract class PageHandler<X, R> {
         int intArg,
         R lockFailed
     ) throws IgniteCheckedException {
-        ByteBuffer buf = writeLock(page, lockListener);
+        ByteBuffer buf = writeLock(page, lockListener, false);
 
         if (buf == null)
             return lockFailed;
@@ -207,11 +229,8 @@ public abstract class PageHandler<X, R> {
         finally {
             assert PageIO.getCrc(buf) == 0; //TODO GG-11480
 
-            if (h.releaseAfterWrite(page, arg, intArg)) {
-                lockListener.onWriteUnlock(page, buf);
-
-                page.releaseWrite(ok);
-            }
+            if (h.releaseAfterWrite(page, arg, intArg))
+                writeUnlock(page, buf, lockListener, ok);
         }
 
         return res;


Mime
View raw message