ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [03/16] ignite git commit: ignite-db - minor refactor
Date Wed, 04 May 2016 06:01:41 GMT
ignite-db - minor refactor


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

Branch: refs/heads/ignite-db-x-10884
Commit: d52ca95b922480c398b4c3a5820a3da38464d9e0
Parents: fa320c9
Author: S.Vladykin <svladykin@gridgain.com>
Authored: Wed Apr 27 22:03:57 2016 +0300
Committer: S.Vladykin <svladykin@gridgain.com>
Committed: Wed Apr 27 22:03:57 2016 +0300

----------------------------------------------------------------------
 .../processors/cache/database/RowStore.java     |  4 +--
 .../cache/database/freelist/FreeList.java       |  4 +--
 .../cache/database/tree/BPlusTree.java          | 36 +++++++++++---------
 .../cache/database/tree/util/PageHandler.java   | 19 ++++-------
 4 files changed, 30 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d52ca95b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/RowStore.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/RowStore.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/RowStore.java
index a66e9dd..fa55322 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/RowStore.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/RowStore.java
@@ -133,7 +133,7 @@ public class RowStore<T extends CacheDataRow> {
 
         if (freeList == null) {
             try (Page page = page(pageId(link))) {
-                writePage(page, rmvRow, null, dwordsOffset(link), 0);
+                writePage(page, rmvRow, null, dwordsOffset(link));
             }
         }
         else
@@ -186,7 +186,7 @@ public class RowStore<T extends CacheDataRow> {
                 pageId = nextDataPage(0, row.partition());
 
             try (Page page = page(pageId)) {
-                if (writePage(page, writeRow, row, -1, -1) >= 0)
+                if (writePage(page, writeRow, row, -1) >= 0)
                     return; // Successful write.
             }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/d52ca95b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/FreeList.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/FreeList.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/FreeList.java
index 4665b6f..3d09316 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/FreeList.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/FreeList.java
@@ -176,7 +176,7 @@ public class FreeList {
         FreeTree tree = tree(partId);
 
         try (Page page = pageMem.page(new FullPageId(pageId, cctx.cacheId()))) {
-            writePage(page, removeRow, tree, itemId, -1);
+            writePage(page, removeRow, tree, itemId);
         }
     }
 
@@ -210,7 +210,7 @@ public class FreeList {
                 writeRow.run(page, buf, row, entrySize);
             }
             else
-                writePage(page, writeRow, row, entrySize, -1);
+                writePage(page, writeRow, row, entrySize);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/d52ca95b/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 ea53991..e4001e0 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
@@ -494,7 +494,7 @@ public abstract class BPlusTree<L, T extends L> {
 
     /** */
     private final PageHandler<Long> updateFirst = new PageHandler<Long>() {
-        @Override public int run(Page page, ByteBuffer buf, Long pageId, int lvl) throws
IgniteCheckedException {
+        @Override public int run(Page meta, ByteBuffer buf, Long pageId, int lvl) throws
IgniteCheckedException {
             assert pageId != null;
 
             BPlusMetaIO io = BPlusMetaIO.VERSIONS.forPage(buf);
@@ -515,7 +515,7 @@ public abstract class BPlusTree<L, T extends L> {
 
     /** */
     private final PageHandler<Long> newRoot = new PageHandler<Long>() {
-        @Override public int run(Page page, ByteBuffer buf, Long rootPageId, int lvl) throws
IgniteCheckedException {
+        @Override public int run(Page meta, ByteBuffer buf, Long rootPageId, int lvl) throws
IgniteCheckedException {
             assert rootPageId != null;
 
             BPlusMetaIO io = BPlusMetaIO.VERSIONS.forPage(buf);
@@ -715,7 +715,7 @@ public abstract class BPlusTree<L, T extends L> {
                 g.pageId = pageId;
                 g.fwdId = fwdId;
 
-                int res = readPage(page, search, g, lvl, Get.RETRY);
+                int res = readPage(page, search, g, lvl);
 
                 switch (res) {
                     case Get.GO_DOWN:
@@ -938,7 +938,7 @@ public abstract class BPlusTree<L, T extends L> {
                 r.fwdId = fwdId;
                 r.backId = backId;
 
-                int res = readPage(page, search, r, lvl, Remove.RETRY);
+                int res = readPage(page, search, r, lvl);
 
                 switch (res) {
                     case Remove.GO_DOWN_X:
@@ -1266,7 +1266,7 @@ public abstract class BPlusTree<L, T extends L> {
                     inner(io).setRight(newRootBuf, 0, fwd.id());
                 }
 
-                int res = writePage(meta, newRoot, newRootId, lvl + 1, FALSE);
+                int res = writePage(meta, newRoot, newRootId, lvl + 1);
 
                 assert res == TRUE : "failed to update meta page";
 
@@ -1324,7 +1324,7 @@ public abstract class BPlusTree<L, T extends L> {
      */
     private int askNeighbor(long pageId, Get g, boolean back) throws IgniteCheckedException
{
         try (Page page = page(pageId)) {
-            return readPage(page, askNeighbor, g, back ? TRUE : FALSE, Get.RETRY);
+            return readPage(page, askNeighbor, g, back ? TRUE : FALSE);
         }
     }
 
@@ -1348,7 +1348,7 @@ public abstract class BPlusTree<L, T extends L> {
                 p.pageId = pageId;
                 p.fwdId = fwdId;
 
-                int res = readPage(page, search, p, lvl, Put.RETRY);
+                int res = readPage(page, search, p, lvl);
 
                 switch (res) {
                     case Put.GO_DOWN:
@@ -1361,7 +1361,7 @@ public abstract class BPlusTree<L, T extends L> {
                         if (p.needReplaceInner == TRUE) {
                             p.needReplaceInner = FALSE; // Protect from retries.
 
-                            res = writePage(page, replace, p, lvl, Put.RETRY);
+                            res = writePage(page, replace, p, lvl);
 
                             if (res != Put.FOUND)
                                 return res; // Need to retry.
@@ -1387,7 +1387,7 @@ public abstract class BPlusTree<L, T extends L> {
                         p.pageId = pageId;
                         p.fwdId = fwdId;
 
-                        return writePage(page, replace, p, lvl, Put.RETRY);
+                        return writePage(page, replace, p, lvl);
 
                     case Put.NOT_FOUND: // Do insert.
                         assert lvl == p.btmLvl : "must insert at the bottom level";
@@ -1397,7 +1397,7 @@ public abstract class BPlusTree<L, T extends L> {
                         p.pageId = pageId;
                         p.fwdId = fwdId;
 
-                        return writePage(page, insert, p, lvl, Put.RETRY);
+                        return writePage(page, insert, p, lvl);
 
                     default:
                         return res;
@@ -1789,7 +1789,7 @@ public abstract class BPlusTree<L, T extends L> {
                 else {
                     assert freePages instanceof FullPageId;
 
-                    queue = new ArrayDeque<>();
+                    queue = new ArrayDeque<>(8);
 
                     queue.add(freePages);
                     freePages = queue;
@@ -1955,7 +1955,7 @@ public abstract class BPlusTree<L, T extends L> {
             Page back = page(backId);
 
             try {
-                return writePage(back, lockBackAndRemoveFromLeaf, this, 0, Remove.RETRY);
+                return writePage(back, lockBackAndRemoveFromLeaf, this, 0);
             }
             finally {
                 if (canRelease(back, 0))
@@ -1971,7 +1971,7 @@ public abstract class BPlusTree<L, T extends L> {
         private int doRemoveFromLeaf() throws IgniteCheckedException {
             assert page != null;
 
-            return writePage(page, removeFromLeaf, this, 0, Remove.RETRY);
+            return writePage(page, removeFromLeaf, this, 0);
         }
 
         /**
@@ -1982,7 +1982,7 @@ public abstract class BPlusTree<L, T extends L> {
         private int doLockTail(int lvl) throws IgniteCheckedException {
             assert page != null;
 
-            return writePage(page, lockTail, this, lvl, Remove.RETRY);
+            return writePage(page, lockTail, this, lvl);
         }
 
         /**
@@ -2008,7 +2008,7 @@ public abstract class BPlusTree<L, T extends L> {
             Page back = page(backId);
 
             try {
-                return writePage(back, lockBackAndTail, this, lvl, Remove.RETRY);
+                return writePage(back, lockBackAndTail, this, lvl);
             }
             finally {
                 if (canRelease(back, lvl))
@@ -2024,7 +2024,7 @@ public abstract class BPlusTree<L, T extends L> {
             assert fwdId != 0;
             assert backId == 0;
 
-            int res = writePage(page(fwdId), lockTailForward, this, lvl, Remove.RETRY);
+            int res = writePage(page(fwdId), lockTailForward, this, lvl);
 
             // Must always be called from lock on back page, thus we should never fail here.
             assert res == Remove.FOUND: res;
@@ -2133,7 +2133,9 @@ public abstract class BPlusTree<L, T extends L> {
                 // This logic will handle root as well.
                 long fwdId = io.getForward(buf);
 
-                writePage(meta, updateFirst, fwdId, lvl, FALSE);
+                int res = writePage(meta, updateFirst, fwdId, lvl);
+
+                assert res == TRUE: res;
             }
 
             // Mark removed.

http://git-wip-us.apache.org/repos/asf/ignite/blob/d52ca95b/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 d16fa9a..f70d13d 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
@@ -22,8 +22,8 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.pagemem.Page;
 
 /**
- * Page handler. Can do {@link #readPage(Page, PageHandler, Object, int, int)}
- * and {@link #writePage(Page, PageHandler, Object, int, int)} operations.
+ * Page handler. Can do {@link #readPage(Page, PageHandler, Object, int)}
+ * and {@link #writePage(Page, PageHandler, Object, int)} operations.
  */
 public abstract class PageHandler<X> {
     /**
@@ -51,14 +51,12 @@ public abstract class PageHandler<X> {
      * @param h Handler.
      * @param arg Argument.
      * @param intArg Argument of type {@code int}.
-     * @param dfltRes Default result in case of page invalidation.
      * @return Handler result.
      * @throws IgniteCheckedException If failed.
      */
-    public static <X> int readPage(Page page, PageHandler<X> h, X arg, int intArg,
int dfltRes)
+    public static <X> int readPage(Page page, PageHandler<X> h, X arg, int intArg)
         throws IgniteCheckedException {
-        if (page == null)
-            return dfltRes;
+        assert page != null;
 
         ByteBuffer buf = page.getForRead();
 
@@ -77,14 +75,12 @@ public abstract class PageHandler<X> {
      * @param h Handler.
      * @param arg Argument.
      * @param intArg Argument of type {@code int}.
-     * @param dfltRes Default result in case of page invalidation.
      * @return Handler result.
      * @throws IgniteCheckedException If failed.
      */
-    public static <X> int writePage(Page page, PageHandler<X> h, X arg, int intArg,
int dfltRes)
+    public static <X> int writePage(Page page, PageHandler<X> h, X arg, int intArg)
         throws IgniteCheckedException {
-        if (page == null)
-            return dfltRes; // TODO drop dfltRes parameter and assert not null
+        assert page != null;
 
         int res;
 
@@ -92,8 +88,7 @@ public abstract class PageHandler<X> {
 
         ByteBuffer buf = page.getForWrite();
 
-        if (buf == null)
-            return dfltRes; // TODO ---//---
+        assert buf != null;
 
         try {
             res = h.run(page, buf, arg, intArg);


Mime
View raw message