MikhailNazarov / ydb-rs-sqlx

Sqlx integration for YDB rust SDK
https://ydb.tech/
Apache License 2.0
2 stars 1 forks source link

Read request aborted #6

Closed makorne closed 3 weeks ago

makorne commented 1 month ago

Hi! Thank you for your useful crate!

But there seems to be some errors here. Often the data is not written to tables or not readable. I`m using a local ydb in docker to avoid network errors. I have never seen such on a regular ydb client.

For example:

 AnyDriverError(
    YdbStatusError(
        YdbStatusError {
            message: "Operation { id: \"\", ready: true, status: Aborted, issues: [IssueMessage { position: None, message: \"Read request aborted\", end_position: None, issue_code: 0, severity: 1, issues: [IssueMessage { position: None, message: \"Table id 13 has no snapshot at v1726892378240/18446744073709551615 shard 72075186224037896 with lowWatermark v1726892768183/0 (node# 1 state# Ready)\", end_position: None, issue_code: 0, severity: 1, issues: [] }] }], result: Some(Any { type_url: \"type.googleapis.com/Ydb.Table.ExecuteQueryResult\", value: [18, 28, 10, 26, 48, 49, 106, 56, 57, 99, 120, 50, 51, 55, 49, 57, 97, 107, 102, 114, 49, 50, 102, 102, 98, 48, 101, 104, 54, 48] }), metadata: None, cost_info: None }",
            operation_status: 400040,
            issues: [
                YdbIssue {
                    issue_code: 0,
                    message: "Read request aborted",
                    issues: [
                        YdbIssue {
                            issue_code: 0,
                            message: "Table id 13 has no snapshot at v1726892378240/18446744073709551615 shard 72075186224037896 with lowWatermark v1726892768183/0 (node# 1 state# Ready)",
                            issues: [],
                            severity: Error,
                        },
                    ],
                    severity: Error,
                },
            ],
        },
    ),
)

Or

 AnyDriverError(
    YdbStatusError(
        YdbStatusError {
            message: "Operation { id: \"\", ready: true, status: BadSession, issues: [IssueMessage { position: None, message: \"Session not found: ydb://session/3?node_id=1&id=NWVmYmRjZTYtZWY1YzExYWQtNGE4OWNlMjctZTQ0NGQ3MjE=\", end_position: None, issue_code: 0, severity: 1, issues: [] }], result: None, metadata: None, cost_info: None }",
            operation_status: 400100,
            issues: [
                YdbIssue {
                    issue_code: 0,
                    message: "Session not found: ydb://session/3?node_id=1&id=NWVmYmRjZTYtZWY1YzExYWQtNGE4OWNlMjctZTQ0NGQ3MjE=",
                    issues: [],
                    severity: Error,
                },
            ],
        },
    ),
)
MikhailNazarov commented 1 month ago

Thank you for issue! I will investigate this issue

MikhailNazarov commented 1 month ago

Second issue is related to original ydb client I suppose that first too

makorne commented 4 weeks ago

I'm not sure. I'm developing two projects on both of then, and I've never seen this problem on the original. Now I`ve transferred the second one to the original, and the problem is gone. Maybe it will appear under load, but in your project it appears even with single requests.

makorne commented 4 weeks ago

May be the issue because wrong implemenation of u8 and u16 types? They dont work and I was temparary changed the colums on u32.

YdbStatusError(YdbStatusError { message: "Operation { id: \"\", ready: true, status: BadRequest, issues: [IssueMessage { position: None, message: \"contrib/ydb/core/kqp/session_actor/kqp_session_actor.cpp:768: Invalid value representation for type: Uint8, expected value case: 3, but current: 2\", end_position: None, issue_code: 0, severity: 1, issues: [] }], result: Some(Any { type_url: \"type.googleapis.com/Ydb.Table.ExecuteQueryResult\", value: [18, 28, 10, 26, 48, 49, 106, 56, 118, 107, 52, 100, 56, 112, 49, 103, 51, 113, 116, 120, 49, 113, 118, 118, 53, 100, 97, 113, 110, 52] }), metadata: None, cost_info: None }", operation_status: 400010, issues: [YdbIssue { issue_code: 0, message: "contrib/ydb/core/kqp/session_actor/kqp_session_actor.cpp:768: Invalid value representation for type: Uint8, expected value case: 3, but current: 2", issues: [], severity: Error }]

MikhailNazarov commented 4 weeks ago

I create simple example:

use std::{env, str::FromStr};

use tracing::{info, Level};

use ydb::{ydb_params, ClientBuilder, ServiceAccountCredentials};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    init_logs();

    let connection_string =
        env::var("YDB_CONNECTION_STRING").map_err(|_| "YDB_CONNECTION_STRING not set")?;

    let client = ClientBuilder::new_from_connection_string(connection_string)?
        .with_credentials(ServiceAccountCredentials::from_env()?)
        .client()?;

    info!("Waiting for client");
    client.wait().await?;

    let table_client =  client.table_client();

    table_client.retry_execute_scheme_query("CREATE TABLE test (id Uint64 NOT NULL, name Utf8, age UInt8, description Utf8, PRIMARY KEY (id))").await?;

    let res = table_client.retry_transaction(|mut t| async move {

       let desc: Option<String> = None;
       let res = t.query(ydb::Query::from(r#"
        DECLARE $id as Uint64;
        DECLARE $name as Text;
        DECLARE $age as Uint8;
        DECLARE $descr as Text?;

        INSERT INTO test (id, name, age, description) VALUES ( $id, $name, $age, $descr)
       "#).with_params(
        ydb_params!(
            "id" => 1,
            "name" => "test".to_owned(),
            "age" => 33u8,
            "descr" => desc
        )
       )).await?;
       Ok(res)   
    }).await?;
    info!("res: {:?}", res);

    Ok(())
}

fn init_logs() {
    let level = env::var("RUST_LOG").unwrap_or("INFO".to_string());
    let log_level = Level::from_str(&level).unwrap();
    let subscriber = tracing_subscriber::FmtSubscriber::builder()
        .with_max_level(log_level)
        .finish();
    tracing::subscriber::set_global_default(subscriber).expect("Error setting subscriber");
}

and have this error:

 ERROR ydb::client_table: error=YdbStatusError(YdbStatusError { message: "Operation { id: \"\", ready: true, status: BadRequest, issues: [IssueMessage { position: None, message: \"contrib/ydb/core/kqp/session_actor/kqp_session_actor.cpp:902: Invalid value representation for type: Uint8, expected value case: 3, but current: 2\", end_position: None, issue_code: 0, severity: 1, issues: [] }], result: Some(Any { type_url: \"type.googleapis.com/Ydb.Table.ExecuteQueryResult\", value: [18, 28, 10, 26, 48, 49, 106, 56, 122, 107, 52, 102, 98, 107, 102, 110, 48, 53, 52, 51, 115, 57, 54, 122, 54, 56, 115, 122, 102, 97] }), metadata: None, cost_info: None }", operation_status: 400010, issues: [YdbIssue { issue_code: 0, message: "contrib/ydb/core/kqp/session_actor/kqp_session_actor.cpp:902: Invalid value representation for type: Uint8, expected value case: 3, but current: 2", issues: [], severity: Error }] })
Error: YdbStatusError(YdbStatusError { message: "Operation { id: \"\", ready: true, status: BadRequest, issues: [IssueMessage { position: None, message: \"contrib/ydb/core/kqp/session_actor/kqp_session_actor.cpp:902: Invalid value representation for type: Uint8, expected value case: 3, but current: 2\", end_position: None, issue_code: 0, severity: 1, issues: [] }], result: Some(Any { type_url: \"type.googleapis.com/Ydb.Table.ExecuteQueryResult\", value: [18, 28, 10, 26, 48, 49, 106, 56, 122, 107, 52, 102, 98, 107, 102, 110, 48, 53, 52, 51, 115, 57, 54, 122, 54, 56, 115, 122, 102, 97] }), metadata: None, cost_info: None }", operation_status: 400010, issues: [YdbIssue { issue_code: 0, message: "contrib/ydb/core/kqp/session_actor/kqp_session_actor.cpp:902: Invalid value representation for type: Uint8, expected value case: 3, but current: 2", issues: [], severity: Error }] })
MikhailNazarov commented 4 weeks ago

I created an issue: https://github.com/ydb-platform/ydb-rs-sdk/issues/210

makorne commented 3 weeks ago

I didn`t do it because it makes no sense. Sdk is dead. There 33 errors that are not resolved for 3 month! Even already self-assigned by developer! This simple errors with u8 and u16 is just because the developer is too lazy and does not write tests and examples

MikhailNazarov commented 3 weeks ago

I created pull request https://github.com/ydb-platform/ydb-rs-sdk/pull/211 that fixed this issue and also update my fork for sqlx implementation. Test example is now working as expected.