我正在尝试获取云扳手中实例的数据库列表
Spanner spannerClient=SpannerOptions.newBuilder().build().getService();
InstanceAdminClient instanceAdminClient = spannerClient.getInstanceAdminClient();
Page<Database> databasePage = instanceAdminClient.getInstance(instanceID).listDatabases();
for (Database database : databasePage.getValues()) {
String databaseName = database.getId().getDatabase();
log.info("Database-->"+databaseName);
}
该代码在我的本地环境中运行良好,但是当我尝试在纱线容器中运行相同的代码时会被阻塞。我从threaddump中获得了以下日志
Thread 10275: (state = BLOCKED)
- sun.misc.Unsafe.park(boolean, long) @bci=0 (Compiled frame; information may be imprecise)
- java.util.concurrent.locks.LockSupport.parkNanos(java.lang.Object, long) @bci=20, line=215 (Compiled frame)
- java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedNanos(int, long) @bci=139, line=1037 (Interpreted frame)
- java.util.concurrent.locks.AbstractQueuedSynchronizer.tryAcquireSharedNanos(int, long) @bci=25, line=1328 (Interpreted frame)
- java.util.concurrent.CountDownLatch.await(long, java.util.concurrent.TimeUnit) @bci=10, line=277 (Interpreted frame)
- com.google.cloud.spanner.SpannerImpl.backoffSleep(io.grpc.Context, long) @bci=67, line=200 (Interpreted frame)
- com.google.cloud.spanner.SpannerImpl.backoffSleep(io.grpc.Context, com.shaded.scanner.google.api.client.util.BackOff) @bci=5, line=170 (Interpreted frame)
- com.google.cloud.spanner.SpannerImpl.runWithRetries(java.util.concurrent.Callable) @bci=105, line=238 (Interpreted frame)
- com.google.cloud.spanner.SpannerImpl$InstanceAdminClientImpl.getInstance(java.lang.String) @bci=25, line=660 (Interpreted frame)
- com.test.spannerscanner.utils.GoogleSpannerManager.execute() @bci=289, line=93 (Interpreted frame)
我无法弄清为什么该连接在纱线容器中被阻塞,但在本地却能正常工作。经过进一步的调试,我发现由于SpannerImpl类的runWithRetries方法中抛出SpannerException而导致代码被阻塞。该代码捕获异常并在退避一段时间后重新输入代码,从而被阻塞。 SpannerException具有以下消息:
java.util.concurrent.ExecutionException: io.grpc.StatusRuntimeException: UNAVAILABLE: io exception
任何关于为什么在纱线容器中引发此异常的帮助或建议,将受到极大的赞赏。我正在使用Cloud Spaner 0.52-beta版。