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

Question: How to handle error thrown by TiKV #9

Open
JaySon-Huang opened this issue Mar 2, 2021 · 10 comments · May be fixed by #10
Open

Question: How to handle error thrown by TiKV #9

JaySon-Huang opened this issue Mar 2, 2021 · 10 comments · May be fixed by #10
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@JaySon-Huang
Copy link
Contributor

JaySon-Huang commented Mar 2, 2021

## Setup a cluster by TiUP playground
client-cpp>  tiup playground --nightly

## Then run the example program of `tikv/client-cpp`
client-cpp> make run-example
RUST_LOG=debug /data3/my/client-cpp/target/tikv-example
[2021-03-02T14:29:15Z INFO  tikv_client_common::security] connect to rpc server at endpoint: "127.0.0.1:2379"
[2021-03-02T14:29:15Z WARN  tikv_client_pd::cluster] PD endpoint 127.0.0.1:2379 failed to respond: Grpc(RpcFailure(RpcStatus { status: 14-UNAVAILABLE, details: Some("failed to connect to all addresses") }))
terminate called after throwing an instance of 'rust::cxxbridge1::Error'
  what():  [/root/.cargo/git/checkouts/client-rust-5a1ccd35a54db20f/89ac804/tikv-client-pd/src/cluster.rs:174]: PD cluster failed to respond
make: *** [run-example] Aborted

client-cpp>  make run-example
RUST_LOG=debug /data3/my/client-cpp/target/tikv-example
[2021-03-02T14:30:34Z INFO  tikv_client_common::security] connect to rpc server at endpoint: "127.0.0.1:2379"
[2021-03-02T14:30:34Z INFO  tikv_client_pd::cluster] All PD endpoints are consistent: ["127.0.0.1:2379"]
[2021-03-02T14:30:34Z INFO  tikv_client_common::security] connect to rpc server at endpoint: "http://127.0.0.1:2379"
[2021-03-02T14:30:34Z INFO  tikv_client_common::security] connect to rpc server at endpoint: "http://127.0.0.1:2379"
get key k1:v2
terminate called after throwing an instance of 'rust::cxxbridge1::Error'
  what():  Leader of region 2 is not found
make: *** [run-example] Aborted

I try to run the example program while setting up a tiup-playground cluster, it throws some errors.

For example, if I want to write some code to handle leader not found error, now I have to write it like

    auto txn = client.begin();

    txn.put("k1", "v2");

    bool success = false;
    while (!success) {
        try {
            txn.commit();
            success = true;
        } catch (rust::cxxbridge1::Error &e) {
            // Ignore Leader not found and try to commit again
            std::string err_msg = e.what();
            if (err_msg.find("Leader of region") == std::string::npos) {
                // Other error, throw exception
                throw;
            }
        }
    }

Can client-cpp throw different kind of Exception? So I can write codes like:

    auto txn = client.begin();

    txn.put("k1", "v2");

    bool success = false;
    while (!success) {
        try {
            txn.commit();
            success = true;
        } catch (tikv_client::LeaderNotFoundException &e) {
            // Ignore Leader not found and try to commit again
        }
    }
@JaySon-Huang JaySon-Huang changed the title How to handle error Question: How to handle error Mar 2, 2021
@JaySon-Huang JaySon-Huang changed the title Question: How to handle error Question: How to handle error thrown by TiKV Mar 22, 2021
@andylokandy andylokandy added help wanted Extra attention is needed enhancement New feature or request labels Mar 22, 2021
@anishagg17
Copy link

I would like to work on this one, can any maintainer assign this issue to me?

@anishagg17
Copy link

It seems that rust::cxxbridge1::Error has LeaderNotFound as an instance, have you tried rust::cxxbridge1::LeaderNotFound as a type?

@andylokandy
Copy link
Collaborator

@anishagg17 As described in the cxx tutorial, any errors from Rust will be wrapped into an instance of rust::Error provided by cxx, which distinguishes errors only by the message string. I'd like to add custom error types that inherit std::exception and reflect the errors in the rust client. This requires us to return a custom FFI-Result instead of the std::result::Result which should simply be a struct containing an error message and an error code.

@anishagg17
Copy link

Hi, @andylokandy can you please share your environment specifications?

I have macOS, the make command failed with clang as it wasn't able to link ssl and crypto,
then I added the paths to include ssl and crypto library but didn't work

c++ $(cur_makefile_path)/example/main.cpp -o $(cur_makefile_path)/target/tikv-example -std=c++17 -g -I$(cur_makefile_path)/include -L$(cur_makefile_path)/target/debug -ltikv_client -lpthread -ldl -L/usr/local/Cellar/openssl@1.1/1.1.1k/lib -L/usr/local/opt/openssl@1.1/lib -I/usr/local/Cellar/openssl@1.1/1.1.1k/lib -I/usr/local/opt/openssl@1.1/include/openssl -lssl -lcrypto  -v

I even tried gcc11 but none works.

@andylokandy
Copy link
Collaborator

What is the error message it outputs?

@anishagg17
Copy link

clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [target/tikv-example] Error 1

@andylokandy
Copy link
Collaborator

Try using the openssl from homebrew: https://formulae.brew.sh/formula/openssh

@anishagg17
Copy link

anishagg17 commented May 19, 2021

Try using the openssl from homebrew: https://formulae.brew.sh/formula/openssh

still the same error, I have installed openssl previously also. The link you provided is for openssh, I installed it and ran into same error

@j619s
Copy link

j619s commented May 20, 2021

I am using WSL2 with distro as Ubuntu and the tiup playground nightly runs fine. But when I am trying to run make run-example it says failed to run custom build command for tikv-client-proto v0.0.0 (https://github.com/tikv/client-rust.git?rev=3fad149#3fad149f)``.

Caused by:
process didn't exit successfully: /mnt/c/Users/JATIN/Desktop/Rust/client-cpp/target/debug/build/tikv-client-proto-5d1618a7041c86b4/build-script-build (exit code: 101)
--- stderr
thread 'main' panicked at 'Could not create file: Os { code: 36, kind: Other, message: "File name too long" }', /root/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/protobuf-build-0.12.0/src/wrapper.rs:41:58
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
Building [===================================================> ] 238/248: grpcio-sys(build)

@anishagg17 anishagg17 linked a pull request May 22, 2021 that will close this issue
@Smityz
Copy link
Contributor

Smityz commented Jun 20, 2023

I am using WSL2 with distro as Ubuntu and the tiup playground nightly runs fine. But when I am trying to run make run-example it says tikv-client-proto v0.0.0 (https://github.com/tikv/client-rust.git?rev=3fad149#3fad149f)``%60%60).failed to run custom build command for

Caused by: process didn't exit successfully: (exit code: 101) --- stderr thread 'main' panicked at 'Could not create file: Os { code: 36, kind: Other, message: "File name too long" }', /root/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/protobuf-build-0.12.0/src/wrapper.rs:41:58 note: run with environment variable to display a backtrace warning: build failed, waiting for other jobs to finish... Building [===================================================> ] 238/248: grpcio-sys(build)/mnt/c/Users/JATIN/Desktop/Rust/client-cpp/target/debug/build/tikv-client-proto-5d1618a7041c86b4/build-script-build``RUST_BACKTRACE=1

I think it's a separate problem, perhaps you should open another issue to discuss it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants