bool-rus / ydb-unofficial

Other
2 stars 0 forks source link

How to use it with default local ydb server from ydb example? #1

Open makorne opened 6 months ago

makorne commented 6 months ago

Hi! Thank you for your great crate!

But how to use it with default local ydb server from ydb example? When I tried:

use ydb_unofficial::sqlx::prelude::*;

     let conn_str =  "grpc://localhost:2136?database=local";
   // "ydbs://localhost:2136?database=local";
     let options = YdbConnectOptions::from_str(&conn_str)?;
     let mut conn = options.connect().await?;
     let path = std::path::Path::new("test/migrations");
     let migrator = Migrator::new(path).await?;
     migrator.run_direct(&mut conn).await?;

ydbs://localhost:2136?database=local

Error: Database(Grpc(Status { code: Unavailable, message: "error trying to connect: received corrupt message of type InvalidContentType", source: Some(tonic::transport::Error(Transport, hyper::Error(Connect, Custom { kind: InvalidData, error: InvalidMessage(InvalidContentType) }))) }))

grpc://localhost:2136?database=local

Error: Database(Grpc(Status { code: Unknown, message: "Bad :scheme header", metadata: MetadataMap { headers: {"content-type": "application/grpc"} }, source: None }))

bool-rus commented 6 months ago

@makorne are you use tls? It not worked without tls with unknown cause.

makorne commented 6 months ago

I tried GRPC_TLS_PORT=2135 too

Error: Database(Grpc(Status { code: Unknown, message: "transport error", source: Some(tonic::transport::Error(Transport, hyper::Error(Io, Custom { kind: BrokenPipe, error: "stream closed because of a broken pipe" }))) }))

Looks like docker image tls part broken:

ydb -e grpc://localhost:2135 -d /local scheme ls


Status: TRANSPORT_UNAVAILABLE
Issues: 
<main>: Error: GRpc error: (14): failed to connect to all addresses; last error: UNAVAILABLE: ipv4:127.0.0.1:2135: Socket closed
<main>: Error: Grpc error response on endpoint localhost:2135
<main>: Error: Endpoint list is empty for database /local, cluster endpoint localhost:2135.
bool-rus commented 6 months ago

I think this is some undocumented peculiarity of the database. I'm not able to test my lib with standalone ydb-database, but it works fine with yandex cloud service. If you can make standalone database instance, I will try to check cause of fail and fix it.

makorne commented 6 months ago

Why cant you setup it self hosted on your PC?

bool-rus commented 6 months ago

i'm on mac

makorne commented 6 months ago

But why dont you use a VirtuaBox? Or KVM? Recent qemu version have support for the macos hypervisor framework, use accel=hvf for that. For example: qemu-system-x86_64 -m 2G -hda ubuntu.20.qcow2 -accel hvf

bool-rus commented 6 months ago

i'm on m1, kvm/virtualbox cannot use because of private reason

makorne commented 6 months ago

Ok. But why dont you use a virtual cloud server for $0.5 for day? Or vps for $2 for month?

bool-rus commented 6 months ago

Ydb server not worked on lowcost wps, it need more ram/disk. I have no time to search optimal configuratoion.

Furthermore, there is no guarantee that it is implemented in ydb standalone. Is official ydb lib worked with ydb standalone? At the time I tested it didn't work.

bool-rus commented 6 months ago

Ok. But why dont you use a virtual cloud server for $0.5 for day? Or vps for $2 for month?

But if you want, YOU can do that.

makorne commented 6 months ago

Ok. But why dont you use a virtual cloud server for $0.5 for day? Or vps for $2 for month?

But if you want, YOU can do that.

Of course I've already done this. Fresh docker:

let conn_str = "ydbs://localhost:2135?database=local";

Error: Database(Grpc(Status { code: Unavailable, message: "error trying to connect: invalid peer certificate: Other(CaUsedAsEndEntity)", source: Some(tonic::transport::Error(Transport, hyper::Error(Connect, Custom { kind: InvalidData, error: InvalidCertificate(Other(CaUsedAsEndEntity)) })))

let conn_str = "ydbs://localhost:2136?database=local";

Error: Database(Grpc(Status { code: Unavailable, message: "error trying to connect: received corrupt message of type InvalidContentType", source: Some(tonic::transport::Error(Transport, hyper::Error(Connect, Custom { kind: InvalidData, error: InvalidMessage(InvalidContentType) }))) }))

bool-rus commented 6 months ago

I think cause in self-singed certificate on your db instance

makorne commented 6 months ago

But examples like ydb-rs-sdk/target/debug/examples/basic-select-upsert` work with the same docker...

sum: 4950
row id '1' with value 'val: 1'
row id '2' with value 'val: 2'
row id '3' with value 'val: 3'
row id '4' with value 'val: 4'
row id '5' with value 'val: 5'
row id '6' with value 'val: 6'
row id '7' with value 'val: 7'
row id '8' with value 'val: 8'
row id '9' with value 'val: 9'
row id '10' with value 'val: 10'
makorne commented 6 months ago

I think cause in self-singed certificate on your db instance

Looks like it's old known tonic issue And can be resolved with adding an openssl as feature

bool-rus commented 2 months ago

@makorne can you try to make cert with lets encrypt, and test local ydb with it?

makorne commented 2 months ago

But I need json anyway, so I came back to ydb official.

bool-rus commented 1 month ago

But I need json anyway, so I came back to ydb official.

maybe it's not that hard to implement such a feature. I'll try

bool-rus commented 1 month ago

I think cause in self-singed certificate on your db instance

Looks like it's old known tonic issue And can be resolved with adding an openssl as feature

@makorne can you help with test it?

makorne commented 1 month ago

Will be happy, my online friend!

makorne commented 1 week ago

I think cause in self-singed certificate on your db instance

Looks like it's old known tonic issue And can be resolved with adding an openssl as feature

@makorne can you help with test it?

What do you mean? Test connection to local ydb server in docker?

grpcs://localhost:2135?database=/local Database(Grpc(Status { code: Unavailable, message: "error trying to connect: invalid peer certificate: Other(CaUsedAsEndEntity)", source: Some(tonic::transport::Error(Transport, hyper::Error(Connect, Custom { kind: InvalidData, error: InvalidCertificate(Other(CaUsedAsEndEntity)) }))) }))

grpc://localhost:2136?database=/local << This one work with ydb official

Database(Grpc(Status { code: Unknown, message: "Bad :scheme header", metadata: MetadataMap { headers: {"content-type": "application/grpc"} }, source: None }))

makorne commented 1 week ago
let db_name = "local".to_string();
let ep = ydb_unofficial::client::YdbEndpoint {ssl: false, host: "localhost".to_owned(), port: 2136, load_factor: 0.0};
let pool = ydb_unofficial::pool::YdbPoolBuilder::new(creds, db_name.try_into().unwrap(), ep).build().unwrap();
let mut conn = pool.get().await.unwrap();
let mut table = conn.table().await.unwrap();  << Here
`Result::unwrap()` on an `Err` value: Grpc(Status { code: Unknown, message: "Bad :scheme header", metadata: MetadataMap { headers: {"content-type": "application/grpc"} }, source: None })