gg-11414: refactoring after core review
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/0712a813 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/0712a813 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/0712a813 Branch: refs/heads/ignite-3477 Commit: 0712a8139c3fd17f6d089ce3ace9bb221e488616 Parents: ccc1956 Author: Sergey Sidorov <ssido...@gridgain.com> Authored: Fri Nov 25 13:41:02 2016 +0300 Committer: Sergey Sidorov <ssido...@gridgain.com> Committed: Fri Nov 25 17:26:55 2016 +0300 ---------------------------------------------------------------------- .../cache/IgniteCacheOffheapManagerImpl.java | 2 +- .../cache/database/tree/BPlusTree.java | 50 ++---------- .../apache/ignite/internal/util/IgniteTree.java | 24 +----- .../offheap/unsafe/GridOffHeapSnapTreeMap.java | 82 +------------------- .../internal/util/snaptree/SnapTreeMap.java | 76 +----------------- .../processors/database/BPlusTreeSelfTest.java | 6 +- .../query/h2/opt/GridH2SpatialIndex.java | 24 ++++-- .../internal/processors/query/h2/H2Cursor.java | 4 + .../query/h2/database/H2TreeIndex.java | 6 +- .../query/h2/opt/GridH2IndexBase.java | 6 +- .../query/h2/opt/GridH2TreeIndex.java | 59 +++++++------- 11 files changed, 66 insertions(+), 273 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/0712a813/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java index 861bb11..66896d2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java @@ -897,7 +897,7 @@ public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter imple /** {@inheritDoc} */ @Override public GridCursor<? extends CacheDataRow> cursor() throws IgniteCheckedException { - return dataTree.findAll(); + return dataTree.find(null, null); } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/ignite/blob/0712a813/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 d60246e..57d420d 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 @@ -727,7 +727,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements * @return Cursor. * @throws IgniteCheckedException If failed. */ - public final GridCursor<T> find(L lower, L upper) throws IgniteCheckedException { + @Override public final GridCursor<T> find(L lower, L upper) throws IgniteCheckedException { checkDestroyed(); try { @@ -751,34 +751,12 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements } } - public GridCursor<T> find(L lower, boolean lowerInclusive, - L upper, boolean upperInclusive) throws IgniteCheckedException { - if (lower == null || upper == null) - throw new NullPointerException(); - - ForwardCursor cursor = new ForwardCursor(lower, upper); - - if (!lowerInclusive) - cursor.lowerShift = 1; - - if (!upperInclusive) - cursor.upperShift = -1; - - cursor.find(); - - return cursor; - } - - public GridCursor<T> findAll() throws IgniteCheckedException { - return find(null, null); - } - /** * @param row Lookup row for exact match. * @return Found row. */ @SuppressWarnings("unchecked") - public final T findOne(L row) throws IgniteCheckedException { + @Override public final T findOne(L row) throws IgniteCheckedException { checkDestroyed(); try { @@ -1270,14 +1248,10 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements * @return Removed row. * @throws IgniteCheckedException If failed. */ - public final T remove(L row) throws IgniteCheckedException { + @Override public final T remove(L row) throws IgniteCheckedException { return doRemove(row, false, null); } - @Override public T removeNode(L key) throws IgniteCheckedException { - return doRemove(key, false, null); - } - /** * @param row Lookup row. * @param ceil If we can remove ceil row when we can not find exact. @@ -1490,7 +1464,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements * @return Size. * @throws IgniteCheckedException If failed. */ - public final long size() throws IgniteCheckedException { + @Override public final long size() throws IgniteCheckedException { checkDestroyed(); long pageId; @@ -1530,14 +1504,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements /** * {@inheritDoc} */ - public final long treeSize() throws IgniteCheckedException { - return size(); - } - - /** - * {@inheritDoc} - */ - public final T put(T row) throws IgniteCheckedException { + @Override public final T put(T row) throws IgniteCheckedException { return put(row, null); } @@ -3476,9 +3443,6 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements /** */ private final L upperBound; - /** */ - private int upperShift = 1; // Initially it is -1 to handle multiple equal rows. - /** * @param lowerBound Lower bound. * @param upperBound Upper bound. @@ -3550,8 +3514,8 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements // Compare with the last row on the page. int cmp = compare(io, buf, cnt - 1, upperBound); - if (cmp > 0 || (cmp == 0 && upperShift == -1)) { - int idx = findInsertionPoint(io, buf, low, cnt, upperBound, upperShift); + if (cmp > 0) { + int idx = findInsertionPoint(io, buf, low, cnt, upperBound, 1); assert idx < 0; http://git-wip-us.apache.org/repos/asf/ignite/blob/0712a813/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteTree.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteTree.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteTree.java index 512792b..0c08cd9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteTree.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteTree.java @@ -45,19 +45,6 @@ public interface IgniteTree<L, T> { T findOne(L key) throws IgniteCheckedException; /** - * Returns a cursor from lower to upper bounds. - * - * @param lower Lower bound or {@code null} if unbounded. - * @param lowerInclusive {@code true} if the low bound - * is to be included in the returned view - * @param upper Upper bound or {@code null} if unbounded. - * @param upperInclusive {@code true} if the upper bound - * is to be included in the returned view - * @return Cursor. - */ - GridCursor<T> find(L lower, boolean lowerInclusive, L upper, boolean upperInclusive) throws IgniteCheckedException; - - /** * Returns a cursor from lower to upper bounds inclusive. * * @param lower Lower bound or {@code null} if unbounded. @@ -67,24 +54,17 @@ public interface IgniteTree<L, T> { GridCursor<T> find(L lower, L upper) throws IgniteCheckedException; /** - * Returns a cursor over all values. - * @return Cursor. - * @throws IgniteCheckedException - */ - GridCursor<T> findAll() throws IgniteCheckedException; - - /** * Removes the mapping for a key from this tree if it is present. * * @param key key whose mapping is to be removed from the tree * @return the previous value associated with key, or null if there was no mapping for key. */ - T removeNode(L key) throws IgniteCheckedException; + T remove(L key) throws IgniteCheckedException; /** * Returns the number of elements in this tree. * * @return the number of elements in this tree */ - long treeSize() throws IgniteCheckedException; + long size() throws IgniteCheckedException; } http://git-wip-us.apache.org/repos/asf/ignite/blob/0712a813/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridOffHeapSnapTreeMap.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridOffHeapSnapTreeMap.java b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridOffHeapSnapTreeMap.java index ab175de..6a97f9e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridOffHeapSnapTreeMap.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridOffHeapSnapTreeMap.java @@ -112,7 +112,7 @@ import org.jsr166.ConcurrentHashMap8; @SuppressWarnings("ALL") public class GridOffHeapSnapTreeMap<K extends GridOffHeapSmartPointer, V extends GridOffHeapSmartPointer> extends AbstractMap<K, V> - implements ConcurrentNavigableMap<K, V>, Cloneable, AutoCloseable, GridReservable, IgniteTree<K, V> { + implements ConcurrentNavigableMap<K, V>, Cloneable, AutoCloseable, GridReservable { /** This is a special value that indicates that an optimistic read failed. */ private static final GridOffHeapSmartPointer SpecialRetry = new GridOffHeapSmartPointer() { @Override public long pointer() { @@ -3825,52 +3825,10 @@ public class GridOffHeapSnapTreeMap<K extends GridOffHeapSmartPointer, V extends return new SubMap(this, null, null, false, null, null, false, true); } - //////////////// IgniteTree - - @Override public V put(V value) throws IgniteCheckedException { - return put((K)value, value); - } - - @Override public V findOne(K key) throws IgniteCheckedException { - return get(key); - } - - @Override public GridCursor<V> findAll() throws IgniteCheckedException { - return find(null, null); - } - - @Override public GridCursor<V> find(K lower, K upper) throws IgniteCheckedException { - return find(lower, true, upper, true); - } - - @Override public GridCursor<V> find(K lower, boolean lowerInclusive, K upper, boolean upperInclusive) - throws IgniteCheckedException { - if (lower == null || upper == null) - throw new NullPointerException(); - - final Comparable<? super K> fromCmp = comparable(lower); - - if (fromCmp.compareTo(upper) > 0) { - throw new IllegalArgumentException(); - } - - SubMap subMap = new SubMap(this, lower, fromCmp, lowerInclusive, upper, comparable(upper), upperInclusive, false); - - return new GridCursorIteratorWrapper<>(subMap.values().iterator()); - } - - @Override public V removeNode(K key) throws IgniteCheckedException { - return remove(key); - } - - @Override public long treeSize() throws IgniteCheckedException { - return size(); - } - /** * Submap. */ - private class SubMap extends AbstractMap<K, V> implements ConcurrentNavigableMap<K, V>, IgniteTree<K, V> { + private class SubMap extends AbstractMap<K, V> implements ConcurrentNavigableMap<K, V> { /** */ private final GridOffHeapSnapTreeMap<K,V> m; @@ -4476,42 +4434,6 @@ public class GridOffHeapSnapTreeMap<K extends GridOffHeapSmartPointer, V extends @Override public NavigableSet<K> descendingKeySet() { return descendingMap().navigableKeySet(); } - - /////////// IgniteTree - - @Override public V put(V value) throws IgniteCheckedException { - return put((K)value, value); - } - - @Override public V findOne(K key) throws IgniteCheckedException { - return get(key); - } - - @Override public GridCursor<V> findAll() throws IgniteCheckedException { - return find(null, null); - } - - @Override public GridCursor<V> find(K lower, K upper) throws IgniteCheckedException { - return find(lower, true, upper, true); - } - - @Override public GridCursor<V> find(K lower, boolean lowerInclusive, K upper, boolean upperInclusive) - throws IgniteCheckedException { - if (lower == null || upper == null) - throw new NullPointerException(); - - SubMap subMap = subMap(lower, lowerInclusive, upper, upperInclusive); - - return new GridCursorIteratorWrapper(subMap.values().iterator()); - } - - @Override public V removeNode(K key) throws IgniteCheckedException { - return remove(key); - } - - @Override public long treeSize() throws IgniteCheckedException { - return size(); - } } /** http://git-wip-us.apache.org/repos/asf/ignite/blob/0712a813/modules/core/src/main/java/org/apache/ignite/internal/util/snaptree/SnapTreeMap.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/snaptree/SnapTreeMap.java b/modules/core/src/main/java/org/apache/ignite/internal/util/snaptree/SnapTreeMap.java index 79c110d..dce2fb8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/snaptree/SnapTreeMap.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/snaptree/SnapTreeMap.java @@ -107,7 +107,7 @@ import java.util.concurrent.ConcurrentNavigableMap; */ @SuppressWarnings("ALL") public class SnapTreeMap<K, V> extends AbstractMap<K, V> implements ConcurrentNavigableMap<K, V>, Cloneable, - Serializable, IgniteTree<K, V> { + Serializable { /** */ private static final long serialVersionUID = 0L; @@ -2347,43 +2347,7 @@ public class SnapTreeMap<K, V> extends AbstractMap<K, V> implements ConcurrentNa return new SubMap(this, null, null, false, null, null, false, true); } - //////////////// IgniteTree - - @Override public GridCursor<V> find(K lower, boolean lowerInclusive, - K upper, boolean upperInclusive) throws IgniteCheckedException { - if (lower == null || upper == null) - throw new NullPointerException(); - - return new GridCursorIteratorWrapper<>(subMap(lower, lowerInclusive, upper, upperInclusive) - .values().iterator()); - } - - public GridCursor<V> find(K lower, K upper) throws IgniteCheckedException { - return find(lower, true, upper, true); - } - - public GridCursor<V> findAll() throws IgniteCheckedException { - return find(null, null); - } - - @Override public V findOne(K key) throws IgniteCheckedException { - return get(key); - } - - @Override public long treeSize() throws IgniteCheckedException { - return size(); - } - - @Override public V put(V value) throws IgniteCheckedException { - return put((K)value, value); - } - - @Override public V removeNode(K key) throws IgniteCheckedException { - return remove(key); - } - - private static class SubMap<K, V> extends AbstractMap<K, V> implements ConcurrentNavigableMap<K, V>, Serializable, - IgniteTree<K, V> { + private static class SubMap<K, V> extends AbstractMap<K, V> implements ConcurrentNavigableMap<K, V>, Serializable { /** */ private static final long serialVersionUID = 0L; @@ -2905,42 +2869,6 @@ public class SnapTreeMap<K, V> extends AbstractMap<K, V> implements ConcurrentNa minCmp = minKey == null ? null : m.comparable(minKey); maxCmp = maxKey == null ? null : m.comparable(maxKey); } - - /////// IgniteTree - - @Override public V findOne(K key) throws IgniteCheckedException { - return get(key); - } - - @Override public GridCursor<V> find(K lower, boolean lowerInclusive, - K upper, boolean upperInclusive) throws IgniteCheckedException { - - if (lower == null || upper == null) - throw new NullPointerException(); - - return new GridCursorIteratorWrapper<>(subMap(lower, lowerInclusive, upper, upperInclusive) - .values().iterator()); - } - - public GridCursor<V> find(K lower, K upper) throws IgniteCheckedException { - return find(lower, true, upper, true); - } - - public GridCursor<V> findAll() throws IgniteCheckedException { - return find(null, null); - } - - @Override public long treeSize() throws IgniteCheckedException { - return size(); - } - - @Override public V put(V value) throws IgniteCheckedException { - return put((K)value, value); - } - - @Override public V removeNode(K key) throws IgniteCheckedException { - return remove(key); - } } //////// Serialization http://git-wip-us.apache.org/repos/asf/ignite/blob/0712a813/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java index 88edaf1..4dcb7a9 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java @@ -184,12 +184,8 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest { map.put(i, i); } - checkCursor(tree.findAll(), map.values().iterator()); + checkCursor(tree.find(null, null), map.values().iterator()); checkCursor(tree.find(10L, 70L), map.subMap(10L, true, 70L, true).values().iterator()); - checkCursor(tree.find(10L, true, 50L, false), map.subMap(10L, true, 50L, false).values().iterator()); - checkCursor(tree.find(10L, false, 50L, true), map.subMap(10L, false, 50L, true).values().iterator()); - checkCursor(tree.find(10L, false, 50L, false), map.subMap(10L, false, 50L, false).values().iterator()); - checkCursor(tree.find(10L, true, 50L, true), map.subMap(10L, true, 50L, true).values().iterator()); } /** http://git-wip-us.apache.org/repos/asf/ignite/blob/0712a813/modules/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SpatialIndex.java ---------------------------------------------------------------------- diff --git a/modules/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SpatialIndex.java b/modules/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SpatialIndex.java index ed91800..b6060b4 100644 --- a/modules/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SpatialIndex.java +++ b/modules/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SpatialIndex.java @@ -28,6 +28,11 @@ import java.util.Map; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; + +import org.apache.ignite.*; +import org.apache.ignite.internal.processors.query.h2.*; +import org.apache.ignite.internal.util.*; +import org.apache.ignite.internal.util.lang.*; import org.h2.engine.Session; import org.h2.index.Cursor; import org.h2.index.IndexType; @@ -119,7 +124,7 @@ public class GridH2SpatialIndex extends GridH2IndexBase implements SpatialIndex } /** {@inheritDoc} */ - @Nullable @Override protected Object doTakeSnapshot() { + @Nullable @Override protected IgniteTree doTakeSnapshot() { return null; // TODO We do not support snapshots, but probably this is possible. } @@ -258,7 +263,7 @@ public class GridH2SpatialIndex extends GridH2IndexBase implements SpatialIndex try { checkClosed(); - return new GridH2Cursor(rowIterator(treeMap.keySet().iterator(), filter)); + return new H2Cursor(rowIterator(treeMap.keySet().iterator(), filter)); } finally { l.unlock(); @@ -280,9 +285,9 @@ public class GridH2SpatialIndex extends GridH2IndexBase implements SpatialIndex * @param filter Table filter. * @return Iterator over rows. */ - private Iterator<GridH2Row> rowIterator(Iterator<SpatialKey> i, TableFilter filter) { + private GridCursor<GridH2Row> rowIterator(Iterator<SpatialKey> i, TableFilter filter) { if (!i.hasNext()) - return Collections.emptyIterator(); + return EMPTY_CURSOR; List<GridH2Row> rows = new ArrayList<>(); @@ -295,7 +300,7 @@ public class GridH2SpatialIndex extends GridH2IndexBase implements SpatialIndex } while (i.hasNext()); - return filter(rows.iterator(), threadLocalFilter()); + return filter(new GridCursorIteratorWrapper(rows.iterator()), threadLocalFilter()); } /** {@inheritDoc} */ @@ -310,9 +315,12 @@ public class GridH2SpatialIndex extends GridH2IndexBase implements SpatialIndex if (!first) throw DbException.throwInternalError("Spatial Index can only be fetch by ascending order"); - Iterator<GridH2Row> iter = rowIterator(treeMap.keySet().iterator(), null); + GridCursor<GridH2Row> iter = rowIterator(treeMap.keySet().iterator(), null); - return new SingleRowCursor(iter.hasNext() ? iter.next() : null); + return new SingleRowCursor(iter.next() ? iter.get() : null); + } + catch (IgniteCheckedException e) { + throw DbException.convert(e); } finally { l.unlock(); @@ -339,7 +347,7 @@ public class GridH2SpatialIndex extends GridH2IndexBase implements SpatialIndex if (intersection == null) return find(filter.getSession(), null, null); - return new GridH2Cursor(rowIterator(treeMap.findIntersectingKeys(getEnvelope(intersection, 0)), filter)); + return new H2Cursor(rowIterator(treeMap.findIntersectingKeys(getEnvelope(intersection, 0)), filter)); } finally { l.unlock(); http://git-wip-us.apache.org/repos/asf/ignite/blob/0712a813/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Cursor.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Cursor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Cursor.java index 95114a2..cc71813 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Cursor.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2Cursor.java @@ -50,6 +50,10 @@ public class H2Cursor implements Cursor { this.filter = filter; } + public H2Cursor(GridCursor<GridH2Row> cursor) { + this(cursor, null); + } + /** {@inheritDoc} */ @Override public Row get() { try { http://git-wip-us.apache.org/repos/asf/ignite/blob/0712a813/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java index b56b1ed..f685f3a 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java @@ -207,10 +207,8 @@ public class H2TreeIndex extends GridH2IndexBase { } /** {@inheritDoc} */ - @Nullable @Override protected Object doTakeSnapshot() { - assert false; - - return this; + @Nullable @Override protected IgniteTree<SearchRow, GridH2Row> doTakeSnapshot() { + return tree; } protected IgniteTree<SearchRow, GridH2Row> treeForRead() { http://git-wip-us.apache.org/repos/asf/ignite/blob/0712a813/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java index 84d3b6a..56c9edc 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java @@ -276,7 +276,7 @@ public abstract class GridH2IndexBase extends BaseIndex { * * @return Snapshot or {@code null}. */ - @Nullable protected abstract Object doTakeSnapshot(); + @Nullable protected abstract IgniteTree doTakeSnapshot(); /** * @return Thread local snapshot. @@ -456,12 +456,10 @@ public abstract class GridH2IndexBase extends BaseIndex { if (msg.bounds() != null) { // This is the first request containing all the search rows. - Object snapshot0 = qctx.getSnapshot(idxId); + IgniteTree snapshotTree = qctx.getSnapshot(idxId); assert !msg.bounds().isEmpty() : "empty bounds"; - IgniteTree snapshotTree = (IgniteTree)snapshot0; - src = new RangeSource(msg.bounds(), snapshotTree, qctx.filter()); } else { http://git-wip-us.apache.org/repos/asf/ignite/blob/0712a813/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 f442e4e..d1f2d28 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 @@ -17,9 +17,7 @@ package org.apache.ignite.internal.processors.query.h2.opt; -import java.util.Comparator; -import java.util.List; -import java.util.NavigableMap; +import java.util.*; import java.util.concurrent.ConcurrentSkipListMap; import org.apache.ignite.*; @@ -50,7 +48,7 @@ import org.jetbrains.annotations.Nullable; @SuppressWarnings("ComparatorNotSerializable") public class GridH2TreeIndex extends GridH2IndexBase implements Comparator<GridSearchRowPointer> { /** */ - private final IgniteTree<GridSearchRowPointer, GridH2Row> tree; + private final IgniteNavigableMapTree tree; /** */ private final boolean snapshotEnabled; @@ -78,7 +76,7 @@ public class GridH2TreeIndex extends GridH2IndexBase implements Comparator<GridS snapshotEnabled = desc == null || desc.snapshotableIndex(); if (snapshotEnabled) { - tree = new SnapTreeMap<GridSearchRowPointer, GridH2Row>(this) { + tree = new IgniteNavigableMapTree(new SnapTreeMap<GridSearchRowPointer, GridH2Row>(this) { @Override protected void afterNodeUpdate_nl(Node<GridSearchRowPointer, GridH2Row> node, Object val) { if (val != null) node.key = (GridSearchRowPointer)val; @@ -90,7 +88,7 @@ public class GridH2TreeIndex extends GridH2IndexBase implements Comparator<GridS return super.comparable(key); } - }; + }); } else { tree = new IgniteNavigableMapTree( @@ -114,7 +112,7 @@ public class GridH2TreeIndex extends GridH2IndexBase implements Comparator<GridS snapshotEnabled = true; - tree = new GridOffHeapSnapTreeMap<GridSearchRowPointer, GridH2Row>(desc, desc, desc.memory(), desc.guard(), this) { + tree = new IgniteNavigableMapTree(new GridOffHeapSnapTreeMap<GridSearchRowPointer, GridH2Row>(desc, desc, desc.memory(), desc.guard(), this) { @Override protected void afterNodeUpdate_nl(long node, GridH2Row val) { final long oldKey = keyPtr(node); @@ -135,19 +133,17 @@ public class GridH2TreeIndex extends GridH2IndexBase implements Comparator<GridS return super.comparable(key); } - }; + }); } initDistributedJoinMessaging(tbl); } /** {@inheritDoc} */ - @Override protected Object doTakeSnapshot() { + @Override protected IgniteTree doTakeSnapshot() { assert snapshotEnabled; - return tree instanceof SnapTreeMap ? - ((SnapTreeMap)tree).clone() : - ((GridOffHeapSnapTreeMap)tree).clone(); + return tree.clone(); } /** {@inheritDoc} */ @@ -167,9 +163,6 @@ public class GridH2TreeIndex extends GridH2IndexBase implements Comparator<GridS @Override public void destroy() { assert threadLocalSnapshot() == null; - if (tree instanceof AutoCloseable) - U.closeQuiet((AutoCloseable)tree); - super.destroy(); } @@ -180,7 +173,7 @@ public class GridH2TreeIndex extends GridH2IndexBase implements Comparator<GridS // Fast path if we don't need to perform any filtering. if (f == null || f.forSpace((getTable()).spaceName()) == null) try { - return treeForRead().treeSize(); + return treeForRead().size(); } catch (IgniteCheckedException e) { throw DbException.convert(e); } @@ -338,7 +331,7 @@ public class GridH2TreeIndex extends GridH2IndexBase implements Comparator<GridS try { // We take exclusive bounds because it is possible that one search row will be equal to multiple key rows // in tree and we must return them all. - return tree.find(first, false, last, false); + return tree.find(first, last); } catch (IgniteCheckedException e) { throw DbException.convert(e); @@ -377,7 +370,7 @@ public class GridH2TreeIndex extends GridH2IndexBase implements Comparator<GridS /** {@inheritDoc} */ @Override public GridH2Row remove(SearchRow row) { try { - return tree.removeNode(comparable(row, 0)); + return tree.remove(comparable(row, 0)); } catch (IgniteCheckedException e) { throw DbException.convert(e); @@ -487,7 +480,7 @@ public class GridH2TreeIndex extends GridH2IndexBase implements Comparator<GridS long i = 0; try { - GridCursor<GridH2Row> cursor = tree.findAll(); + GridCursor<GridH2Row> cursor = tree.find(null, null); while(cursor.next()) { GridH2Row row = cursor.get(); @@ -524,33 +517,35 @@ public class GridH2TreeIndex extends GridH2IndexBase implements Comparator<GridS return tree.get(key); } - @Override public GridCursor<GridH2Row> find(GridSearchRowPointer lower, boolean lowerInclusive, - GridSearchRowPointer upper, boolean upperInclusive) + @Override public GridCursor<GridH2Row> find(GridSearchRowPointer lower, GridSearchRowPointer upper) throws IgniteCheckedException { if (lower == null || upper == null) throw new NullPointerException(); NavigableMap<GridSearchRowPointer, GridH2Row> subMap = - tree.subMap(lower, lowerInclusive, upper, upperInclusive); + tree.subMap(lower, false, upper, false); return new GridCursorIteratorWrapper<GridH2Row>(subMap.values().iterator()); } - public GridCursor<GridH2Row> find(GridSearchRowPointer lower, GridSearchRowPointer upper) - throws IgniteCheckedException { - return find(lower, true, upper, true); + @Override public GridH2Row remove(GridSearchRowPointer key) throws IgniteCheckedException { + return tree.remove(key); } - public GridCursor<GridH2Row> findAll() throws IgniteCheckedException { - return find(null, null); + @Override public long size() throws IgniteCheckedException { + return tree.size(); } - @Override public GridH2Row removeNode(GridSearchRowPointer key) throws IgniteCheckedException { - return tree.remove(key); - } + @Override public IgniteNavigableMapTree clone() { + AbstractMap copy; - @Override public long treeSize() throws IgniteCheckedException { - return tree.size(); + try { + copy = (AbstractMap) super.clone(); + } catch (final CloneNotSupportedException e) { + throw DbException.convert(e); + } + + return new IgniteNavigableMapTree((NavigableMap)copy); } } } \ No newline at end of file