yandex-cloud / ydb-java-sdk

Yandex Database Java SDK
Other
32 stars 9 forks source link

Unable to connect to serverless YDB #12

Closed planesweep closed 3 years ago

planesweep commented 3 years ago

Hello,

I want to connect to the company serverless YDB database via the ydb-java-sdk. I think there is a bug in the GrpcTransport.forEndpoint(...) implementation.

I executed the examples/CloudConnect.java file as follow:

...

GrpcTransport transport = GrpcTransport.forEndpoint(
                "ydb.serverless.yandexcloud.net:2135",
                "/ru-central1/b1gul4gcbijqmpib7lne/etn03jpffv3jmj168l2j")
                .withAuthProvider(authProvider)
                .withSecureConnection(cert)
                .build();

TableClient tableClient = TableClient.newClient(GrpcTableRpc.useTransport(transport))
                .build();

tableClient.getOrCreateSession(Duration.ofSeconds(60)).join().expect("ok");

The connection fails because the database could not be resolved (UnexpectedResultException).

Response

WARNING: [Channel<3>: (ydb://ydb.serverless.yandexcloud.net:2135/ru-central1/b1gul4gcbijqmpib7lne/etn03jpffv3jmj168l2j)] Failed to resolve name. status=Status{code=UNAVAILABLE, description=unable to resolve database /ru-central1/b1gul4gcbijqmpib7lne/etn03jpffv3jmj168l2j, got non SUCCESS response: TRANSPORT_UNAVAILABLE, issues: [gRPC error: (UNAVAILABLE) io exception (S_ERROR)], cause=null}
Exception in thread "main" com.yandex.ydb.core.UnexpectedResultException: ok: cannot acquire session from pool
    at com.yandex.ydb.core.Result$Error.expect(Result.java:228)
    at com.yandex.ydb.examples.CloudConnect.main(CloudConnect.java:38)
Caused by: java.util.concurrent.CompletionException: com.yandex.ydb.core.UnexpectedResultException: cannot create session, code: TRANSPORT_UNAVAILABLE, issues: [gRPC error: (UNAVAILABLE) unable to resolve database /ru-central1/b1gul4gcbijqmpib7lne/etn03jpffv3jmj168l2j, got non SUCCESS response: TRANSPORT_UNAVAILABLE, issues: [gRPC error: (UNAVAILABLE) io exception (S_ERROR)] (S_ERROR)]
    at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:314)
    at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:319)
    at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:645)
    at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
    at java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2073)
    at com.yandex.ydb.core.grpc.UnaryStreamToFuture.onClose(UnaryStreamToFuture.java:48)
    at io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39)
    at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23)
    at io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40)
    at io.grpc.internal.CensusStatsModule$StatsClientInterceptor$1$1.onClose(CensusStatsModule.java:700)
    at io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39)
    at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23)
    at io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40)
    at io.grpc.internal.CensusTracingModule$TracingClientInterceptor$1$1.onClose(CensusTracingModule.java:399)
    at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:521)
    at io.grpc.internal.ClientCallImpl.access$300(ClientCallImpl.java:66)
    at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:641)
    at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$700(ClientCallImpl.java:529)
    at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInternal(ClientCallImpl.java:703)
    at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:692)
    at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
    at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: com.yandex.ydb.core.UnexpectedResultException: cannot create session, code: TRANSPORT_UNAVAILABLE, issues: [gRPC error: (UNAVAILABLE) unable to resolve database /ru-central1/b1gul4gcbijqmpib7lne/etn03jpffv3jmj168l2j, got non SUCCESS response: TRANSPORT_UNAVAILABLE, issues: [gRPC error: (UNAVAILABLE) io exception (S_ERROR)] (S_ERROR)]
    at com.yandex.ydb.core.Result$Fail.newException(Result.java:196)
    at com.yandex.ydb.core.Result$Fail.expect(Result.java:154)
    at com.yandex.ydb.table.impl.SessionPool.lambda$create$0(SessionPool.java:56)
    at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:642)
    ... 22 more

I am wondering why the protocol/scheme ydb:// instead of grpc:// is used. Is the protocol correct?

On the other hand, with the ydb-python-sdk I am able to connect to the same database . Here I am able to define the protocol type grpc:// explicitly.

python3 __main__.py -e grpcs://ydb.serverless.yandexcloud.net:2135  \
-d /ru-central1/b1gul4gcbijqmpib7lne/etn03jpffv3jmj168l2j

CC: @jamel, @arcadia-devtools

planesweep commented 3 years ago

can be closed replace .withSecureConnection(cert) with .withSecureConnection()