ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject ignite git commit: ignite-sql-opt
Date Tue, 24 Nov 2015 17:14:36 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-sql-opt 9a06c5df7 -> 17c0b4f58


ignite-sql-opt


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

Branch: refs/heads/ignite-sql-opt
Commit: 17c0b4f58edb0ae15e23c058bd3fe6ddd996749a
Parents: 9a06c5d
Author: sboikov <sboikov@gridgain.com>
Authored: Tue Nov 24 19:48:06 2015 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Tue Nov 24 20:12:22 2015 +0300

----------------------------------------------------------------------
 .../processors/query/h2/opt/GridH2Table.java    |  10 +-
 .../query/h2/opt/GridH2TreeIndex.java           | 104 ++++++++++---------
 .../h2/GridIndexingSpiAbstractSelfTest.java     |  17 ++-
 3 files changed, 78 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/17c0b4f5/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
index bf318b2..df4d031 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
@@ -54,6 +54,7 @@ import org.h2.table.TableFilter;
 import org.h2.value.Value;
 import org.jetbrains.annotations.Nullable;
 import org.jsr166.ConcurrentHashMap8;
+import org.jsr166.LongAdder8;
 
 import static org.apache.ignite.internal.processors.query.h2.opt.GridH2AbstractKeyValueRow.VAL_COL;
 
