英文:
Failed to connect to my own azure cosmos db instance using ScalarDB
问题
在测试 ScalarDB(2.2.0 版本)的 Cosmos DB 功能时,我无法通过 ScalarDB 连接到 Azure Cosmos DB 实例。当我尝试使用以下代码初始化 DistributedTransaction 或 Cosmos 对象时:
DatabaseConfig cosmosDBConfig = new DatabaseConfig(f);
Cosmos cosmos = new Cosmos(cosmosDBConfig);
DistributedTransactionManager db = Guice.createInjector(new TransactionModule(cosmosDBConfig))
.getInstance(TransactionService.class); // 此处失败
// 也尝试过这个
// Cosmos cosmos = new Cosmos(cosmosDBConfig); // 此处失败
我遇到了以下错误:
网络故障
java.lang.IllegalArgumentException: port out of range: -1
at java.net.InetSocketAddress.checkPort(InetSocketAddress.java:143)
...
我还尝试了在节点js和Java客户端上使用 Cosmos DB SDK(不使用 ScalarDB),成功向实例插入数据。以下是我的 ScalarDB 配置。我甚至尝试在我的一个 Azure 虚拟机上运行 ScalarDB 初始化代码,但仍然出现相同的错误。以下是我的 ScalarDB 配置:
scalar.db.contact_points=<InstanceContactPoints>
scalar.db.contact_port=<DefaultPort>
scalar.db.username=<InstanceUsername>
scalar.db.password=<InstancePassword>
scalar.db.storage=cosmos
我想知道是否我的配置有问题?如何进行设置?提前感谢您的帮助。
英文:
While i was testing the functionality of cosmosdb of the scalardb (2.2.0), i couldn’t connect to the azure cosmos db instance via scalardb, when i try to initialize the DistributedTransaction or the Cosmos object with the following code
DatabaseConfig cosmosDBConfig = new DatabaseConfig(f);
Cosmos cosmos = new Cosmos(cosmosDBConfig);
DistributedTransactionManager db = Guice.createInjector(new TransactionModule(cosmosDBConfig))
.getInstance(TransactionService.class); // failed here
// also tried with this
// Cosmos cosmos = new Cosmos(cosmosDBConfig); // fail here
and I got the following errors
Network failure
java.lang.IllegalArgumentException: port out of range:-1
at java.net.InetSocketAddress.checkPort(InetSocketAddress.java:143)
at java.net.InetSocketAddress.<init>(InetSocketAddress.java:188)
at reactor.netty.tcp.InetSocketAddressUtil.createForIpString(InetSocketAddressUtil.java:88)
at reactor.netty.tcp.InetSocketAddressUtil.createInetSocketAddress(InetSocketAddressUtil.java:74)
at reactor.netty.tcp.InetSocketAddressUtil.createUnresolved(InetSocketAddressUtil.java:48)
at reactor.netty.tcp.TcpUtils._updatePort(TcpUtils.java:91)
at reactor.netty.tcp.TcpUtils.updatePort(TcpUtils.java:73)
at reactor.netty.tcp.TcpClient.lambda$port$5(TcpClient.java:411)
at reactor.netty.tcp.TcpClientBootstrap.configure(TcpClientBootstrap.java:39)
at reactor.netty.tcp.TcpClientBootstrap.configure(TcpClientBootstrap.java:39)
at reactor.netty.tcp.TcpClientBootstrap.configure(TcpClientBootstrap.java:39)
at reactor.netty.tcp.TcpClientBootstrap.configure(TcpClientBootstrap.java:39)
at reactor.netty.tcp.TcpClient.connect(TcpClient.java:196)
at reactor.netty.http.client.HttpClientFinalizer.connect(HttpClientFinalizer.java:68)
at reactor.netty.http.client.HttpClientFinalizer.responseConnection(HttpClientFinalizer.java:85)
at com.azure.cosmos.implementation.http.ReactorNettyClient.send(ReactorNettyClient.java:123)
at com.azure.cosmos.implementation.RxGatewayStoreModel.performRequest(RxGatewayStoreModel.java:159)
at com.azure.cosmos.implementation.RxGatewayStoreModel.read(RxGatewayStoreModel.java:91)
at com.azure.cosmos.implementation.RxGatewayStoreModel.invokeAsyncInternal(RxGatewayStoreModel.java:351)
at com.azure.cosmos.implementation.RxGatewayStoreModel.lambda$invokeAsync$3(RxGatewayStoreModel.java:366)
at com.azure.cosmos.implementation.BackoffRetryUtility.lambda$executeRetry$0(BackoffRetryUtility.java:34)
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:44)
at reactor.core.publisher.FluxRetryWhen.subscribe(FluxRetryWhen.java:79)
at reactor.core.publisher.MonoRetryWhen.subscribeOrReturn(MonoRetryWhen.java:46)
at reactor.core.publisher.FluxFromMonoOperator.subscribe(FluxFromMonoOperator.java:76)
at reactor.core.publisher.FluxDefer.subscribe(FluxDefer.java:54)
at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:150)
at reactor.core.publisher.MonoDelay$MonoDelayRunnable.run(MonoDelay.java:117)
at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:68)
at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:28)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Failed to retrieve database account information. java.lang.IllegalArgumentException: port out of range:-1
Fail to reach global gateway [scalardb-test-cosmos.cassandra.cosmos.azure.com], [null]
startRefreshLocationTimerAsync() - Unable to refresh database account from any location. Exception: CosmosException{userAgent=Linux/4.18.0-147.8.1.el8_1.x86_64 JRE/1.8.0_252 cosmosdb-java-sdk/4.1.0, error=null, resourceAddress='null', requestUri='null', statusCode=0, message=null, causeInfo=[class: class java.lang.IllegalArgumentException, message: port out of range:-1], responseHeaders={}, requestHeaders=[Accept=application/json, x-ms-date=Thu, 01 Oct 2020 09:28:49 GMT]}
CosmosException{userAgent=Linux/4.18.0-147.8.1.el8_1.x86_64 JRE/1.8.0_252 cosmosdb-java-sdk/4.1.0, error=null, resourceAddress='null', requestUri='null', statusCode=0, message=null, causeInfo=[class: class java.lang.IllegalArgumentException, message: port out of range:-1], responseHeaders={}, requestHeaders=[Accept=application/json, x-ms-date=Thu, 01 Oct 2020 09:28:49 GMT]}
at com.azure.cosmos.BridgeInternal.createCosmosException(BridgeInternal.java:281)
at com.azure.cosmos.implementation.RxGatewayStoreModel.lambda$toDocumentServiceResponse$2(RxGatewayStoreModel.java:301)
at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:88)
at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onError(FluxMapFuseable.java:134)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onError(MonoFlatMap.java:165)
at reactor.core.publisher.MonoSingle$SingleSubscriber.onError(MonoSingle.java:141)
at reactor.core.publisher.Operators.error(Operators.java:196)
at reactor.core.publisher.FluxFlatMap.trySubscribeScalarMap(FluxFlatMap.java:134)
at reactor.core.publisher.MonoFlatMapMany.subscribeOrReturn(MonoFlatMapMany.java:49)
at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:57)
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
at reactor.core.publisher.FluxRetryWhen.subscribe(FluxRetryWhen.java:79)
at reactor.core.publisher.MonoRetryWhen.subscribeOrReturn(MonoRetryWhen.java:46)
at reactor.core.publisher.FluxFromMonoOperator.subscribe(FluxFromMonoOperator.java:76)
at reactor.core.publisher.FluxDefer.subscribe(FluxDefer.java:54)
at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:150)
at reactor.core.publisher.MonoDelay$MonoDelayRunnable.run(MonoDelay.java:117)
at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:68)
at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:28)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalArgumentException: port out of range:-1
at java.net.InetSocketAddress.checkPort(InetSocketAddress.java:143)
at java.net.InetSocketAddress.<init>(InetSocketAddress.java:188)
at reactor.netty.tcp.InetSocketAddressUtil.createForIpString(InetSocketAddressUtil.java:88)
at reactor.netty.tcp.InetSocketAddressUtil.createInetSocketAddress(InetSocketAddressUtil.java:74)
at reactor.netty.tcp.InetSocketAddressUtil.createUnresolved(InetSocketAddressUtil.java:48)
at reactor.netty.tcp.TcpUtils._updatePort(TcpUtils.java:91)
at reactor.netty.tcp.TcpUtils.updatePort(TcpUtils.java:73)
at reactor.netty.tcp.TcpClient.lambda$port$5(TcpClient.java:411)
at reactor.netty.tcp.TcpClientBootstrap.configure(TcpClientBootstrap.java:39)
at reactor.netty.tcp.TcpClientBootstrap.configure(TcpClientBootstrap.java:39)
at reactor.netty.tcp.TcpClientBootstrap.configure(TcpClientBootstrap.java:39)
at reactor.netty.tcp.TcpClientBootstrap.configure(TcpClientBootstrap.java:39)
at reactor.netty.tcp.TcpClient.connect(TcpClient.java:196)
at reactor.netty.http.client.HttpClientFinalizer.connect(HttpClientFinalizer.java:68)
at reactor.netty.http.client.HttpClientFinalizer.responseConnection(HttpClientFinalizer.java:85)
at com.azure.cosmos.implementation.http.ReactorNettyClient.send(ReactorNettyClient.java:123)
at com.azure.cosmos.implementation.RxGatewayStoreModel.performRequest(RxGatewayStoreModel.java:159)
at com.azure.cosmos.implementation.RxGatewayStoreModel.read(RxGatewayStoreModel.java:91)
at com.azure.cosmos.implementation.RxGatewayStoreModel.invokeAsyncInternal(RxGatewayStoreModel.java:351)
at com.azure.cosmos.implementation.RxGatewayStoreModel.lambda$invokeAsync$3(RxGatewayStoreModel.java:366)
at com.azure.cosmos.implementation.BackoffRetryUtility.lambda$executeRetry$0(BackoffRetryUtility.java:34)
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:44)
... 15 more
Exception in thread "main" java.lang.NullPointerException
at com.azure.cosmos.BridgeInternal.isEnableMultipleWriteLocations(BridgeInternal.java:163)
at com.azure.cosmos.implementation.RxDocumentClientImpl.initializeGatewayConfigurationReader(RxDocumentClientImpl.java:264)
at com.azure.cosmos.implementation.RxDocumentClientImpl.init(RxDocumentClientImpl.java:281)
at com.azure.cosmos.implementation.AsyncDocumentClient$Builder.build(AsyncDocumentClient.java:203)
at com.azure.cosmos.CosmosAsyncClient.<init>(CosmosAsyncClient.java:79)
at com.azure.cosmos.CosmosClientBuilder.buildAsyncClient(CosmosClientBuilder.java:649)
at com.azure.cosmos.CosmosClient.<init>(CosmosClient.java:30)
at com.azure.cosmos.CosmosClientBuilder.buildClient(CosmosClientBuilder.java:661)
at com.scalar.db.storage.cosmos.Cosmos.<init>(Cosmos.java:58)
However, I was able to insert data into the instance using the cosmosdb sdk (without scalardb) on both nodejs and java client. Below is my scalardb configuration. I even tried to run the scalardb initialization code on one of my azure vm but didn’t work as well with the same error.
Below is my scalardb configuration
scalar.db.contact_points=<InstanceContactPoints>
scalar.db.contact_port=<DefaultPort>
scalar.db.username=<InstanceUsername>
scalar.db.password=<InstancePassword>
scalar.db.storage=cosmos
I wonder if my configuration is wrong? How do I set it up? Thanks in advance.
答案1
得分: 1
你的代码看起来不错。
我想知道 scalar.db.contact_points
在你的 Scalar DB 配置中是否像 ...:443
这样带有端口。
对于 Cosmos DB,不需要 scalar.db.contract_port
,因为 contact_point 已经包含了端口信息。你可以删除 scalar.db.contact_port
这一行。
英文:
Your code looks good.
I'm wondering whether the scalar.db.contact_points
has the port like ...:443
in your Scalar DB configuration.
The scalar.db.contract_port
isn't required for Cosmos DB because the contact_point has the port. You can remove the scalar.db.contact_port
line.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论