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

obkv-table-client-rs 驱动 运行报错 #6

Open
FrankXMX opened this issue Nov 16, 2022 · 7 comments
Open

obkv-table-client-rs 驱动 运行报错 #6

FrankXMX opened this issue Nov 16, 2022 · 7 comments

Comments

@FrankXMX
Copy link

场景:

observer、ob-configserver部署成功,且使用obkv-table-client-java测试正常。obkv-table-client-rs的demo编译正常,运行报错。

报错信息:

frank@LAPTOP-4OF1323N:~/ob/obkv/obkv_cli$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.21s
     Running `target/debug/obkv_cli`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: MySqlError { ERROR 1193 (HY000): Unknown system variable 'socket' }', /home/frank/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/mysql-16.1.0/src/conn/mod.rs:1760:61
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

详细报错信息:


frank@LAPTOP-4OF1323N:~/ob/obkv/obkv_cli$ RUST_BACKTRACE=full cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.69s
     Running `target/debug/obkv_cli`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: MySqlError { ERROR 1193 (HY000): Unknown system variable 'socket' }', /home/frank/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/mysql-16.1.0/src/conn/mod.rs:1760:61
stack backtrace:
   0:     0x560e07436cc0 - std::backtrace_rs::backtrace::libunwind::trace::h32eb3e08e874dd27
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x560e07436cc0 - std::backtrace_rs::backtrace::trace_unsynchronized::haa3f451d27bc11a5
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x560e07436cc0 - std::sys_common::backtrace::_print_fmt::h5b94a01bb4289bb5
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x560e07436cc0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb070b7fa7e3175df
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x560e0745a42e - core::fmt::write::hd5207aebbb9a86e9
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/fmt/mod.rs:1202:17
   5:     0x560e07430b95 - std::io::Write::write_fmt::h3bd699bbd129ab8a
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/io/mod.rs:1679:15
   6:     0x560e074384f3 - std::sys_common::backtrace::_print::h7a21be552fdf58da
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x560e074384f3 - std::sys_common::backtrace::print::ha85c41fe4dd80b13
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x560e074384f3 - std::panicking::default_hook::{{closure}}::h04cca40023d0eeca
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:295:22
   9:     0x560e074381df - std::panicking::default_hook::haa3ca8c310ed5402
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:314:9
  10:     0x560e07438b9a - std::panicking::rust_panic_with_hook::h7b190ce1a948faac
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:698:17
  11:     0x560e07438a97 - std::panicking::begin_panic_handler::{{closure}}::hbafbfdc3e1b97f68
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:588:13
  12:     0x560e0743716c - std::sys_common::backtrace::__rust_end_short_backtrace::hda93e5fef243b4c0
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:138:18
  13:     0x560e074387b2 - rust_begin_unwind
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:584:5
  14:     0x560e069f72d3 - core::panicking::panic_fmt::h8d17ca1073d9a733
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:142:14
  15:     0x560e069f7423 - core::result::unwrap_failed::hfaddf24b248137d3
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/result.rs:1785:5
  16:     0x560e070f868b - core::result::Result<T,E>::unwrap::hd6ca67c4717efe46
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/result.rs:1107:23
  17:     0x560e07107801 - mysql::conn::Conn::get_system_var::h266a2955a72cb6a1
                               at /home/frank/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/mysql-16.1.0/src/conn/mod.rs:1760:20
  18:     0x560e070fd2ce - mysql::conn::Conn::can_improved::h9ce62211aa045e11
                               at /home/frank/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/mysql-16.1.0/src/conn/mod.rs:713:26
  19:     0x560e070fd86f - mysql::conn::Conn::new::h204349fa80266ed3
                               at /home/frank/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/mysql-16.1.0/src/conn/mod.rs:734:37
  20:     0x560e0711e8ce - mysql::conn::pool::InnerPool::new_conn::hcc71942bbf27d52a
                               at /home/frank/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/mysql-16.1.0/src/conn/pool.rs:43:15
  21:     0x560e0711e761 - mysql::conn::pool::InnerPool::new::h2984a33ddecf7061
                               at /home/frank/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/mysql-16.1.0/src/conn/pool.rs:38:13
  22:     0x560e06b0011a - mysql::conn::pool::Pool::new_manual::hc31bb0b50ebbccd0
                               at /home/frank/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/mysql-16.1.0/src/conn/pool.rs:200:20
  23:     0x560e06acbd55 - obkv::location::ObTableLocation::get_or_create_mysql_pool::he665093014ad6c6c
                               at /home/frank/ob/obkv/obkv-table-client-rs/src/location/mod.rs:567:33
  24:     0x560e06acde75 - obkv::location::ObTableLocation::get_table_entry_from_remote::hb099b29e8cb6f108
                               at /home/frank/ob/obkv/obkv-table-client-rs/src/location/mod.rs:816:20
  25:     0x560e06acd338 - obkv::location::ObTableLocation::load_table_entry_randomly::hbbb127c1b5fe71a7
                               at /home/frank/ob/obkv/obkv-table-client-rs/src/location/mod.rs:664:9
  26:     0x560e06a9d575 - obkv::client::table_client::ObTableClientInner::init_metadata::h97474ac57aadcd07
                               at /home/frank/ob/obkv/obkv-table-client-rs/src/client/table_client.rs:1273:13
  27:     0x560e06a9b22d - obkv::client::table_client::ObTableClientInner::init::h26e654a285580413
                               at /home/frank/ob/obkv/obkv-table-client-rs/src/client/table_client.rs:1142:9
  28:     0x560e06a9fd3b - obkv::client::table_client::ObTableClient::init::h84cd50a11ba30a5f
                               at /home/frank/ob/obkv/obkv-table-client-rs/src/client/table_client.rs:1489:9
  29:     0x560e069fba1c - obkv_cli::build_client::ha0c2d099ef90f6d0
                               at /home/frank/ob/obkv/obkv_cli/src/main.rs:37:5
  30:     0x560e069fbfd6 - obkv_cli::main::h8cc4d8f2d6733d3e
                               at /home/frank/ob/obkv/obkv_cli/src/main.rs:76:18
  31:     0x560e069f809b - core::ops::function::FnOnce::call_once::h8587ff7b46b6bd57
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/ops/function.rs:248:5
  32:     0x560e069f795e - std::sys_common::backtrace::__rust_begin_short_backtrace::h7927763c39832bbb
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:122:18
  33:     0x560e069f7731 - std::rt::lang_start::{{closure}}::h128c88e20d637041
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/rt.rs:166:18
  34:     0x560e0742d12f - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hb69be6e0857c6cfb
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/ops/function.rs:283:13
  35:     0x560e0742d12f - std::panicking::try::do_call::h396dfc441ee9c786
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:492:40
  36:     0x560e0742d12f - std::panicking::try::h6cdda972d28b3a4f
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:456:19
  37:     0x560e0742d12f - std::panic::catch_unwind::h376039ec264e8ef9
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panic.rs:137:14
  38:     0x560e0742d12f - std::rt::lang_start_internal::{{closure}}::hc94720ca3d4cb727
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/rt.rs:148:48
  39:     0x560e0742d12f - std::panicking::try::do_call::h2422fb95933fa2d5
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:492:40
  40:     0x560e0742d12f - std::panicking::try::h488286b5ec8333ff
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:456:19
  41:     0x560e0742d12f - std::panic::catch_unwind::h81636549836d2a25
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panic.rs:137:14
  42:     0x560e0742d12f - std::rt::lang_start_internal::h6ba1bb743c1e9df9
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/rt.rs:148:20
  43:     0x560e069f770a - std::rt::lang_start::h572baf80932b36e1
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/rt.rs:165:17
  44:     0x560e069fc1d1 - main
  45:     0x7fc944aced90 - <unknown>
  46:     0x7fc944acee40 - __libc_start_main
  47:     0x560e069f7605 - _start
  48:                0x0 - <unknown>

