xtern commented on code in PR #7246:
URL: https://github.com/apache/ignite-3/pull/7246#discussion_r2639892128
##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -310,7 +315,8 @@ public ClientInboundMessageHandler(
BitSet features,
Map<HandshakeExtension, Object> extensions,
Function<String, CompletableFuture<PlatformComputeConnection>>
computeConnectionFunc,
- HandshakeEventLoopSwitcher handshakeEventLoopSwitcher
+ HandshakeEventLoopSwitcher handshakeEventLoopSwitcher,
+ Supplier<Boolean> ddlBatchingSuggestionEnabled
Review Comment:
Refactored a bit, but it’s not quite the way you would like to see it.
The issue here is:
1. On the one hand, I don't want to pass `DDlBatchingSuggester` directly, as
it's inconvenient for unit tests.
2. On the other hand, I don't want to pass Supplier<Consumer<SqlQueryType>>.
Supplier acts as a factory method, which is needed to create an instance and is
needed so that we create an instance of DDlBatchingSuggester for each
connection. But it's not obvious and looks confusing :pensive:
##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/DdlBatchingSuggester.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.client.handler;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Consumer;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.sql.engine.SqlQueryType;
+import org.jetbrains.annotations.TestOnly;
+
+/**
+ * Tracks the number of consecutive DDL queries executed and prints
+ * the recommendation to use batch processing of DDL queries.
+ */
+public class DdlBatchingSuggester implements Consumer<SqlQueryType> {
+ /** The number of DDL commands, after which it is necessary to print the
recommendation for the user. */
+ static final int THRESHOLD = 10;
+
+ /** Logger. */
+ private static final IgniteLogger LOG =
Loggers.forClass(DdlBatchingSuggester.class);
+
+ /** Message printer. */
+ private final Consumer<String> printer;
+
+ /** Number of DDL queries processed in a row. */
+ private final AtomicInteger counter = new AtomicInteger();
+
+ DdlBatchingSuggester() {
+ this.printer = LOG::warn;
+ }
+
+ @TestOnly
+ DdlBatchingSuggester(Consumer<String> printer) {
+ this.printer = printer;
+ }
+
+ @Override
+ public void accept(SqlQueryType type) {
+ if (type != SqlQueryType.DDL) {
+ counter.set(0);
+
+ return;
+ }
+
+ if (counter.incrementAndGet() == THRESHOLD) {
+ printer.accept("The system detected that a batch of DDL commands
was executed one by one. "
Review Comment:
Currently we don't plan to implement printing of this suggestion for
embedded mode (at least, because we cannot identify from which IgniteSql
instance the queries are coming).
However, we plan to work on the overall design of the suggestions.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]