ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [04/16] ignite git commit: ignite-db - get rid of extra abstract methods
Date Wed, 04 May 2016 06:01:42 GMT
ignite-db - get rid of extra abstract methods


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

Branch: refs/heads/ignite-db-x-10884
Commit: 2272d97c8ba3bbf1086f8905841bc6d6a2bed80f
Parents: d52ca95
Author: S.Vladykin <svladykin@gridgain.com>
Authored: Thu Apr 28 06:16:12 2016 +0300
Committer: S.Vladykin <svladykin@gridgain.com>
Committed: Thu Apr 28 06:16:12 2016 +0300

----------------------------------------------------------------------
 .../cache/database/freelist/FreeTree.java       | 25 +--------
 .../cache/database/tree/BPlusTree.java          | 34 +++++++++--
 .../cache/database/tree/io/IOVersions.java      | 15 ++++-
 .../cache/database/tree/reuse/ReuseTree.java    | 25 +--------
 .../processors/query/h2/database/H2Tree.java    | 25 +--------
 .../processors/database/BPlusTreeSelfTest.java  | 59 ++------------------
 6 files changed, 53 insertions(+), 130 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/2272d97c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/FreeTree.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/FreeTree.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/FreeTree.java
index 17f047e..682b7c0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/FreeTree.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/freelist/FreeTree.java
@@ -26,9 +26,6 @@ import org.apache.ignite.internal.processors.cache.database.freelist.io.FreeInne
 import org.apache.ignite.internal.processors.cache.database.freelist.io.FreeLeafIO;
 import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree;
 import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO;
-import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusInnerIO;
-import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusLeafIO;
-import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO;
 import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList;
 
 /**
@@ -48,7 +45,7 @@ public class FreeTree extends BPlusTree<FreeItem, FreeItem> {
      */
     public FreeTree(ReuseList reuseList, int cacheId, int partId, PageMemory pageMem, FullPageId
metaPageId, boolean initNew)
         throws IgniteCheckedException {
-        super(cacheId, pageMem, metaPageId, reuseList);
+        super(cacheId, pageMem, metaPageId, reuseList, FreeInnerIO.VERSIONS, FreeLeafIO.VERSIONS);
 
         this.partId = partId;
 
@@ -66,26 +63,6 @@ public class FreeTree extends BPlusTree<FreeItem, FreeItem> {
     }
 
     /** {@inheritDoc} */
-    @Override protected BPlusIO<FreeItem> io(int type, int ver) {
-        if (type == PageIO.T_FREE_INNER)
-            return FreeInnerIO.VERSIONS.forVersion(ver);
-
-        assert type == PageIO.T_FREE_LEAF: type;
-
-        return FreeLeafIO.VERSIONS.forVersion(ver);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected BPlusInnerIO<FreeItem> latestInnerIO() {
-        return FreeInnerIO.VERSIONS.latest();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected BPlusLeafIO<FreeItem> latestLeafIO() {
-        return FreeLeafIO.VERSIONS.latest();
-    }
-
-    /** {@inheritDoc} */
     @Override protected int compare(BPlusIO<FreeItem> io, ByteBuffer buf, int idx,
FreeItem row)
         throws IgniteCheckedException {
         int res = Short.compare(((FreeIO)io).getFreeSpace(buf, idx), row.freeSpace());

http://git-wip-us.apache.org/repos/asf/ignite/blob/2272d97c/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 e4001e0..42bab88 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
@@ -37,6 +37,7 @@ import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO;
 import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusInnerIO;
 import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusLeafIO;
 import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusMetaIO;
+import org.apache.ignite.internal.processors.cache.database.tree.io.IOVersions;
 import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO;
 import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseBag;
 import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList;
@@ -86,6 +87,12 @@ public abstract class BPlusTree<L, T extends L> {
     private final long metaPageId;
 
     /** */
+    private final IOVersions<? extends BPlusInnerIO<L>> innerIos;
+
+    /** */
+    private final IOVersions<? extends BPlusLeafIO<L>> leafIos;
+
+    /** */
     private final AtomicLong globalRmvId = new AtomicLong(U.currentTimeMillis() * 1000_000);
// TODO init from WAL?
 
     /** */
@@ -534,16 +541,23 @@ public abstract class BPlusTree<L, T extends L> {
      * @param pageMem Page memory.
      * @param metaPageId Meta page ID.
      * @param reuseList Reuse list.
+     * @param innerIos Inner IO versions.
+     * @param leafIos Leaf IO versions.
      * @throws IgniteCheckedException If failed.
      */
-    public BPlusTree(int cacheId, PageMemory pageMem, FullPageId metaPageId, ReuseList reuseList)
+    public BPlusTree(int cacheId, PageMemory pageMem, FullPageId metaPageId, ReuseList reuseList,
+        IOVersions<? extends BPlusInnerIO<L>> innerIos, IOVersions<? extends
BPlusLeafIO<L>> leafIos)
         throws IgniteCheckedException {
         // TODO make configurable: 0 <= minFill <= maxFill <= 1
         minFill = 0f; // Testing worst case when merge happens only on empty page.
         maxFill = 0f; // Avoiding random effects on testing.
 
         assert pageMem != null;
+        assert innerIos != null;
+        assert leafIos != null;
 
+        this.innerIos = innerIos;
+        this.leafIos = leafIos;
         this.pageMem = pageMem;
         this.cacheId = cacheId;
         this.metaPageId = metaPageId.pageId();
@@ -2514,17 +2528,29 @@ public abstract class BPlusTree<L, T extends L> {
      * @param ver Page version.
      * @return IO.
      */
-    protected abstract BPlusIO<L> io(int type, int ver);
+    private BPlusIO<L> io(int type, int ver) {
+        if (innerIos.getType() == type)
+            return innerIos.forVersion(ver);
+
+        if (leafIos.getType() != type)
+            throw new IllegalStateException("Unknown page type: " + type);
+
+        return leafIos.forVersion(ver);
+    }
 
     /**
      * @return Latest version of inner page IO.
      */
-    protected abstract BPlusInnerIO<L> latestInnerIO();
+    private BPlusInnerIO<L> latestInnerIO() {
+        return innerIos.latest();
+    }
 
     /**
      * @return Latest version of leaf page IO.
      */
-    protected abstract BPlusLeafIO<L> latestLeafIO();
+    private BPlusLeafIO<L> latestLeafIO() {
+        return leafIos.latest();
+    }
 
     /**
      * @param buf Buffer.

http://git-wip-us.apache.org/repos/asf/ignite/blob/2272d97c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/IOVersions.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/IOVersions.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/IOVersions.java
index 2699104..ec2c7bd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/IOVersions.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/IOVersions.java
@@ -26,6 +26,9 @@ public final class IOVersions<V extends PageIO> {
     /** */
     private final V[] vers;
 
+    /** */
+    private final int type;
+
     /**
      * @param vers Versions.
      */
@@ -35,16 +38,26 @@ public final class IOVersions<V extends PageIO> {
         assert vers.length > 0;
 
         this.vers = vers;
+        this.type = vers[0].getType();
 
         assert checkVersions();
     }
 
     /**
+     * @return Type.
+     */
+    public int getType() {
+        return type;
+    }
+
+    /**
      * @return {@code true} If versions are correct.
      */
     private boolean checkVersions() {
         for (int i = 0; i < vers.length; i++) {
-            if (vers[i].getVersion() != i + 1)
+            V v = vers[i];
+
+            if (v.getType() != type || v.getVersion() != i + 1)
                 return false;
         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2272d97c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseTree.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseTree.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseTree.java
index e7e6a1b..c6793b6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseTree.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/reuse/ReuseTree.java
@@ -24,9 +24,6 @@ import org.apache.ignite.internal.pagemem.PageIdUtils;
 import org.apache.ignite.internal.pagemem.PageMemory;
 import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree;
 import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO;
-import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusInnerIO;
-import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusLeafIO;
-import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO;
 import org.apache.ignite.internal.processors.cache.database.tree.reuse.io.ReuseInnerIO;
 import org.apache.ignite.internal.processors.cache.database.tree.reuse.io.ReuseLeafIO;
 
@@ -44,33 +41,13 @@ public final class ReuseTree extends BPlusTree<FullPageId, FullPageId>
{
      */
     public ReuseTree(ReuseList reuseList, int cacheId, PageMemory pageMem, FullPageId metaPageId,
boolean initNew)
         throws IgniteCheckedException {
-        super(cacheId, pageMem, metaPageId, reuseList);
+        super(cacheId, pageMem, metaPageId, reuseList, ReuseInnerIO.VERSIONS, ReuseLeafIO.VERSIONS);
 
         if (initNew)
             initNew();
     }
 
     /** {@inheritDoc} */
-    @Override protected BPlusIO<FullPageId> io(int type, int ver) {
-        if (type == PageIO.T_REUSE_INNER)
-            return ReuseInnerIO.VERSIONS.forVersion(ver);
-
-        assert type == PageIO.T_REUSE_LEAF: type;
-
-        return ReuseLeafIO.VERSIONS.forVersion(ver);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected BPlusInnerIO<FullPageId> latestInnerIO() {
-        return ReuseInnerIO.VERSIONS.latest();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected BPlusLeafIO<FullPageId> latestLeafIO() {
-        return ReuseLeafIO.VERSIONS.latest();
-    }
-
-    /** {@inheritDoc} */
     @Override protected int compare(BPlusIO<FullPageId> io, ByteBuffer buf, int idx,
FullPageId fullPageId)
         throws IgniteCheckedException {
         long pageIdx = io.isLeaf() ?

http://git-wip-us.apache.org/repos/asf/ignite/blob/2272d97c/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 07f437a..2e60c06 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
@@ -6,9 +6,6 @@ import org.apache.ignite.internal.pagemem.FullPageId;
 import org.apache.ignite.internal.pagemem.PageMemory;
 import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree;
 import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO;
-import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusInnerIO;
-import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusLeafIO;
-import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO;
 import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList;
 import org.apache.ignite.internal.processors.query.h2.database.io.H2InnerIO;
 import org.apache.ignite.internal.processors.query.h2.database.io.H2LeafIO;
@@ -38,7 +35,7 @@ public abstract class H2Tree extends BPlusTree<SearchRow, GridH2Row>
{
         FullPageId metaPageId,
         boolean initNew
     ) throws IgniteCheckedException {
-        super(cacheId, pageMem, metaPageId, reuseList);
+        super(cacheId, pageMem, metaPageId, reuseList, H2InnerIO.VERSIONS, H2LeafIO.VERSIONS);
 
         assert rowStore != null;
 
@@ -56,26 +53,6 @@ public abstract class H2Tree extends BPlusTree<SearchRow, GridH2Row>
{
     }
 
     /** {@inheritDoc} */
-    @Override protected BPlusIO<SearchRow> io(int type, int ver) {
-        if (type == PageIO.T_H2_REF_INNER)
-            return H2InnerIO.VERSIONS.forVersion(ver);
-
-        assert type == PageIO.T_H2_REF_LEAF: type;
-
-        return H2LeafIO.VERSIONS.forVersion(ver);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected BPlusInnerIO<SearchRow> latestInnerIO() {
-        return H2InnerIO.VERSIONS.latest();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected BPlusLeafIO<SearchRow> latestLeafIO() {
-        return H2LeafIO.VERSIONS.latest();
-    }
-
-    /** {@inheritDoc} */
     @Override protected GridH2Row getRow(BPlusIO<SearchRow> io, ByteBuffer buf, int
idx)
         throws IgniteCheckedException {
         return (GridH2Row)io.getLookupRow(this, buf, idx);

http://git-wip-us.apache.org/repos/asf/ignite/blob/2272d97c/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java
index a8b5cf3..4a1d2ed 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java
@@ -32,6 +32,7 @@ import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree;
 import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusIO;
 import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusInnerIO;
 import org.apache.ignite.internal.processors.cache.database.tree.io.BPlusLeafIO;
+import org.apache.ignite.internal.processors.cache.database.tree.io.IOVersions;
 import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList;
 import org.apache.ignite.internal.util.lang.GridCursor;
 import org.apache.ignite.internal.util.typedef.T2;
@@ -553,10 +554,8 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
         /** */
         static Random rnd;
 
-        /** */
-        final boolean canGetRow;
-
         /**
+         * @param reuseList Reuse list.
          * @param canGetRow Can get row from inner page.
          * @param cacheId Cache ID.
          * @param pageMem Page memory.
@@ -565,9 +564,8 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
          */
         public TestTree(ReuseList reuseList, boolean canGetRow, int cacheId, PageMemory pageMem,
FullPageId metaPageId)
             throws IgniteCheckedException {
-            super(cacheId, pageMem, metaPageId, reuseList);
-
-            this.canGetRow = canGetRow;
+            super(cacheId, pageMem, metaPageId, reuseList,
+                new IOVersions<>(new LongInnerIO(canGetRow)), new IOVersions<>(new
LongLeafIO()));
 
             initNew();
         }
@@ -579,42 +577,6 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
         }
 
         /** {@inheritDoc} */
-        @Override protected BPlusIO<Long> io(int type, int ver) {
-            BPlusIO<Long> io = io(type);
-
-            assert io.getVersion() == ver: ver;
-
-            return io;
-        }
-
-        /**
-         * @param type Type.
-         * @return IO.
-         */
-        private BPlusIO<Long> io(int type) {
-            switch (type) {
-                case LONG_INNER_IO:
-                    return latestInnerIO();
-
-                case LONG_LEAF_IO:
-                    return latestLeafIO();
-
-                default:
-                    throw new IllegalStateException("type: " + type);
-            }
-        }
-
-        /** {@inheritDoc} */
-        @Override protected BPlusInnerIO<Long> latestInnerIO() {
-            return canGetRow ? LongInnerIO.INSTANCE1 : LongInnerIO.INSTANCE0;
-        }
-
-        /** {@inheritDoc} */
-        @Override protected BPlusLeafIO<Long> latestLeafIO() {
-            return LongLeafIO.INSTANCE;
-        }
-
-        /** {@inheritDoc} */
         @Override protected int compare(BPlusIO<Long> io, ByteBuffer buf, int idx,
Long n2)
             throws IgniteCheckedException {
             Long n1 = io.getLookupRow(this, buf, idx);
@@ -635,16 +597,10 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
      * Long inner.
      */
     private static final class LongInnerIO extends BPlusInnerIO<Long> {
-        /** */
-        static final LongInnerIO INSTANCE0 = new LongInnerIO(false);
-
-        /** */
-        static final LongInnerIO INSTANCE1 = new LongInnerIO(true);
-
         /**
          */
         protected LongInnerIO(boolean canGetRow) {
-            super(LONG_INNER_IO, 302, canGetRow, 8);
+            super(LONG_INNER_IO, 1, canGetRow, 8);
         }
 
         /** {@inheritDoc} */
@@ -677,13 +633,10 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
      * Long leaf.
      */
     private static final class LongLeafIO extends BPlusLeafIO<Long> {
-        /** */
-        static final LongLeafIO INSTANCE = new LongLeafIO();
-
         /**
          */
         protected LongLeafIO() {
-            super(LONG_LEAF_IO, 603, 8);
+            super(LONG_LEAF_IO, 1, 8);
         }
 
         /** {@inheritDoc} */


Mime
View raw message