You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by is...@apache.org on 2022/03/05 10:55:58 UTC

[ignite] branch master updated: IGNITE-16608 Fix ODBC connection timeouts

This is an automated email from the ASF dual-hosted git repository.

isapego pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 43b9a99  IGNITE-16608 Fix ODBC connection timeouts
43b9a99 is described below

commit 43b9a9985776ea8b10cee81957af6ddad2a9824d
Author: Igor Sapego <is...@apache.org>
AuthorDate: Sat Mar 5 14:54:50 2022 +0400

    IGNITE-16608 Fix ODBC connection timeouts
    
    This closes #9862
---
 .../cpp/odbc-test/config/queries-default.xml       |  2 ++
 .../cpp/odbc-test/include/odbc_test_suite.h        | 10 ++++++++
 .../cpp/odbc-test/src/odbc_test_suite.cpp          | 28 +++++++++++++---------
 .../platforms/cpp/odbc-test/src/queries_test.cpp   | 21 ++++++++++++++++
 .../cpp/odbc/include/ignite/odbc/connection.h      |  2 +-
 .../platforms/cpp/odbc/src/query/batch_query.cpp   | 15 ++----------
 .../platforms/cpp/odbc/src/query/data_query.cpp    | 23 ++----------------
 7 files changed, 55 insertions(+), 46 deletions(-)

diff --git a/modules/platforms/cpp/odbc-test/config/queries-default.xml b/modules/platforms/cpp/odbc-test/config/queries-default.xml
index 996ef6e..5920f0b 100644
--- a/modules/platforms/cpp/odbc-test/config/queries-default.xml
+++ b/modules/platforms/cpp/odbc-test/config/queries-default.xml
@@ -74,6 +74,8 @@
         <property name="cacheMode" value="PARTITIONED"/>
         <property name="atomicityMode" value="TRANSACTIONAL"/>
 
+        <property name="sqlFunctionClasses" value="org.apache.ignite.testframework.GridTestUtils.SqlTestFunctions"/>
+
         <!-- Configure type metadata to enable queries. -->
         <property name="queryEntities">
             <list>
diff --git a/modules/platforms/cpp/odbc-test/include/odbc_test_suite.h b/modules/platforms/cpp/odbc-test/include/odbc_test_suite.h
index 1bdd3b0..c312d7b 100644
--- a/modules/platforms/cpp/odbc-test/include/odbc_test_suite.h
+++ b/modules/platforms/cpp/odbc-test/include/odbc_test_suite.h
@@ -119,6 +119,16 @@ namespace ignite
              *
              * @param from Index to start from.
              * @param to Index to stop.
+             * @param merge Set to true to use merge instead of insert.
+             * @return Execution result.
+             */
+            SQLRETURN InsertTestBatchNoCheck(int from, int to, bool merge = false);
+
+            /**
+             * Insert requested number of TestType values in a batch.
+             *
+             * @param from Index to start from.
+             * @param to Index to stop.
              * @param expectedToAffect Expected number of affected records.
              * @param merge Set to true to use merge instead of insert.
              * @return Records inserted.
diff --git a/modules/platforms/cpp/odbc-test/src/odbc_test_suite.cpp b/modules/platforms/cpp/odbc-test/src/odbc_test_suite.cpp
index bef4639..fbc1b9b 100644
--- a/modules/platforms/cpp/odbc-test/src/odbc_test_suite.cpp
+++ b/modules/platforms/cpp/odbc-test/src/odbc_test_suite.cpp
@@ -463,7 +463,7 @@ namespace ignite
                 BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
         }
 
-        int OdbcTestSuite::InsertTestBatch(int from, int to, int expectedToAffect, bool merge)
+        SQLRETURN OdbcTestSuite::InsertTestBatchNoCheck(int from, int to, bool merge)
         {
             using common::FixedSizeArray;
 
@@ -527,14 +527,6 @@ namespace ignite
                 i8ArrayFieldsLen[i] = 42;
             }
 
-            SQLULEN setsProcessed = 0;
-
-            BOOST_TEST_CHECKPOINT("Setting processed pointer");
-            ret = SQLSetStmtAttr(stmt, SQL_ATTR_PARAMS_PROCESSED_PTR, &setsProcessed, SQL_IS_POINTER);
-
-            if (!SQL_SUCCEEDED(ret))
-                BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
-
             BOOST_TEST_CHECKPOINT("Binding keys");
             ret = SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_SBIGINT, SQL_BIGINT, 0, 0, keys.GetData(), 0, 0);
 
@@ -609,13 +601,27 @@ namespace ignite
 
             BOOST_TEST_CHECKPOINT("Setting paramset size");
             ret = SQLSetStmtAttr(stmt, SQL_ATTR_PARAMSET_SIZE,
-                 reinterpret_cast<SQLPOINTER>(static_cast<ptrdiff_t>(recordsNum)), 0);
+                                 reinterpret_cast<SQLPOINTER>(static_cast<ptrdiff_t>(recordsNum)), 0);
 
             if (!SQL_SUCCEEDED(ret))
                 BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
 
             BOOST_TEST_CHECKPOINT("Executing query");
-            ret = SQLExecute(stmt);
+
+            return SQLExecute(stmt);
+        }
+
+        int OdbcTestSuite::InsertTestBatch(int from, int to, int expectedToAffect, bool merge)
+        {
+            SQLULEN setsProcessed = 0;
+
+            BOOST_TEST_CHECKPOINT("Setting processed pointer");
+            SQLRETURN ret = SQLSetStmtAttr(stmt, SQL_ATTR_PARAMS_PROCESSED_PTR, &setsProcessed, SQL_IS_POINTER);
+
+            if (!SQL_SUCCEEDED(ret))
+                BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
+
+            ret = InsertTestBatchNoCheck(from, to, merge);
 
             if (!SQL_SUCCEEDED(ret))
                 BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
diff --git a/modules/platforms/cpp/odbc-test/src/queries_test.cpp b/modules/platforms/cpp/odbc-test/src/queries_test.cpp
index 60333ff..aed97ba 100644
--- a/modules/platforms/cpp/odbc-test/src/queries_test.cpp
+++ b/modules/platforms/cpp/odbc-test/src/queries_test.cpp
@@ -1950,6 +1950,27 @@ BOOST_AUTO_TEST_CASE(TestConnectionTimeoutQuery)
     InsertTestStrings(10, false);
 }
 
+BOOST_AUTO_TEST_CASE(TestConnectionTimeoutQueryExpires)
+{
+    Connect("DRIVER={Apache Ignite};ADDRESS=127.0.0.1:11110;SCHEMA=cache;PAGE_SIZE=500000");
+
+    SQLRETURN ret = SQLSetConnectAttr(dbc, SQL_ATTR_CONNECTION_TIMEOUT, reinterpret_cast<SQLPOINTER>(1), 0);
+
+    ODBC_FAIL_ON_ERROR(ret, SQL_HANDLE_DBC, dbc);
+
+    SQLCHAR req[] = "select delay(5000)";
+
+    ret = SQLExecDirect(stmt, req, SQL_NTS);
+
+    BOOST_REQUIRE_EQUAL(ret, SQL_ERROR);
+
+    std::string error = GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt);
+    std::string pattern = "HYT01: Receive operation timed out";
+
+    if (error.substr(0, pattern.size()) != pattern)
+        BOOST_FAIL("'" + error + "' does not match '" + pattern + "'");
+}
+
 BOOST_AUTO_TEST_CASE(TestConnectionTimeoutBatch)
 {
     Connect("DRIVER={Apache Ignite};ADDRESS=127.0.0.1:11110;SCHEMA=cache");
diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/connection.h b/modules/platforms/cpp/odbc/include/ignite/odbc/connection.h
index 1e13348..189438a 100644
--- a/modules/platforms/cpp/odbc/include/ignite/odbc/connection.h
+++ b/modules/platforms/cpp/odbc/include/ignite/odbc/connection.h
@@ -204,7 +204,7 @@ namespace ignite
              *
              * @param req Request message.
              * @param rsp Response message.
-             * @param timeout Timeout.
+             * @param timeout Timeout. 0 means disabled.
              * @return @c true on success, @c false on timeout.
              * @throw OdbcError on error.
              */
diff --git a/modules/platforms/cpp/odbc/src/query/batch_query.cpp b/modules/platforms/cpp/odbc/src/query/batch_query.cpp
index 8b26e0d..e34464c 100644
--- a/modules/platforms/cpp/odbc/src/query/batch_query.cpp
+++ b/modules/platforms/cpp/odbc/src/query/batch_query.cpp
@@ -144,23 +144,12 @@ namespace ignite
             {
                 const std::string& schema = connection.GetSchema();
 
-                QueryExecuteBatchRequest req(schema, sql, params, begin, end, last, timeout,
-                    connection.IsAutoCommit());
+                QueryExecuteBatchRequest req(schema, sql, params, begin, end, last, timeout, connection.IsAutoCommit());
                 QueryExecuteBatchResponse rsp;
 
                 try
                 {
-                    // Setting connection timeout to 1 second more than query timeout itself.
-                    int32_t connectionTimeout = timeout ? timeout + 1 : 0;
-
-                    bool success = connection.SyncMessage(req, rsp, connectionTimeout);
-
-                    if (!success)
-                    {
-                        diag.AddStatusRecord(SqlState::SHYT00_TIMEOUT_EXPIRED, "Query timeout expired");
-
-                        return SqlResult::AI_ERROR;
-                    }
+                    connection.SyncMessage(req, rsp);
                 }
                 catch (const OdbcError& err)
                 {
diff --git a/modules/platforms/cpp/odbc/src/query/data_query.cpp b/modules/platforms/cpp/odbc/src/query/data_query.cpp
index 54723a1..9865164 100644
--- a/modules/platforms/cpp/odbc/src/query/data_query.cpp
+++ b/modules/platforms/cpp/odbc/src/query/data_query.cpp
@@ -233,17 +233,7 @@ namespace ignite
 
                 try
                 {
-                    // Setting connection timeout to 1 second more than query timeout itself.
-                    int32_t connectionTimeout = timeout ? timeout + 1 : 0;
-
-                    bool success = connection.SyncMessage(req, rsp, connectionTimeout);
-
-                    if (!success)
-                    {
-                        diag.AddStatusRecord(SqlState::SHYT00_TIMEOUT_EXPIRED, "Query timeout expired");
-
-                        return SqlResult::AI_ERROR;
-                    }
+                    connection.SyncMessage(req, rsp);
                 }
                 catch (const OdbcError& err)
                 {
@@ -408,16 +398,7 @@ namespace ignite
 
                 try
                 {
-                    // Setting connection timeout to 1 second more than query timeout itself.
-                    int32_t connectionTimeout = timeout ? timeout + 1 : 0;
-                    bool success = connection.SyncMessage(req, rsp, connectionTimeout);
-
-                    if (!success)
-                    {
-                        diag.AddStatusRecord(SqlState::SHYT00_TIMEOUT_EXPIRED, "Query timeout expired");
-
-                        return SqlResult::AI_ERROR;
-                    }
+                    connection.SyncMessage(req, rsp);
                 }
                 catch (const OdbcError& err)
                 {