Skip to content

Composable protocol#41198

Merged
yakov-olkhovskiy merged 35 commits intomasterfrom
composable-protocol
Oct 17, 2022
Merged

Composable protocol#41198
yakov-olkhovskiy merged 35 commits intomasterfrom
composable-protocol

Conversation

@yakov-olkhovskiy
Copy link
Copy Markdown
Member

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Composable protocol configuration is added.

closes #38411

protocols configuration example:

    <protocols>
        <tcp>
            <type>tcp</type>
            <host>127.0.0.1</host>
            <port>9000</port>
            <description>native protocol (tcp)</description>
        </tcp>
        <tcp_secure>
            <type>tls</type>
            <impl>tcp</impl>
            <host>127.0.0.1</host>
            <port>9440</port>
            <description>secure native protocol (tcp_secure)</description>
        </tcp_secure>
        <tcp2>
            <impl>tcp</impl>
            <host>127.0.0.1</host>
            <port>9101</port>
            <description>native protocol second endpoint (tcp)</description>
        </tcp2>
        <tcp_secure2>
            <impl>tcp_secure</impl>
            <host>127.0.0.1</host>
            <port>9541</port>
            <description>secure native protocol second endpoint (tcp_secure)</description>
        </tcp_secure2>
        <mysql>
            <type>mysql</type>
            <host>127.0.0.1</host>
            <port>9004</port>
            <description>mysql</description>
        </mysql>
    </protocols>

@robot-ch-test-poll robot-ch-test-poll added the pr-feature Pull request with new product feature label Sep 11, 2022
throw Exception(ErrorCodes::INVALID_CONFIG_PARAMETER, "Protocol configuration error, unknown protocol name '{}'", type);
};

for (const auto & protocol : protocols)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that it is a WIP, but I was just passing by, and want to note about applying changes w/o server restart (Server::updateServers())

@yakov-olkhovskiy yakov-olkhovskiy marked this pull request as ready for review September 15, 2022 12:51
@devcrafter devcrafter self-assigned this Sep 16, 2022
bool listen_try = config.getBool("listen_try", false);
if (!listen_try)
listen_try = DB::getMultipleValuesFromConfig(config, "", "listen_host").empty();
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please could you add comment what we are doing here and why?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still have no idea - this will only affect starting interserver - lines starting at 2153 - the logic is that if config listen_try is false, make it true if no listen_host is configured (which means this node doesn't serve anything but interserver communication). And this change will preserve this logic with composable protocols.

throw Exception(ErrorCodes::SUPPORT_IS_DISABLED, "SSL support is disabled");
#endif
return std::make_shared<FunctionShowCertificate>();
return std::make_shared<FunctionShowCertificate>(ctx->getQueryContext()->getClientInfo().certificate);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear if the pointers access is safe (is it guaranteed that they are not null?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is guaranteed

<clickhouse>
<profiles>
<default>
<max_memory_usage>10000000000</max_memory_usage>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need these settings?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's just a copy-paste from some other test - does nothing

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's not necessary, let's remove it?

IServer & server [[maybe_unused]];
Poco::Logger * log;
std::string conf_name;
std::list<TCPServerConnectionFactory::Ptr> stack;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace with vector

Comment on lines +1931 to +1932
if (config.has(prefix + "port"))
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use the code below to reduce unnecessary nesting

if (!config.has(...))
   continue;

@@ -0,0 +1,69 @@
import ssl
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add tests with incorrect configs

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't make much sense - server will just not start

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, my PoV - we've added some checks about config correctness for layer protocol, which would be nice to test. You to decide

throw Exception(ErrorCodes::INVALID_CONFIG_PARAMETER, "Protocol '{}' configuration contains a loop on '{}'", protocol, conf_name);
}

if (!stack || stack->size() == 0)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!stack - does it make sense here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stack->size() == 0 -> stack->empty()

bool is_secure = false;
auto stack = std::make_unique<TCPProtocolStackFactory>(*this, conf_name);

while (true)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to move this logic to a function, something like buildProtocolStackFromConfig(). It'll contain create_factory() lambda as well and will not blow up createServers() method

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are too many connections in the code - dispatching it through function parameters will be quite cumbersome and will make code less clear

<clickhouse>
<profiles>
<default>
<max_memory_usage>10000000000</max_memory_usage>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's not necessary, let's remove it?

@@ -0,0 +1,69 @@
import ssl
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, my PoV - we've added some checks about config correctness for layer protocol, which would be nice to test. You to decide

http_params->setTimeout(settings.http_receive_timeout);
http_params->setKeepAliveTimeout(keep_alive_timeout);

Poco::Util::AbstractConfiguration::Keys protocols;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still would ask you to move this code to a separate method/function. The method will not have more parameters than Server::createServers, composable protocol creation code will be localized in certain method and will not blow up existing method.


void append(TCPServerConnectionFactory::Ptr factory)
{
stack.push_back(factory);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
stack.push_back(factory);
stack.push_back(std::move(factory));

@devcrafter
Copy link
Copy Markdown
Member

It'd be nice if you could address this comment, but I don't insist. The concern is, - adding new functionality this way is a right way to make code less readable

@yakov-olkhovskiy
Copy link
Copy Markdown
Member Author

@devcrafter already did - probably you are looking at previous version?

@devcrafter
Copy link
Copy Markdown
Member

@devcrafter already did - probably you are looking at previous version?

Sorry then. Thanks 👍

@yakov-olkhovskiy yakov-olkhovskiy merged commit 3ce1fa0 into master Oct 17, 2022
@yakov-olkhovskiy yakov-olkhovskiy deleted the composable-protocol branch October 17, 2022 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Composable protocols configuration of the server.

4 participants