Skip to content
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

Refactoring of Server.h: Isolate server management from other logic #64132

Merged
merged 3 commits into from
May 26, 2024

Conversation

TTPO100AJIEX
Copy link
Contributor

@TTPO100AJIEX TTPO100AJIEX commented May 20, 2024

Logic to manage protocol servers is implemented in the global Server class, which is responsible for the "main" function. I find it reasonable to abstract this in a separate class responsible only for managing the list of servers to improve readability and code encapsulation.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

@CLAassistant
Copy link

CLAassistant commented May 20, 2024

CLA assistant check
All committers have signed the CLA.

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label May 20, 2024
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-improvement Pull request with some product improvements label May 20, 2024
@robot-ch-test-poll3
Copy link
Contributor

robot-ch-test-poll3 commented May 20, 2024

This is an automated comment for commit 7a313e7 with description of existing statuses. It's updated for the latest CI running

❌ Click here to open a full report in a separate page

Check nameDescriptionStatus
A SyncThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS⏳ pending
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help❌ failure
CI runningA meta-check that indicates the running CI. Normally, it's in success or pending state. The failed status indicates some problems with the PR⏳ pending
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests❌ failure
Mergeable CheckChecks if all other necessary checks are successful⏳ pending
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc❌ failure
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts❌ failure
Successful checks
Check nameDescriptionStatus
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ success
ClickHouse build checkBuilds ClickHouse in various configurations for use in further steps. You have to fix the builds that fail. Build logs often has enough information to fix the error, but you might have to reproduce the failure locally. The cmake options can be found in the build log, grepping for cmake. Use these options and follow the general build process✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker keeper imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docker server imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docs checkBuilds and tests the documentation✅ success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here✅ success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integration tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
PR CheckThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests✅ success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors✅ success
Style checkRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success

Copy link
Member

@rschu1ze rschu1ze left a comment

Choose a reason for hiding this comment

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

To be honest, extracting and splitting the code into separate files makes sense if it was used by multiple places but this is not the case here. The only user of "InterServerManager" and "ProtocolServersManager" is Server.cpp. Things are IMHO easier to understand if everything is in one place. I would therefore prefer to not merge this PR (unless there is a good reason which I missed).

@rschu1ze rschu1ze self-assigned this May 21, 2024
@TTPO100AJIEX
Copy link
Contributor Author

TTPO100AJIEX commented May 21, 2024

To be honest, extracting and splitting the code into separate files makes sense if it was used by multiple places but this is not the case here. The only user of "InterServerManager" and "ProtocolServersManager" is Server.cpp. Things are IMHO easier to understand if everything is in one place. I would therefore prefer to not merge this PR (unless there is a good reason which I missed).

The idea behind the change was to aid the addition of new protocols - a relatively common improvement that should not require modifications of existing code. Currently, besides implementing the new logic, you would have to change Server.cpp, which is over 2500 lines of code - not the best experience. 
After the change, the code will be encapsulated in ServersManager - a class responsible solely for holding a list of servers, which aids in making the Server responsible for exactly one thing - initialization of all components. With the Manager, everything related to running the servers will remain in one (but different) place explicitly separated from everything else happening in the Server. Thus, to add a new protocol, one would need to modify only a much smaller file - ProtocolServersManager.cpp. 
Furthermore, both InterServersManager and ProtocolServersManager have a hard-coded list of servers to run, which I think is a bad architectural decision. Abstracting this logic in separate classes helps later rework this as well.
Finally, there is similar logic in Keeper.cpp: https://github.com/ClickHouse/ClickHouse/blob/master/programs/keeper/Keeper.cpp#L441 . We might find a way to encapsulate all three places behind a common interface, which improves code readability.

@TTPO100AJIEX TTPO100AJIEX marked this pull request as ready for review May 21, 2024 21:44
@rschu1ze
Copy link
Member

@TTPO100AJIEX Okay, fine with me then, thanks! The only problem I have at this point is that the PR mixes tons of unrelated formatting/cosmetic changes with actual refactorings (moved code). I am really not against formatting changes, but in order to make this reviewable and also revertable (<-- in case something goes wrong), we need to separate the signal from the noise. Therefore, it would be nice if you could rework the commit history (commit messages are at the moment trash anyways - excuse me, just stating the obvious), and make two commits: 1. with all formatting changes 2. the actual refactoring - then force-push and remove "[WIP]" from the PR title.

@clickhouse-ci clickhouse-ci bot added the manual approve Manual approve required to run CI label May 23, 2024
@TTPO100AJIEX TTPO100AJIEX reopened this May 23, 2024
Co-authored-by: Alex Koledaev <ax3l3rator@gmail.com>
@TTPO100AJIEX TTPO100AJIEX changed the title [WIP] Abstract ProtocolServer logic Isolate server management from other logic in clickhouse-server May 24, 2024
@TTPO100AJIEX
Copy link
Contributor Author

@rschu1ze Could you please have a look at the PR? I have removed the styling changes and squashed the commits. There are some failed tests, but I do not understand how the changes could have affected them (especially the upgrade check). Is there a possibility those tests are inherently broken? Could you please clarify, what exactly those tests are checking?

@rschu1ze
Copy link
Member

Checking now.

I also restarted the failing tests (they are indeed unrelated).

Copy link
Member

@rschu1ze rschu1ze left a comment

Choose a reason for hiding this comment

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

Thanks! In general, the refactoring looks like it was done right though I did not step through the code or verify it further.

Please see my (mostly minor) comments, after adressing them we can merge.

src/Server/ServersManager/IServersManager.cpp Outdated Show resolved Hide resolved
src/Server/ServersManager/InterServersManager.h Outdated Show resolved Hide resolved
src/Server/ServersManager/IServersManager.h Show resolved Hide resolved
@TTPO100AJIEX
Copy link
Contributor Author

TTPO100AJIEX commented May 24, 2024

@rschu1ze The CI has been completed. Some tests failed, but they seem unrelated to the changes again (and they are different from what had failed before). Could you please merge the PR as it is?

@rschu1ze rschu1ze changed the title Isolate server management from other logic in clickhouse-server Refactoring of Server.h: Isolate server management from other logic May 26, 2024
@rschu1ze rschu1ze added this pull request to the merge queue May 26, 2024
Merged via the queue into ClickHouse:master with commit 79bcc54 May 26, 2024
229 of 244 checks passed
@tavplubix
Copy link
Member

@rschu1ze, some CI checks have not finished

@TTPO100AJIEX
Copy link
Contributor Author

TTPO100AJIEX commented May 27, 2024

@rschu1ze, some CI checks have not finished

@tavplubix But aren't those checks just broken or flaky? Something fails for all PRs, and the changes do not seem to be related to the failed tests.
Are any more modifications required to merge this change?

@rschu1ze
Copy link
Member

@TTPO100AJIEX As you probably know, ClickHouse also maintains an internal repository and all "public" PRs are picked in the background into the non-public repo. In this case, there was a merge conflict in the non-public repository (as can be expected by such large refactorings) but I merged your PR yesterday without noticing. By bad, sorry. I'll do a revert of the revert soon and check/resolve these conflicts.

@javisantana
Copy link
Contributor

javisantana commented Jun 7, 2024

I do think you guys should give a heads up about this kind of things to the community, otherwise it'll be impossible to contribute in a few months (when your fork diverges enough)

@rschu1ze
Copy link
Member

rschu1ze commented Jun 7, 2024

Sorry for the delay, priorities got a bit disarranged for me this week. I'll definitely check today, promised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can be tested Allows running workflows for external contributors manual approve Manual approve required to run CI pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants