Seeking help with the issue of compiling TiKV's client-c source code with unit test options, resulting in a final compilation failure

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: tikv的client-c源码加单元测试编译选项,最后编译失败的问题求助

| username: TiDBer_CozPRH8J

To improve efficiency, please provide the following information. Clear problem descriptions can help solve issues faster:
【TiDB Usage Environment】

【Overview】 Scenario + Problem Overview

【Application Framework and Business Logic Adaptation】

【Background】 The client-c code of tikv compiles without issues using the default cmake, but when using the command cmake -DENABLE_TESTS=ON … it compiles to 100% and then a bunch of grpc-related errors appear. Has anyone encountered this and how to solve it?

【Phenomenon】 Business and database phenomenon

【Problem】 The client-c code of tikv compiles without issues using the default cmake, but when using the command cmake -DENABLE_TESTS=ON … it compiles to 100% and then a bunch of grpc-related errors appear. Has anyone encountered this and how to solve it?

【Business Impact】

【TiDB Version】

【Attachments】 Related logs and monitoring (https://metricstool.pingcap.com/)


If the question is related to performance optimization or troubleshooting, please download the script and run it. Please select all and copy-paste the terminal output.

| username: gengliqi-PingCAP | Original post link

I tried compiling locally on my Mac without any issues. Try clearing the build directory, running cmake -DENABLE_TESTS=ON again, and then make?

| username: TiDBer_CozPRH8J | Original post link

You mean clearing the compilation. Did you compile it as a root user? Did you pre-install other grpc and poco libraries into the system directory? I pulled the code under a non-root account, then recompiled and installed it into a custom directory based on cmake errors, and then specified the prefix directory in the find_xxx.cmake file in the cmake directory before compiling with cmake.

| username: TiDBer_CozPRH8J | Original post link

Could I add you on WeChat to ask for detailed advice? We are working on domestic storage-related matters.

| username: gengliqi-PingCAP | Original post link

My environment on the CentOS 7 server includes grpc (v1.26), protobuf (v3.8.0), and poco (poco-1.9.0-release), all manually installed using make install. What version of the grpc library are you using? What are your compilation commands?

| username: TiDBer_CozPRH8J | Original post link

Oh, then you should be compiling as the root user by default. I pulled the latest master of grpc from git, and the same for poco. The grpc compilation command is:

cmake ../.. -DgRPC_INSTALL=ON\
-DCMAKE_BUILD_TYPE=Release\
-DCMAKE_INSTALL_PREFIX=/home/zhangzhiliang/testDemo/grpc/cmake/build\
-DgRPC_ABSL_PROVIDER=module\
-DgRPC_CARES_PROVIDER=module\
-DgRPC_PROTOBUF_PROVIDER=module\
-DgRPC_RE2_PROVIDER=module\
-DgRPC_SSL_PROVIDER=module\
-DgRPC_ZLIB_PROVIDER=module

By the way, in your client-c directory, the find_grpc.cmake files in cmake will report errors, right? If not modified, I added a line before find_packet to specify the include and lib directories of the grpc installation with CMAKE_PREFIX_PATH. Can you add me on WeChat for a detailed discussion? Thanks.

| username: gengliqi-PingCAP | Original post link

Sorry, I realized that I didn’t add -DENABLE_TESTS=ON when compiling with CentOS 7. After adding it just now, I found the same error. Previously, there were no issues when compiling tests on my local Mac. We’ll look into why this is happening and get back to you.

I directly installed gRPC to the system directory using make install, so I didn’t modify find_grpc.cmake. Your modification seems fine as well.

Additionally, it’s better to discuss technical issues here so that the information can be preserved and serve as a reference for other team members.

| username: TiDBer_CozPRH8J | Original post link

Okay, then adding -DENABLE_TESTS=ON also causes issues. It should be the same problem on my side. If I don’t add it, it can compile by default on my side.

| username: gengliqi-PingCAP | Original post link

You can try compiling gRPC into a dynamic link library (add -DBUILD_SHARED_LIBS=ON to the cmake parameters). After making the changes on my side, it was able to compile.

I will fix the issue with static linking not compiling later.

| username: TiDBer_CozPRH8J | Original post link

Okay, thank you.

| username: TiDBer_CozPRH8J | Original post link

Let me ask again, the client-c only has these few interfaces for adding, deleting, and querying, and they all have no return values, they are all void. How can this be used in production? We don’t know if the transaction or set operation was actually successful. Without these, it won’t pass the review with the leadership.

| username: TiDBer_CozPRH8J | Original post link

After recompiling gRPC into a dynamic library, the following error occurred when compiling the client-c project:


Do you have any other special configurations on your side?

| username: gengliqi-PingCAP | Original post link

The client-c transmits errors through exceptions, so it requires try-catch when using it. However, it is not recommended to use client-c for adding, deleting, or querying, as these interfaces have not been maintained for a long time. Currently, client-c is only used for TiFlash to perform coprocessor reads for other TiFlash instances and to send resolve lock requests to TiKV.

| username: gengliqi-PingCAP | Original post link

There is nothing special. It looks like libabsl_synchronization.so is missing. By the way, did you run git submodule update --init --recursive when compiling grpc?

| username: TiDBer_CozPRH8J | Original post link

Yes, I have seen this library.

| username: gengliqi-PingCAP | Original post link

It is necessary to add some absl link libraries in the CMakefile. I am using grpc version 1.26, which by default does not depend on abseil, so it can be compiled without linking these.

| username: TiDBer_CozPRH8J | Original post link

Adding this, there are still other errors. I set it up again on Alibaba Cloud, and the unit tests have also been compiled. However, directly using libkv_client in the test program causes issues. This is really frustrating. I suggest the official team should provide static compilation and add a usage document. Using this client has too high a threshold and the errors are very confusing.

| username: TiDBer_CozPRH8J | Original post link

Additionally, the compiled libkv_client.a static library cannot be used when I write a test program and compile it into an executable. It shows a bunch of undefined errors. Is it because grpc is a dynamic library when compiling client-c, causing a conflict? Can you try and see if this usage works on your side?

| username: system | Original post link

This topic was automatically closed 1 minute after the last reply. No new replies are allowed.