ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [39/50] [abbrv] ignite git commit: ignite-db - more changes
Date Tue, 19 Apr 2016 12:58:56 GMT
ignite-db - more changes


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

Branch: refs/heads/ignite-db-x-10884
Commit: 3a7e3772e7e877ca10f1999aa2b81830e83a8509
Parents: adbcfba
Author: S.Vladykin <svladykin@gridgain.com>
Authored: Thu Apr 14 19:48:50 2016 +0300
Committer: S.Vladykin <svladykin@gridgain.com>
Committed: Thu Apr 14 19:48:50 2016 +0300

----------------------------------------------------------------------
 .../database/IgniteCacheH2DatabaseManager.java  |   6 +-
 .../query/h2/database/H2RowStore.java           |  31 +++++-
 .../query/h2/database/freelist/FreeList.java    | 105 +++++++++++++++++--
 3 files changed, 124 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/3a7e3772/modules/indexing/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheH2DatabaseManager.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheH2DatabaseManager.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheH2DatabaseManager.java
index d910ff2..72c0c3f 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheH2DatabaseManager.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheH2DatabaseManager.java
@@ -20,8 +20,8 @@ package org.apache.ignite.internal.processors.cache.database;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.pagemem.FullPageId;
 import org.apache.ignite.internal.processors.cache.GridCacheManagerAdapter;
-import org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex;
 import org.apache.ignite.internal.processors.query.h2.database.H2RowStore;
+import org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex;
 import org.apache.ignite.internal.processors.query.h2.opt.GridH2Table;
 import org.apache.ignite.lang.IgniteBiTuple;
 import org.h2.index.Index;
