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

Fix system cityhash setup #301

Merged
merged 1 commit into from
May 24, 2023
Merged

Conversation

ZhongRuoyu
Copy link
Contributor

@ZhongRuoyu ZhongRuoyu commented Apr 19, 2023

cityhash does not provide any CMake packages. Add a Findcityhash.cmake script to help find cityhash.

@CLAassistant
Copy link

CLAassistant commented Apr 19, 2023

CLA assistant check
All committers have signed the CLA.

@Enmk
Copy link
Collaborator

Enmk commented Apr 21, 2023

Thank you for a contribution!

Quick question: how do you test this setup? It looks like libcityhash-dev or any other cityhash packages are missing from any recent Ubuntu repos. I've tried 22.04, 20.04, and 18.04, all to no avail.

@ZhongRuoyu
Copy link
Contributor Author

Homebrew does provide the cityhash package :) . We are already working around this in Homebrew/homebrew-core#128575, with the following adjustments:

    # `cityhash` does not provide a pkg-config or CMake config file.
    # Help CMake find it.
    inreplace "CMakeLists.txt", "FIND_PACKAGE(cityhash REQUIRED)",
                                "FIND_LIBRARY(CITYHASH NAMES cityhash REQUIRED)"
    inreplace "clickhouse/CMakeLists.txt", "cityhash::cityhash", "cityhash"

With this, the build passed on both macOS and Linux.

I suggest trying the following in a homebrew/ubuntu22.04 Docker container, to verify the fix:

brew install cityhash cmake

git clone https://github.com/ClickHouse/clickhouse-cpp.git
cd clickhouse-cpp

# This should fail
cmake -S . -B build -DWITH_SYSTEM_CITYHASH=ON -DCMAKE_FIND_ROOT_PATH="$(brew --prefix)"

# This should work
git fetch origin refs/pull/301/head:fix
git checkout fix
export CXXFLAGS="-I`brew --prefix cityhash`/include"
cmake -S . -B build -DWITH_SYSTEM_CITYHASH=ON -DCMAKE_FIND_ROOT_PATH="$(brew --prefix)"
cmake --build build -j "$(nproc)"

@Enmk
Copy link
Collaborator

Enmk commented Apr 21, 2023

Nice! Could you please add a workflow that verifies such setup? That would be a more solid guarantee that it doesn't break in the future :)

@ZhongRuoyu
Copy link
Contributor Author

ZhongRuoyu commented Apr 22, 2023

Sure, I've pushed 45edfc1 and fefc0ee. I also adjusted the patch to avoid additional -L linker flags, because it seems that /usr/local/lib is not in macOS's default linker search paths (error here).

However, when testing this on my fork, some of the tests failed. Specifically, these on Linux, and these on macOS. The failing tests reported DB::Exception: Checksum doesn't match:, so I suspect that this is due to a mismatch between the cityhash versions (clickhouse-cpp uses v1.0.2, while Homebrew ships the latest v1.1.1).

According to cityhash's changelog, cityhash v1.1 did "Change existing functions to improve their hash quality and/or speed". Does this raise a concern?

@Enmk
Copy link
Collaborator

Enmk commented Apr 24, 2023

According to cityhash's changelog, cityhash v1.1 did "Change existing functions to improve their hash quality and/or speed". Does this raise a concern?

Breaking a hash compatibility with CH server is a big "no-no", perhaps you can choose another version from homebrew to install?

@ZhongRuoyu
Copy link
Contributor Author

ZhongRuoyu commented Apr 24, 2023

Understood. In that case, I think we'll have to use the vendored cityhash because Homebrew does not support installing a specific version of a formula (package). I opened Homebrew/homebrew-core#129222 to fix this in Homebrew's clickhouse-cpp.

And as for this PR, let me see what I can do here. Some of the failures seem unrelated -- are they transient SSL issues?

@Enmk
Copy link
Collaborator

Enmk commented Apr 24, 2023

SSL errors seem to be unrelated, maybe just some network issues, but rest are pretty suspicious, especially:

Windows MSVC

https://github.com/ClickHouse/clickhouse-cpp/actions/runs/4772342534/jobs/8517401004?pr=301
ArrayOfLowCardinality.InsertAndQuery
GenericColumnTest/0.RoundTrip
GenericColumnTest/0.NulableT_RoundTrip
GenericColumnTest/1.RoundTrip
GenericColumnTest/1.NulableT_RoundTrip
closed: The operation completed successfully.

MacOS

https://github.com/ClickHouse/clickhouse-cpp/actions/runs/4772342519/jobs/8517401026?pr=301
ArrayOfLowCardinality.InsertAndQuery
"closed: Operation now in progress"

https://github.com/ClickHouse/clickhouse-cpp/actions/runs/4772342519/jobs/8517401280?pr=301
ArrayOfLowCardinality.InsertAndQuery
"closed: Operation now in progress"

CMakeLists.txt Outdated Show resolved Hide resolved
ZhongRuoyu added a commit to ZhongRuoyu/homebrew-core that referenced this pull request Apr 24, 2023
Use the vendored version (1.0.2) of `cityhash` because newer versions
break hash compatibility. See:
  ClickHouse/clickhouse-cpp#301 (comment)
@ZhongRuoyu
Copy link
Contributor Author

OK, I think I'll need to roll back the workflow changes because I don't know any system that ships this very version of cityhash (v1.0.2). (The fact that the clickhouse library was built should suggest that the changes are fine, though.)

As for the other failures, I am very confused because I haven't touched the Windows / MinGW workflows at all. Anyway, I've tried to keep only the CMake changes in another testing branch; the tests should work fine.

@@ -38,12 +38,18 @@ IF (WITH_OPENSSL)
LIST(APPEND clickhouse-cpp-lib-src base/sslsocket.cpp)
ENDIF ()

IF (WITH_SYSTEM_CITYHASH AND NOT cityhash_FOUND)
SET (CITYHASH ${SYSTEM_CITYHASH})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps we can add something similar to https://github.com/ClickHouse/clickhouse-cpp/blob/master/cmake/Findlz4.cmake to properly set a cityhash::cityhash imported library instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's actually a good idea. I pushed a Findcityhash.cmake and that should do it. I've verified this with a workflow in my fork: https://github.com/ZhongRuoyu/clickhouse-cpp/actions/runs/4840656304/jobs/8626442071#step:7:41. (Failure is due to a mismatched cityhash version, as discussed earlier -- but it's functional.)

cityhash does not provide any CMake packages. Add a `Findcityhash.cmake`
script to help find cityhash.

Signed-off-by: Ruoyu Zhong <zhongruoyu@outlook.com>
Copy link
Contributor

@xakod xakod left a comment

Choose a reason for hiding this comment

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

Looks nice, thank you!

@Enmk
Copy link
Collaborator

Enmk commented May 24, 2023

Temporary closing to re-trigger against latest master

@Enmk Enmk closed this May 24, 2023
@Enmk Enmk reopened this May 24, 2023
@Enmk Enmk merged commit dbbdefc into ClickHouse:master May 24, 2023
@ZhongRuoyu ZhongRuoyu deleted the system-cityhash branch May 24, 2023 23:57
@ZhongRuoyu
Copy link
Contributor Author

Thanks for the help to get this merged, @Enmk @Jihadist!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants