You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2022/06/28 08:49:19 UTC

[GitHub] [ignite-3] korlov42 commented on a diff in pull request #889: IGNITE-16987 Alt alterative version of network refactoring

korlov42 commented on code in PR #889:
URL: https://github.com/apache/ignite-3/pull/889#discussion_r908194415


##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/JdbcQueryCursorHandlerImpl.java:
##########
@@ -0,0 +1,177 @@
+/*
+ * 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.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.jdbc.proto.JdbcQueryCursorHandler;
+import org.apache.ignite.internal.jdbc.proto.event.JdbcColumnMeta;
+import org.apache.ignite.internal.jdbc.proto.event.JdbcMetaColumnsResult;
+import org.apache.ignite.internal.jdbc.proto.event.JdbcQueryCloseRequest;
+import org.apache.ignite.internal.jdbc.proto.event.JdbcQueryCloseResult;
+import org.apache.ignite.internal.jdbc.proto.event.JdbcQueryFetchRequest;
+import org.apache.ignite.internal.jdbc.proto.event.JdbcQueryFetchResult;
+import org.apache.ignite.internal.jdbc.proto.event.JdbcQueryMetadataRequest;
+import org.apache.ignite.internal.jdbc.proto.event.Response;
+import org.apache.ignite.internal.sql.engine.AsyncSqlCursor;
+import org.apache.ignite.internal.sql.engine.util.Commons;
+import org.apache.ignite.lang.IgniteInternalCheckedException;
+import org.apache.ignite.sql.ColumnMetadata;
+import org.apache.ignite.sql.ColumnMetadata.ColumnOrigin;
+import org.apache.ignite.sql.ResultSetMetadata;
+
+/**
+ * Jdbc query event handler implementation.
+ */
+public class JdbcQueryCursorHandlerImpl implements JdbcQueryCursorHandler {
+    /** Client registry resources. */
+    private final ClientResourceRegistry resources;
+
+    /**
+     * Constructor.
+     *
+     * @param resources Client resources.
+     */
+    public JdbcQueryCursorHandlerImpl(ClientResourceRegistry resources) {
+        this.resources = resources;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public CompletableFuture<JdbcQueryFetchResult> fetchAsync(JdbcQueryFetchRequest req) {
+        AsyncSqlCursor<List<Object>> asyncSqlCursor = null;
+        try {
+            asyncSqlCursor = resources.get(req.cursorId()).get(AsyncSqlCursor.class);
+        } catch (IgniteInternalCheckedException e) {
+            return CompletableFuture.completedFuture(new JdbcQueryFetchResult(Response.STATUS_FAILED,
+                    "Failed to find query cursor with ID: " + req.cursorId() + ". " + e));

Review Comment:
   Could you please fix the messages to inline with single pattern? 
   
   Current patterns are:
   `Failed ... with ID: " + req.cursorId()`
   `Failed ... with id  " + req.cursorId()`
   `Failed ... [curId=" + req.cursorId()`
   ...
   
   Other messages worth to be revised too



##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/JdbcQueryCursorHandlerImpl.java:
##########
@@ -0,0 +1,177 @@
+/*
+ * 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.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.jdbc.proto.JdbcQueryCursorHandler;
+import org.apache.ignite.internal.jdbc.proto.event.JdbcColumnMeta;
+import org.apache.ignite.internal.jdbc.proto.event.JdbcMetaColumnsResult;
+import org.apache.ignite.internal.jdbc.proto.event.JdbcQueryCloseRequest;
+import org.apache.ignite.internal.jdbc.proto.event.JdbcQueryCloseResult;
+import org.apache.ignite.internal.jdbc.proto.event.JdbcQueryFetchRequest;
+import org.apache.ignite.internal.jdbc.proto.event.JdbcQueryFetchResult;
+import org.apache.ignite.internal.jdbc.proto.event.JdbcQueryMetadataRequest;
+import org.apache.ignite.internal.jdbc.proto.event.Response;
+import org.apache.ignite.internal.sql.engine.AsyncSqlCursor;
+import org.apache.ignite.internal.sql.engine.util.Commons;
+import org.apache.ignite.lang.IgniteInternalCheckedException;
+import org.apache.ignite.sql.ColumnMetadata;
+import org.apache.ignite.sql.ColumnMetadata.ColumnOrigin;
+import org.apache.ignite.sql.ResultSetMetadata;
+
+/**
+ * Jdbc query event handler implementation.
+ */
+public class JdbcQueryCursorHandlerImpl implements JdbcQueryCursorHandler {
+    /** Client registry resources. */
+    private final ClientResourceRegistry resources;
+
+    /**
+     * Constructor.
+     *
+     * @param resources Client resources.
+     */
+    public JdbcQueryCursorHandlerImpl(ClientResourceRegistry resources) {
+        this.resources = resources;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public CompletableFuture<JdbcQueryFetchResult> fetchAsync(JdbcQueryFetchRequest req) {
+        AsyncSqlCursor<List<Object>> asyncSqlCursor = null;
+        try {
+            asyncSqlCursor = resources.get(req.cursorId()).get(AsyncSqlCursor.class);
+        } catch (IgniteInternalCheckedException e) {
+            return CompletableFuture.completedFuture(new JdbcQueryFetchResult(Response.STATUS_FAILED,
+                    "Failed to find query cursor with ID: " + req.cursorId() + ". " + e));

Review Comment:
   BTW, why do some exceptions are wrapped with `getWriterWithStackTrace`, but others don't?



##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/JdbcQueryEventHandlerImpl.java:
##########
@@ -118,24 +109,32 @@ public CompletableFuture<QueryExecuteResult> queryAsync(QueryExecuteRequest req)
         }
 
         if (results.isEmpty()) {
-            return CompletableFuture.completedFuture(new QueryExecuteResult(Response.STATUS_FAILED,
+            return CompletableFuture.completedFuture(new JdbcQueryExecuteResult(Response.STATUS_FAILED,
                     "At least one cursor is expected for query " + req.sqlQuery()));
         }
 
         return CompletableFuture.allOf(results.toArray(new CompletableFuture[0])).thenApply(none -> {
             var actualResults = results.stream().map(CompletableFuture::join).collect(Collectors.toList());
 
-            return new QueryExecuteResult(actualResults);
+            return new JdbcQueryExecuteResult(actualResults);
         }).exceptionally(t -> {
             results.stream()
                     .filter(fut -> !fut.isCompletedExceptionally())
                     .map(CompletableFuture::join)
-                    .map(res -> openCursors.get(res.cursorId()))
-                    .forEach(AsyncSqlCursor::closeAsync);
+                    .filter(res -> res.cursorId() != null) //close only for QUERY cursors
+                    .map(res -> {
+                        try {
+                            return resources.remove(res.cursorId()).get(AsyncSqlCursor.class);
+                        } catch (IgniteInternalCheckedException e) {
+                            //we can do nothing about this.
+                        }
+                        return null;
+                    }).filter(Objects::nonNull).forEach(AsyncSqlCursor::closeAsync);

Review Comment:
   lets put each step of a stream processing on a new line



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org