ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject ignite git commit: IGNITE-2093 Implemented scan for near caches.
Date Mon, 07 Dec 2015 16:30:24 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-2093 [created] ac9ee86dc


IGNITE-2093 Implemented scan for near caches.


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

Branch: refs/heads/ignite-2093
Commit: ac9ee86dc7771e752f995f7ec510b4daa9186d30
Parents: 9a14d64
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Mon Dec 7 23:29:57 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Mon Dec 7 23:29:57 2015 +0700

----------------------------------------------------------------------
 .../ignite/internal/visor/cache/VisorCache.java | 13 ++++
 .../internal/visor/query/VisorQueryJob.java     | 76 +++++++++++++++++---
 .../internal/visor/query/VisorQueryUtils.java   |  5 +-
 3 files changed, 84 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/ac9ee86d/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java
b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java
index 1bbcf2f..6def8c3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java
@@ -108,6 +108,9 @@ public class VisorCache implements Serializable {
     /** Cache partitions states. */
     private GridDhtPartitionMap2 partitionsMap;
 
+    /** Flag indicating that cache has near cache. */
+    private boolean near;
+
     /**
      * @param ignite Grid.
      * @param cacheName Cache name.
@@ -140,6 +143,8 @@ public class VisorCache implements Serializable {
 
         CacheConfiguration cfg = ca.configuration();
 
+        near = ca.context().isNear();
+
         mode = cfg.getCacheMode();
 
         boolean partitioned = (mode == CacheMode.PARTITIONED || mode == CacheMode.REPLICATED)
@@ -275,6 +280,7 @@ public class VisorCache implements Serializable {
         c.primaryPartitions = Collections.emptyList();
         c.backupPartitions = Collections.emptyList();
         c.metrics = metrics;
+        c.near = near;
 
         return c;
     }
@@ -405,6 +411,13 @@ public class VisorCache implements Serializable {
         return partitionsMap;
     }
 
+    /**
+     * @return {@code true} if cache has near cache.
+     */
+    public boolean near() {
+        return near;
+    }
+
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(VisorCache.class, this);

http://git-wip-us.apache.org/repos/asf/ignite/blob/ac9ee86d/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryJob.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryJob.java
b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryJob.java
index 40c5cc3..50e5a06 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryJob.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryJob.java
@@ -20,11 +20,14 @@ package org.apache.ignite.internal.visor.query;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Iterator;
 import java.util.List;
 import java.util.UUID;
 import java.util.concurrent.ConcurrentMap;
 import javax.cache.Cache;
 import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CachePeekMode;
+import org.apache.ignite.cache.query.QueryCursor;
 import org.apache.ignite.cache.query.ScanQuery;
 import org.apache.ignite.cache.query.SqlFieldsQuery;
 import org.apache.ignite.internal.processors.cache.GridCacheProcessor;
@@ -39,6 +42,7 @@ import org.apache.ignite.lang.IgniteBiTuple;
 import static org.apache.ignite.internal.visor.query.VisorQueryUtils.RMV_DELAY;
 import static org.apache.ignite.internal.visor.query.VisorQueryUtils.SCAN_COL_NAMES;
 import static org.apache.ignite.internal.visor.query.VisorQueryUtils.SCAN_QRY_NAME;
+import static org.apache.ignite.internal.visor.query.VisorQueryUtils.SCAN_NEAR_CACHE;
 import static org.apache.ignite.internal.visor.query.VisorQueryUtils.SQL_QRY_NAME;
 import static org.apache.ignite.internal.visor.query.VisorQueryUtils.fetchScanQueryRows;
 import static org.apache.ignite.internal.visor.query.VisorQueryUtils.fetchSqlQueryRows;
@@ -70,26 +74,49 @@ public class VisorQueryJob extends VisorJob<VisorQueryArg, IgniteBiTuple<?
exten
         return cacheProcessor.jcache(cacheName);
     }
 