测试代码:

// Copyright 2022 CeresDB Project Authors. Licensed under Apache-2.0.

extern crate obkv;

use std::{sync::Arc, thread, time};

use obkv::{serde_obkv::value::Value, Builder, ClientConfig, ObTableClient, RunningMode, Table};

// TODO: use test conf to control which environments to test.
const TEST_FULL_USER_NAME: &str = "frank@sys#obcluster";
const TEST_URL: &str = "http://172.18.108.43:8080/services?Action=ObRootServiceInfo&ObCluster=obcluster&database=test";
const TEST_PASSWORD: &str = "frank";
const TEST_SYS_USER_NAME: &str = "root@sys";
const TEST_SYS_PASSWORD: &str = "root";

fn build_client(mode: RunningMode) -> ObTableClient {
    let mut config = ClientConfig::default();
    config.min_idle_conns_per_server = 1;
    config.max_conns_per_server = 1;
    config.rpc_connect_timeout = std::time::Duration::from_secs(1);
    config.metadata_mysql_conn_pool_max_size = 1;
    config.metadata_mysql_conn_pool_min_size = 1;

    let builder = Builder::new()
        .full_user_name(TEST_FULL_USER_NAME)
        .param_url(TEST_URL)
        .running_mode(mode)
        .password(TEST_PASSWORD)
        .sys_user_name(TEST_SYS_USER_NAME)
        .sys_password(TEST_SYS_PASSWORD);

    let client = builder.build();

    assert!(client.is_ok());

    let client = client.unwrap();
    client.init().expect("Fail to create obkv client.");
    client
}

const TABLE_NAME: &str = "series_key_to_id_0";
// read and write the table:
// create table series_key_to_id_0 (
//  series_key VARBINARY(8096) NOT NULL,
//  series_id BIGINT NOT NULL,
//  PRIMARY KEY(series_key),
//  KEY index_id(series_id)
// );
fn concurrent_insert(client: Arc<ObTableClient>) {
    let mut thds = Vec::with_capacity(20);
    for i in 0..50 {
        let client = client.clone();
        let thd = thread::spawn(move || {
            for j in i * 100..(i * 100 + 50) {
                let series_key = format!("series_key_test_padding_padding_{}", j);
                let series_id = j * j;
                client
                    .insert(
                        TABLE_NAME,
                        vec![Value::from(series_key.clone())],
                        vec!["series_id".to_owned()],
                        vec![Value::from(series_id as i64)],
                    )
                    .expect(&format!("fail to insert row:{} {}", series_key, series_id));
            }
        });
        thds.push(thd);
    }

    for (i, thd) in thds.into_iter().enumerate() {
        thd.join().expect(&format!("thread#{} fail to join", i));
    }
}

fn main() {
    let client = build_client(RunningMode::Normal);
    client
        .truncate_table(TABLE_NAME)
        .expect("fail to truncate the table");
    let start = time::Instant::now();
    concurrent_insert(Arc::new(client));
    let elapsed = time::Instant::now() - start;
    println!("Benches::concurrent_insert cost time:{:?}", elapsed);
}

curl测试ob-configserver正常:

frank@LAPTOP-4OF1323N:~/ob/obkv/obkv_cli$ curl "http://172.18.108.43:8080/services?Action=ObRootServiceInfo&ObCluster=obcluster&database=test" | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   337  100   337    0     0  29355      0 --:--:-- --:--:-- --:--:-- 30636
{
  "Code": 200,
  "Message": "successful",
  "Success": true,
  "Data": {
    "ObClusterId": 1,
    "ObRegionId": 1,
    "ObCluster": "obcluster",
    "ObRegion": "obcluster",
    "ReadonlyRsList": [],
    "RsList": [
      {
        "address": "127.0.0.1:2882",
        "role": "LEADER",
        "sql_port": 2881
      }
    ],
    "Type": "PRIMARY",
    "timestamp": 1668058564676408
  },
  "Trace": "0a55540c19c43d88",
  "Server": "172.18.108.43",
  "Cost": 6
}

@jiacai2050
Copy link
Contributor

Which OB version are you testing?

We only test this SDK against 2.33 or less than 1.0

@FrankXMX
Copy link
Author

OB version:3.1.4

@FrankXMX
Copy link
Author

实验步骤:https://www.modb.pro/db/559123

@jiacai2050
Copy link
Contributor

jiacai2050 commented Nov 17, 2022

We haven't test against 3.1.4, maybe there are wire protocol changes, we will fix this in future, thanks for reporting.

PS: Welcome to open a PR to fix this if you're interested.

@FrankXMX
Copy link
Author

看了一下,主要原因应该是mysql的package版本是16.1.0,这个版本过低了,query的语法发生了变化。接口可能不兼容了,需要改的地方有点多。主要修改点在src/location/mod.rs、src/location/util.rs里面。mysql驱动升级到23.0.0后修改对应的接口,理论上可以解决。

@J0HN50N133
Copy link
Contributor

J0HN50N133 commented Aug 10, 2023

@jiacai2050 我在OB 4.1.0重复了 @FrankXMX 下面的操作,同样会得到这个错误,但是我观察到mysql的package已经升级到了24.0.0,但问题依然存在。

实验步骤:https://www.modb.pro/db/559123

经过Debug发现错误发生在创建Mysql Pool的时候。由于上面builder构造参数的时候prefer_socket一项默认为true,当client通过127.0.0.1创建连接成功后,则会尝试通过socket文件进行连接。由于实验中的oceanbase是部署在docker中的,故无法找到socket文件,因而连接错误。

我将prefer_socket一项设置为false(如下图):
图片
执行本项目的cargo test,则会出现下面的错误:
图片
原因目前还不知道

@IHEII
Copy link
Contributor

IHEII commented Aug 11, 2023

@JohnsonLee-debug Thank you for helping to solve the problem of the MySQL pool in docker!

Conclusion: obkv-table-client-rs dosen't support 4.x observer now.

We need meta info for routing in the client. Currently, this information is obtained through SQL. Different versions of observers need to use different methods and SQL. We now only support 3.x and 2.x observers.

PS: Welcome to open an issue related to the problem of the MySQL pool in the docker.

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

No branches or pull requests

4 participants