-
Notifications
You must be signed in to change notification settings - Fork 138
IGNITE-27870 added proxy class. #7607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,29 @@ function(fetch_dependency NAME URL MD5) | |
| endif() | ||
| endfunction() | ||
|
|
||
| function(add_asio_dependency) | ||
| message(STATUS "Download dependency: asio") | ||
| # FetchContent_Declare( | ||
| # asio | ||
| # GIT_REPOSITORY https://github.com/chriskohlhoff/asio.git | ||
| # GIT_TAG asio-1-36-0 | ||
| # ) | ||
|
|
||
| FetchContent_Declare( | ||
| asio | ||
| URL https://github.com/chriskohlhoff/asio/archive/refs/tags/asio-1-36-0.tar.gz | ||
| URL_HASH MD5=6699ac1dea111c20d024f25e06e573db | ||
| ) | ||
|
|
||
| FetchContent_Populate(asio) | ||
|
|
||
| add_library(asio INTERFACE) | ||
|
|
||
| target_include_directories(asio INTERFACE ${asio_SOURCE_DIR}/asio/include) | ||
|
|
||
| target_compile_definitions(asio INTERFACE ASIO_STANDALONE) | ||
| endfunction() | ||
|
|
||
| if (${USE_LOCAL_DEPS}) | ||
| find_package(msgpack REQUIRED) | ||
| if (${msgpack_FOUND}) | ||
|
|
@@ -76,6 +99,7 @@ else() | |
| fetch_dependency(uni-algo https://github.com/uni-algo/uni-algo/archive/v1.2.0.tar.gz 6e0cce94a6b45ebee7b904316df9f87f) | ||
| if (${ENABLE_TESTS}) | ||
| fetch_dependency(googletest https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz c8340a482851ef6a3fe618a082304cfc) | ||
| add_asio_dependency(https://github.com/chriskohlhoff/asio/archive/refs/tags/asio-1-36-0.tar.gz 6699ac1dea111c20d024f25e06e573db) | ||
|
||
| endif() | ||
| endif() | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,6 +22,7 @@ set(SOURCES | |||||||
| fake_server.cpp | ||||||||
| tcp_client_channel.cpp | ||||||||
| connection_test.cpp | ||||||||
| proxy/asio_proxy.cpp | ||||||||
|
||||||||
| proxy/asio_proxy.cpp | |
| proxy/asio_proxy.cpp | |
| proxy/kgb_proxy.cpp |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,13 +15,16 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * limitations under the License. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "tests/client-test/ignite_runner_suite.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "ignite/client/ignite_client.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "fake_server.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "ignite/client/ignite_client.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "proxy/kgb_proxy.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "proxy/asio_proxy.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "tests/client-test/ignite_runner_suite.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <gtest/gtest.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <thread> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using namespace ignite; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using namespace std::chrono_literals; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -76,3 +79,40 @@ TEST_F(connection_test, request_timeout) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EXPECT_EQ(error::code::OPERATION_TIMEOUT, err.get_status_code()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // TEST_F(connection_test, using_proxy) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // fake_server fs{50900, get_logger()}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // proxy::kgb_proxy proxy{50800, 50900}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // fs.start(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // proxy.start(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ignite_client_configuration cfg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // cfg.set_logger(get_logger()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // cfg.set_endpoints(get_endpoints()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // auto cl = ignite_client::start(cfg, 5s); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // auto cluster_nodes = cl.get_cluster_nodes(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ASSERT_EQ(1, cluster_nodes.size()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+83
to
+100
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // TEST_F(connection_test, using_proxy) { | |
| // fake_server fs{50900, get_logger()}; | |
| // proxy::kgb_proxy proxy{50800, 50900}; | |
| // | |
| // fs.start(); | |
| // proxy.start(); | |
| // | |
| // ignite_client_configuration cfg; | |
| // cfg.set_logger(get_logger()); | |
| // cfg.set_endpoints(get_endpoints()); | |
| // | |
| // auto cl = ignite_client::start(cfg, 5s); | |
| // | |
| // auto cluster_nodes = cl.get_cluster_nodes(); | |
| // | |
| // ASSERT_EQ(1, cluster_nodes.size()); | |
| // } | |
| TEST_F(connection_test, using_proxy) { | |
| fake_server fs{50900, get_logger()}; | |
| proxy::kgb_proxy proxy{50800, 50900}; | |
| fs.start(); | |
| proxy.start(); | |
| ignite_client_configuration cfg; | |
| cfg.set_logger(get_logger()); | |
| cfg.set_endpoints(get_endpoints()); | |
| auto cl = ignite_client::start(cfg, 5s); | |
| auto cluster_nodes = cl.get_cluster_nodes(); | |
| ASSERT_EQ(1, cluster_nodes.size()); | |
| } |
Copilot
AI
Feb 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The timeout value of 500 seconds seems excessively long for a unit test. This is inconsistent with other tests in the same file that use 5s timeout (line 50, 94). Consider using a more reasonable timeout value consistent with other tests.
| auto cl = ignite_client::start(cfg, 500s); | |
| auto cl = ignite_client::start(cfg, 5s); |
Copilot
AI
Feb 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The io_context.run() will continue executing until all work is completed or the io_context is stopped. When the test ends, there's no mechanism to stop the io_context, which means the thread will continue running indefinitely. The test should call io_context.stop() and then join the thread to ensure proper cleanup. Consider adding a test fixture teardown or ensuring cleanup at the end of the test.
| ASSERT_EQ(1, cluster_nodes.size()); | |
| ASSERT_EQ(1, cluster_nodes.size()); | |
| io_context.stop(); | |
| t.join(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // 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. | ||
| // | ||
|
|
||
| // | ||
|
|
||
| #include "asio_proxy.h" |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,214 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| // 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. | ||||||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| #pragma once | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| #include <iostream> | ||||||||||||||||||||||||||||||||||||||||||||||
| #include <queue> | ||||||||||||||||||||||||||||||||||||||||||||||
| #include <tuple> | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| #include <asio.hpp> | ||||||||||||||||||||||||||||||||||||||||||||||
| #include <asio/ts/buffer.hpp> | ||||||||||||||||||||||||||||||||||||||||||||||
| #include <asio/ts/internet.hpp> | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| namespace ignite::proxy { | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| using asio::ip::tcp; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| struct message { | ||||||||||||||||||||||||||||||||||||||||||||||
| char *m_arr; | ||||||||||||||||||||||||||||||||||||||||||||||
| size_t m_size; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| message(char *arr, size_t size) | ||||||||||||||||||||||||||||||||||||||||||||||
| : m_arr(nullptr) | ||||||||||||||||||||||||||||||||||||||||||||||
| , m_size(size) { | ||||||||||||||||||||||||||||||||||||||||||||||
| m_arr = new char[m_size]; | ||||||||||||||||||||||||||||||||||||||||||||||
| std::memcpy(m_arr, arr, size); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
| message(const message &) = delete; | |
| message &operator=(const message &) = delete; | |
| message(message &&other) noexcept | |
| : m_arr(other.m_arr) | |
| , m_size(other.m_size) { | |
| other.m_arr = nullptr; | |
| other.m_size = 0; | |
| } | |
| message &operator=(message &&other) noexcept { | |
| if (this != &other) { | |
| delete[] m_arr; | |
| m_arr = other.m_arr; | |
| m_size = other.m_size; | |
| other.m_arr = nullptr; | |
| other.m_size = 0; | |
| } | |
| return *this; | |
| } |
Copilot
AI
Feb 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lambda captures references to queue and writable (&queue, &writable), which are local references in the do_read function that point to members of 'this'. If 'this' (the session) is destroyed before the async operation completes, these references will be dangling. The session should be kept alive by capturing shared_from_this() in the lambda to ensure the object outlives the async operation.
Copilot
AI
Feb 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the issue in do_read, the lambda captures references (&queue, &writable) which point to members of 'this'. If the session is destroyed before the async operation completes, these references will be dangling. The session should be kept alive by capturing shared_from_this() in the lambda.
Copilot
AI
Feb 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The session buffer is reused across multiple async read operations without proper synchronization. If multiple read operations are in progress (forward and reverse), they may both write to the same 'buf' array simultaneously, causing data corruption. Each direction should have its own buffer to prevent race conditions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented-out code should be removed rather than left in the codebase. If this alternative implementation using GIT_REPOSITORY is needed for reference, consider documenting it in a comment or external documentation instead.