@@ -79,6 +80,9 @@ public class GridH2Table extends TableBase {
     /** */
     private volatile Object[] actualSnapshot;
 
+    /** */
+    private final LongAdder8 size = new LongAdder8();
+
     /**
      * Creates table.
      *
@@ -379,6 +383,8 @@ public class GridH2Table extends TableBase {
 
                     kvOld.onUnswap(kvOld.getValue(VAL_COL), true);
                 }
+                else if (old == null)
+                    size.increment();
 
                 int len = idxs.size();
 
@@ -414,6 +420,8 @@ public class GridH2Table extends TableBase {
                 }
 
                 if (old != null) {
+                    size.decrement();
+
                     // Remove row from all indexes.
                     // Start from 2 because 0 - Scan (don't need to update), 1 - PK (already
updated).
                     for (int i = 2, len = idxs.size(); i < len; i++) {
@@ -579,7 +587,7 @@ public class GridH2Table extends TableBase {
 
     /** {@inheritDoc} */
     @Override public long getRowCountApproximation() {
-        return getUniqueIndex().getRowCountApproximation();
+        return size.longValue();
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/17c0b4f5/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java
index 6012645..53cb10b 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java
@@ -42,7 +42,6 @@ import org.h2.table.IndexColumn;
 import org.h2.table.TableFilter;
 import org.h2.value.Value;
 import org.jetbrains.annotations.Nullable;
-import org.jsr166.LongAdder8;
 
 /**
  * Base class for snapshotable tree indexes.
@@ -56,9 +55,6 @@ public class GridH2TreeIndex extends GridH2IndexBase implements Comparator<GridS
     private final ThreadLocal<ConcurrentNavigableMap<GridSearchRowPointer, GridH2Row>>
snapshot = new ThreadLocal<>();
 
     /** */
-    private final LongAdder8 size = new LongAdder8();
-
-    /** */
     private final boolean snapshotEnabled;
 
     /**
@@ -88,22 +84,41 @@ public class GridH2TreeIndex extends GridH2IndexBase implements Comparator<GridS
 
         final GridH2RowDescriptor desc = tbl.rowDescriptor();
 
+        final boolean snapshotConfigured = false;
+
         if (desc == null || desc.memory() == null) {
-            snapshotEnabled = false;
+            snapshotEnabled = snapshotConfigured;
 
-            tree = new ConcurrentSkipListMap<>(
-                new Comparator<GridSearchRowPointer>() {
-                    @Override public int compare(GridSearchRowPointer o1, GridSearchRowPointer
o2) {
-                        if (o1 instanceof ComparableRow)
-                            return ((ComparableRow)o1).compareTo(o2);
+            if (snapshotConfigured) {
+                tree = new SnapTreeMap<GridSearchRowPointer, GridH2Row>(this) {
+                    @Override protected void afterNodeUpdate_nl(Node<GridSearchRowPointer,
GridH2Row> node, Object val) {
+                        if (val != null)
+                            node.key = (GridSearchRowPointer)val;
+                    }
 
-                        if (o2 instanceof ComparableRow)
-                            return -((ComparableRow)o2).compareTo(o1);
+                    @Override protected Comparable<? super GridSearchRowPointer> comparable(Object
key) {
+                        if (key instanceof ComparableRow)
+                            return (Comparable<? super SearchRow>)key;
 
-                        return compareRows(o1, o2);
+                        return super.comparable(key);
                     }
-                }
-            );
+                };
+            }
+            else {
+                tree = new ConcurrentSkipListMap<>(
+                        new Comparator<GridSearchRowPointer>() {
+                            @Override public int compare(GridSearchRowPointer o1, GridSearchRowPointer
o2) {
+                                if (o1 instanceof ComparableRow)
+                                    return ((ComparableRow)o1).compareTo(o2);
+
+                                if (o2 instanceof ComparableRow)
+                                    return -((ComparableRow)o2).compareTo(o1);
+
+                                return compareRows(o1, o2);
+                            }
+                        }
+                );
+            }
         }
         else {
             snapshotEnabled = true;
@@ -149,49 +164,48 @@ public class GridH2TreeIndex extends GridH2IndexBase implements Comparator<GridS
      */
     @SuppressWarnings("unchecked")
     @Override public Object takeSnapshot(@Nullable Object s) {
-        if (snapshotEnabled) {
-            assert snapshot.get() == null;
+        if (!snapshotEnabled)
+            return null;
 
-            if (s == null)
-                s = tree instanceof SnapTreeMap ? ((SnapTreeMap)tree).clone() :
-                    ((GridOffHeapSnapTreeMap)tree).clone();
+        assert snapshot.get() == null;
 
-            snapshot.set((ConcurrentNavigableMap<GridSearchRowPointer, GridH2Row>)s);
+        if (s == null)
+            s = tree instanceof SnapTreeMap ? ((SnapTreeMap)tree).clone() :
+                ((GridOffHeapSnapTreeMap)tree).clone();
 
-            return s;
-        }
+        snapshot.set((ConcurrentNavigableMap<GridSearchRowPointer, GridH2Row>)s);
 
-        return null;
+        return s;
     }
 
     /**
      * Releases snapshot for current thread.
      */
     @Override public void releaseSnapshot() {
-        if (snapshotEnabled) {
-            ConcurrentNavigableMap<GridSearchRowPointer, GridH2Row> s = snapshot.get();
+        if (!snapshotEnabled)
+            return;
 
-            snapshot.remove();
+        ConcurrentNavigableMap<GridSearchRowPointer, GridH2Row> s = snapshot.get();
 
-            if (s instanceof Closeable)
-                U.closeQuiet((Closeable)s);
-        }
+        snapshot.remove();
+
+        if (s instanceof Closeable)
+            U.closeQuiet((Closeable)s);
     }
 
     /**
      * @return Snapshot for current thread if there is one.
      */
     private ConcurrentNavigableMap<GridSearchRowPointer, GridH2Row> treeForRead() {
-        if (snapshotEnabled) {
-            ConcurrentNavigableMap<GridSearchRowPointer, GridH2Row> res = snapshot.get();
+        if (!snapshotEnabled)
+            return tree;
 
-            if (res == null)
-                res = tree;
+        ConcurrentNavigableMap<GridSearchRowPointer, GridH2Row> res = snapshot.get();
 
-            return res;
-        }
+        if (res == null)
+            res = tree;
 
-        return tree;
+        return res;
     }
 
     /** {@inheritDoc} */
@@ -225,7 +239,7 @@ public class GridH2TreeIndex extends GridH2IndexBase implements Comparator<GridS
 
     /** {@inheritDoc} */
     @Override public long getRowCountApproximation() {
-        return size.longValue();
+        return table.getRowCountApproximation();
     }
 
     /** {@inheritDoc} */
@@ -386,22 +400,12 @@ public class GridH2TreeIndex extends GridH2IndexBase implements Comparator<GridS
 
     /** {@inheritDoc} */
     @Override public GridH2Row put(GridH2Row row) {
-        GridH2Row old = tree.put(row, row);
-
-        if (old == null)
-            size.increment();
-
-        return old;
+        return tree.put(row, row);
     }
 
     /** {@inheritDoc} */
     @Override public GridH2Row remove(SearchRow row) {
-        GridH2Row old = tree.remove(comparable(row, 0));
-
-        if (old != null)
-            size.decrement();
-
-        return old;
+        return tree.remove(comparable(row, 0));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/17c0b4f5/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
index 6854cc6..c027b26 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
@@ -506,8 +506,21 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
         }
 
         /** {@inheritDoc} */
-        @Override public GridQueryProperty property(String name) {
-            return null;
+        @Override public GridQueryProperty property(final String name) {
+            return new GridQueryProperty() {
+                @Override public Object value(Object key, Object val) throws IgniteCheckedException
{
+                    return TypeDesc.this.value(name, key, val);
+                }
+
+                @Override public String name() {
+                    return name;
+                }
+
+                @Override
+                public Class<?> type() {
+                    return Object.class;
+                }
+            };
         }
 
         /** {@inheritDoc} */


Mime
View raw message