+    /**
+     * Execute scan query.
+     *
+     * @param c Cache to scan.
+     * @param arg Job argument with query parameters.
+     * @return Query cursor.
+     */
+    private QueryCursor<Cache.Entry<Object, Object>> scan(IgniteCache<Object,
Object> c, VisorQueryArg arg) {
+        ScanQuery<Object, Object> qry = new ScanQuery<>(null);
+        qry.setPageSize(arg.pageSize());
+        qry.setLocal(arg.local());
+
+        return c.query(qry);
+    }
+
+    /**
+     * Scan near cache.
+     *
+     * @param c Cache to scan near entries.
+     * @return Cache entries iterator wrapped with query cursor.
+     */
+    private QueryCursor<Cache.Entry<Object, Object>> near(IgniteCache<Object,
Object> c) {
+        return new VisorNearCacheCursor<>(c.localEntries(CachePeekMode.NEAR).iterator());
+    }
+
     /** {@inheritDoc} */
     @Override protected IgniteBiTuple<? extends VisorExceptionWrapper, VisorQueryResultEx>
run(VisorQueryArg arg) {
         try {
             UUID nid = ignite.localNode().id();
 
+            boolean near = SCAN_NEAR_CACHE.equalsIgnoreCase(arg.queryTxt());
+
             boolean scan = arg.queryTxt() == null;
 
-            String qryId = (scan ? SCAN_QRY_NAME : SQL_QRY_NAME) + "-" +
-                UUID.randomUUID();
+            // Generate query ID to store query cursor in node local storage.
+            String qryId = ((scan || near) ? SCAN_QRY_NAME : SQL_QRY_NAME) + "-" + UUID.randomUUID();
 
             IgniteCache<Object, Object> c = cache(arg.cacheName());
 
-            if (scan) {
-                ScanQuery<Object, Object> qry = new ScanQuery<>(null);
-                qry.setPageSize(arg.pageSize());
-                qry.setLocal(arg.local());
-
+            if (near || scan) {
                 long start = U.currentTimeMillis();
 
-                VisorQueryCursor<Cache.Entry<Object, Object>> cur = new VisorQueryCursor<>(c.query(qry));
+                VisorQueryCursor<Cache.Entry<Object, Object>> cur = new VisorQueryCursor<>(near
? near(c) : scan(c, arg));
 
                 List<Object[]> rows = fetchScanQueryRows(cur, arg.pageSize());
 
@@ -184,4 +211,35 @@ public class VisorQueryJob extends VisorJob<VisorQueryArg, IgniteBiTuple<?
exten
     @Override public String toString() {
         return S.toString(VisorQueryJob.class, this);
     }
-}
\ No newline at end of file
+
+    /**
+     * Wrapper for cache iterator to behave like {@link QueryCursor}.
+     */
+    private static class VisorNearCacheCursor<T> implements QueryCursor<T> {
+        private final Iterator<T> it;
+
+        private VisorNearCacheCursor(Iterator<T> it) {
+            this.it = it;
+        }
+
+        /** {@inheritDoc} */
+        @Override public List<T> getAll() {
+            List<T> all = new ArrayList<>();
+
+            while(it.hasNext())
+                all.add(it.next());
+
+            return all;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void close() {
+            // Nothing to close.
+        }
+
+        /** {@inheritDoc} */
+        @Override public Iterator<T> iterator() {
+            return it;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ac9ee86d/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryUtils.java
b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryUtils.java
index e89093f..64d2b95 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryUtils.java
@@ -40,6 +40,9 @@ public class VisorQueryUtils {
     /** Prefix for node local key for SCAN queries. */
     public static final String SCAN_QRY_NAME = "VISOR_SCAN_QUERY";
 
+    /** Prefix for node local key for SCAN near queries. */
+    public static final String SCAN_NEAR_CACHE = "VISOR_SCAN_NEAR_CACHE";
+
     /** Columns for SCAN queries. */
     public static final Collection<VisorQueryField> SCAN_COL_NAMES = Arrays.asList(
         new VisorQueryField(null, null, "Key Class", ""), new VisorQueryField(null, null,
"Key", ""),
@@ -195,4 +198,4 @@ public class VisorQueryUtils {
 
         return rows;
     }
-}
\ No newline at end of file
+}


Mime
View raw message