@@ -92,8 +92,6 @@ public class IgniteCacheH2DatabaseManager extends GridCacheManagerAdapter
implem
      * @return New row store for the given table.
      */
     public H2RowStore createRowStore(GridH2Table tbl) {
-        IgniteCacheDatabaseSharedManager dbMgr = cctx.shared().database();
-
-        return new H2RowStore(dbMgr.pageMemory(), tbl.rowDescriptor(), cctx);
+        return new H2RowStore(tbl.rowDescriptor(), cctx, null); // new FreeList(cctx));
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/3a7e3772/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2RowStore.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2RowStore.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2RowStore.java
index 376ffdd..835e359 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2RowStore.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2RowStore.java
@@ -28,6 +28,7 @@ import org.apache.ignite.internal.pagemem.PageMemory;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.CacheObjectContext;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.query.h2.database.freelist.FreeList;
 import org.apache.ignite.internal.processors.cache.database.tree.io.DataPageIO;
 import org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
@@ -44,6 +45,9 @@ import static org.apache.ignite.internal.processors.cache.database.tree.util.Pag
  */
 public class H2RowStore {
     /** */
+    private final FreeList freeList;
+
+    /** */
     private final PageMemory pageMem;
 
     /** */
@@ -63,7 +67,9 @@ public class H2RowStore {
         @Override public int run(Page page, ByteBuffer buf, GridH2Row row, int ignore) throws
IgniteCheckedException {
             DataPageIO io = DataPageIO.VERSIONS.forPage(buf);
 
-            int idx = io.addRow(coctx, buf, row.key, row.val, row.ver);
+            int entrySize = DataPageIO.entrySize(coctx, row.key, row.val);
+
+            int idx = io.addRow(coctx, buf, row.key, row.val, row.ver, entrySize);
 
             if (idx != -1) {
                 row.link = linkFromDwordOffset(page.id(), idx);
@@ -76,15 +82,19 @@ public class H2RowStore {
     };
 
     /**
-     * @param pageMem Page memory.
      * @param rowDesc Row descriptor.
      * @param cctx Cache context.
      */
-    public H2RowStore(PageMemory pageMem, GridH2RowDescriptor rowDesc, GridCacheContext<?,?>
cctx) {
-        this.pageMem = pageMem;
+    public H2RowStore(GridH2RowDescriptor rowDesc, GridCacheContext<?,?> cctx, FreeList
freeList) {
+        assert rowDesc != null;
+        assert cctx != null;
+
         this.rowDesc = rowDesc;
         this.cctx = cctx;
-        this.coctx = cctx.cacheObjectContext();
+        this.freeList = freeList;
+
+        coctx = cctx.cacheObjectContext();
+        pageMem = cctx.shared().database().pageMemory();
     }
 
     /**
@@ -192,6 +202,17 @@ public class H2RowStore {
      * @param row Row.
      */
     public void writeRowData(GridH2Row row) throws IgniteCheckedException {
+        if (freeList == null)
+            writeRowData0(row);
+        else
+            freeList.writeRowData(row);
+    }
+
+    /**
+     * @param row Row.
+     * @throws IgniteCheckedException If failed.
+     */
+    private void writeRowData0(GridH2Row row) throws IgniteCheckedException {
         assert row.link == 0;
 
         while (row.link == 0) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/3a7e3772/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/freelist/FreeList.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/freelist/FreeList.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/freelist/FreeList.java
index 4fc7629..25c94da 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/freelist/FreeList.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/freelist/FreeList.java
@@ -17,15 +17,23 @@
 
 package org.apache.ignite.internal.processors.query.h2.database.freelist;
 
+import java.nio.ByteBuffer;
 import java.util.concurrent.ThreadLocalRandom;
 import org.apache.ignite.IgniteCheckedException;
 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.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.database.tree.io.DataPageIO;
+import org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler;
+import org.apache.ignite.internal.processors.query.h2.opt.GridH2Row;
 import org.apache.ignite.internal.util.future.GridFutureAdapter;
 import org.apache.ignite.lang.IgniteBiTuple;
 import org.jsr166.ConcurrentHashMap8;
 
+import static org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler.writePage;
+
 /**
  * Free data page list.
  */
@@ -39,6 +47,20 @@ public class FreeList {
     /** */
     private final ConcurrentHashMap8<Integer,GridFutureAdapter<FreeTree>> trees
= new ConcurrentHashMap8<>();
 
+    /** */
+    private final PageHandler<GridH2Row> writeRow = new PageHandler<GridH2Row>()
{
+        @Override public int run(Page page, ByteBuffer buf, GridH2Row row, int entrySize)
+            throws IgniteCheckedException {
+            DataPageIO io = DataPageIO.VERSIONS.forPage(buf);
+
+            int idx = io.addRow(cctx.cacheObjectContext(), buf, row.key, row.val, row.ver,
entrySize);
+
+            assert idx >= 0;
+
+            return io.getFreeSpace(buf);
+        }
+    };
+
     /**
      * @param cctx Cache context.
      */
@@ -53,19 +75,14 @@ public class FreeList {
     }
 
     /**
-     * @param part Partition.
+     * @param tree Tree.
      * @param neededSpace Needed free space.
-     * @return Page ID or {@code null} if it was impossible to find one.
+     * @return Free item or {@code null} if it was impossible to find one.
      * @throws IgniteCheckedException If failed.
      */
-    public FullPageId take(int part, short neededSpace) throws IgniteCheckedException {
-        assert part >= 0: part;
+    private FreeItem take(FreeTree tree, short neededSpace) throws IgniteCheckedException
{
         assert neededSpace > 0 && neededSpace < Short.MAX_VALUE: neededSpace;
 
-        FreeTree tree = tree(part);
-
-        assert tree != null;
-
         FreeItem res = tree.removeCeil(new FreeItem(neededSpace, dispersion(), 0, 0));
 
         assert res == null || (res.pageId() != 0 && res.cacheId() == cctx.cacheId()):
res;
@@ -86,9 +103,11 @@ public class FreeList {
      * @throws IgniteCheckedException If failed.
      */
     private FreeTree tree(Integer part) throws IgniteCheckedException {
+        assert part >= 0 && part < Short.MAX_VALUE: part;
+
         GridFutureAdapter<FreeTree> fut = trees.get(part);
 
-        if (fut != null) {
+        if (fut == null) {
             fut = new GridFutureAdapter<>();
 
             if (trees.putIfAbsent(part, fut) != null)
@@ -106,4 +125,72 @@ public class FreeList {
 
         return fut.get();
     }
+
+    /**
+     * @param row Row.
+     * @throws IgniteCheckedException If failed.
+     */
+    public void writeRowData(GridH2Row row) throws IgniteCheckedException {
+        assert row.link == 0;
+
+        int entrySize = DataPageIO.entrySize(cctx.cacheObjectContext(), row.key, row.val);
+
+        assert entrySize > 0 && entrySize < Short.MAX_VALUE: entrySize;
+
+        FreeTree tree = tree(row.partId);
+        FreeItem item = take(tree, (short)entrySize);
+
+        Page page = null;
+        int freeSpace = -1;
+
+        try {
+            if (item == null) {
+                DataPageIO io = DataPageIO.VERSIONS.latest();
+
+                page = allocatePage(row.partId);
+
+                ByteBuffer buf = page.getForInitialWrite();
+
+                io.initNewPage(buf, page.id());
+
+                freeSpace = writeRow.run(page, buf, row, entrySize);
+            }
+            else {
+                page = pageMem.page(item);
+
+                freeSpace = writePage(page, writeRow, row, entrySize, -1);
+            }
+        }
+        finally {
+            if (page != null) {
+                page.close();
+
+                if (freeSpace != -1) { // Put back to the tree.
+                    assert freeSpace >= 0 && freeSpace < Short.MAX_VALUE: freeSpace;
+
+                    if (item == null)
+                        item = new FreeItem((short)freeSpace, dispersion(), page.id(), cctx.cacheId());
+                    else {
+                        item.freeSpace((short)freeSpace);
+                        item.dispersion(dispersion());
+                    }
+
+                    FreeItem old = tree.put(item);
+
+                    assert old == null;
+                }
+            }
+        }
+    }
+
+    /**
+     * @param part Partition.
+     * @return Page.
+     * @throws IgniteCheckedException If failed.
+     */
+    private Page allocatePage(int part) throws IgniteCheckedException {
+        FullPageId pageId = pageMem.allocatePage(cctx.cacheId(), part, PageIdAllocator.FLAG_DATA);
+
+        return pageMem.page(pageId);
+    }
 }


Mime
View raw message