timoninmaxim commented on a change in pull request #8252:
URL: https://github.com/apache/ignite/pull/8252#discussion_r494330850
##########
File path: modules/core/src/main/java/org/apache/ignite/events/EventType.java
##########
@@ -879,6 +879,16 @@
*/
public static final int EVT_BASELINE_AUTO_ADJUST_AWAITING_TIME_CHANGED =
148;
+ /**
+ * Built-in event type: query execution.
+ * <p>
+ * NOTE: all types in range <b>from 1 to 1000 are reserved</b> for
+ * internal Ignite events and should not be used by user-defined events.
+ *
+ * @see QueryExecutionEvent
+ */
+ public static final int EVT_QUERY_EXECUTION = 150;
Review comment:
Looks like 150 is ok. Really strange sequence for cache query events.
Let do not touch it.
##########
File path:
modules/core/src/main/java/org/apache/ignite/events/QueryExecutionEvent.java
##########
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.events;
+
+import java.util.UUID;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiPredicate;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Query execution event.
+ * <p>
+ * Grid events are used for notification about what happens within the grid.
Note that by
+ * design Ignite keeps all events generated on the local node locally and it
provides
+ * APIs for performing a distributed queries across multiple nodes:
+ * <ul>
+ * <li>
+ * {@link
org.apache.ignite.IgniteEvents#remoteQuery(org.apache.ignite.lang.IgnitePredicate,
long, int...)} -
+ * asynchronously querying events occurred on the nodes specified,
including remote nodes.
+ * </li>
+ * <li>
+ * {@link
org.apache.ignite.IgniteEvents#localQuery(org.apache.ignite.lang.IgnitePredicate,
int...)} -
+ * querying only local events stored on this local node.
+ * </li>
+ * <li>
+ * {@link
org.apache.ignite.IgniteEvents#localListen(org.apache.ignite.lang.IgnitePredicate,
int...)} -
+ * listening to local grid events (events from remote nodes not
included).
+ * </li>
+ * </ul>
+ * User can also wait for events using method {@link
org.apache.ignite.IgniteEvents#waitForLocal(org.apache.ignite.lang.IgnitePredicate,
int...)}.
+ * <h1 class="header">Events and Performance</h1>
+ * Note that by default all events in Ignite are enabled and therefore
generated and stored
+ * by whatever event storage SPI is configured. Ignite can and often does
generate thousands events per seconds
+ * under the load and therefore it creates a significant additional load on
the system. If these events are
+ * not needed by the application this load is unnecessary and leads to
significant performance degradation.
+ * <p>
+ * It is <b>highly recommended</b> to enable only those events that your
application logic requires
+ * by using {@link
org.apache.ignite.configuration.IgniteConfiguration#getIncludeEventTypes()}
method in Ignite configuration. Note that certain
+ * events are required for Ignite's internal operations and such events will
still be generated but not stored by
+ * event storage SPI if they are disabled in Ignite configuration.
+ *
+ * @see EventType#EVT_QUERY_EXECUTION
+ */
+public class QueryExecutionEvent<K, V> extends EventAdapter {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** Query type. */
+ private final String qryType;
+
+ /** Clause. */
+ private final String clause;
+
+ /** Query arguments. */
+ @GridToStringInclude
+ private final Object[] args;
+
+ /** Scan query filter. */
+ @GridToStringInclude
+ private final IgniteBiPredicate<K, V> scanQryFilter;
+
+ /** Security subject ID. */
+ private final UUID subjId;
+
+ /**
+ * @param node Node where event was fired.
+ * @param msg Event message.
+ * @param type Event type.
+ * @param qryType Query type.
+ * @param clause Clause.
+ * @param args Query arguments.
+ * @param subjId Security subject ID.
+ */
+ public QueryExecutionEvent(
+ ClusterNode node,
+ String msg,
+ int type,
+ String qryType,
+ @Nullable String clause,
+ @Nullable Object[] args,
+ @Nullable IgniteBiPredicate<K, V> scanQryFilter,
Review comment:
Skipped in docs. Also, do we need info about it? It's serializable, but
actually does user matter about serialization when implement it? I mean is
there a real case how one can use this filter later?
##########
File path:
modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java
##########
@@ -1545,6 +1555,98 @@ private void checkSqlQueryEvents() throws Exception {
}
}
+ /**
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testQueryExecutionEvents() throws Exception {
+ CountDownLatch execLatch = new CountDownLatch(13);
+
+ IgnitePredicate<Event> lsnr = evt -> {
+ assert evt instanceof QueryExecutionEvent;
+
+ System.out.println(">>> EVENT: " + evt);
+
+ QueryExecutionEvent qe = (QueryExecutionEvent)evt;
+
+ if (SQL_FIELDS.name().equals(qe.queryType()) ||
+ TEXT.name().equals(qe.queryType())
+ )
+ assertNotNull(qe.queryType() + " query clause is empty!",
qe.clause());
+ else
+ assertNull(qe.queryType() + " query clause is not empty!",
qe.clause());
+
+ execLatch.countDown();
+
+ return true;
+ };
+
+ ignite().events().localListen(lsnr, EVT_QUERY_EXECUTION);
+
+ String cacheName = "CACHE_NAME";
+
+ CacheConfiguration<String, String> ccfg = new CacheConfiguration<>();
+
+ ccfg.setName(cacheName);
+ ccfg.setIndexedTypes(String.class, String.class);
+
+ ClientConfiguration cc = new
ClientConfiguration().setAddresses(Config.SERVER);
+
+ try (IgniteClient client = Ignition.startClient(cc)) {
+ ignite().createCache(ccfg).query(new TextQuery<>(String.class,
"text"))
+ .getAll();
+
+ ignite().getOrCreateCache(ccfg).query(new SpiQuery<Integer,
Integer>())
+ .getAll();
+
+ ignite().getOrCreateCache(ccfg).query(new ScanQuery<>())
+ .getAll();
+
+ client.query(new SqlFieldsQuery("create table TEST_TABLE(key int
primary key, val int)"))
+ .getAll();
+
+ client.query(new SqlFieldsQuery("insert into TEST_TABLE values (?,
?)").setArgs(1, 1))
+ .getAll();
+
+ client.query(new SqlFieldsQuery("update TEST_TABLE set val = ?2
where key = ?1").setArgs(1, 2))
+ .getAll();
+
+ client.query(new SqlFieldsQuery("select * from TEST_TABLE"))
+ .getAll();
+
+ client.query(new SqlFieldsQuery("create index idx_1 on
TEST_TABLE(key)"))
+ .getAll();
+
+ client.query(new SqlFieldsQuery("drop index idx_1"))
+ .getAll();
+
+ client.query(new SqlFieldsQuery("alter table TEST_TABLE add column
val2 int"))
+ .getAll();
+
+ client.query(new SqlFieldsQuery("alter table TEST_TABLE drop
val2"))
+ .getAll();
+
+ client.query(new SqlFieldsQuery("drop table TEST_TABLE"))
+ .getAll();
+
+ // Currently, not supported.
+// client.getOrCreateCache(cacheName).query(new
TextQuery<>(String.class, "text"))
Review comment:
Remove commented code.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]