我将 Cosmos Java 驱动程序 4.12.0 与当前的 Cosmos DB 模拟器结合使用。我需要一步编写多个文档。如果我使用同步 API,我的代码就可以工作。为了提高速度,我尝试了异步 API,但在短时间内它就失败并出现 GoneException。 GoneException 的原因可能是什么?
{
"ClassName":"GoneException",
"userAgent":"azsdk-java-cosmos/4.12.0 Windows10/10.0 JRE/11.0.7",
"statusCode":410,
"resourceAddress":"rntbd://10.10.10.10:10253/apps/DocDbApp/services/DocDbServer15/partitions/a4cb495b-38c8-11e6-8106-8cdcd42c33be/replicas/1p/",
"innerErrorMessage":"AsyncRntbdRequestRecord({\"args\":{\"transportRequestId\":102,\"activityId\":\"13ddd623-84e3-11eb-a42d-d5052d2cf638\",
\"origin\":\"rntbd://10.10.10.10:10253\",
\"replicaPath\":\"/apps/DocDbApp/services/DocDbServer15/partitions/a4cb495b-38c8-11e6-8106-8cdcd42c33be/replicas/1p\",
\"timeCreated\":\"2021-03-14T16:33:59.072819500Z\",
\"lifetime\":\"PT5.0601317S\"},
\"requestLength\":333849,
\"responseLength\":-1,
\"status\":{\"done\":false,\"cancelled\":false,
\"completedExceptionally\":false},
\"timeline\":[
{\"eventName\":\"created\",\"startTimeUTC\":\"2021-03-14T16:33:59.072819500Z\",\"durationInMicroSec\":995},
{\"eventName\":\"queued\",\"startTimeUTC\":\"2021-03-14T16:33:59.073815300Z\",\"durationInMicroSec\":0},
{\"eventName\":\"channelAcquisitionStarted\",\"startTimeUTC\":\"2021-03-14T16:33:59.073815300Z\",\"durationInMicroSec\":997},
{\"eventName\":\"pipelined\",\"startTimeUTC\":\"2021-03-14T16:33:59.074812500Z\",\"durationInMicroSec\":1255947},
{\"eventName\":\"transitTime\",\"startTimeUTC\":\"2021-03-14T16:34:00.330760Z\",\"durationInMicroSec\":3802608},
{\"eventName\":\"received\",\"startTimeUTC\":null,\"durationInMicroSec\":0},
{\"eventName\":\"completed\",\"startTimeUTC\":null,\"durationInMicroSec\":0}
]})",
"causeInfo":null,
"responseHeaders":"{}",
"requestHeaders":"[Accept=application/json, x-ms-date=Sun, 14 Mar 2021 16:33:59 GMT, x-ms-documentdb-collection-rid=woU8APC+j8k=, x-ms-client-retry-attempt-count=0, Prefer=return=minimal, x-ms-documentdb-partitionkey=[\"/test/doc/foobar\"], x-ms-remaining-time-in-ms-on-client=60000, Content-Type=application/json]"
}
代码如下:
CosmosAsyncContainer fs = ...;
Mono<?> mono = Mono.empty();
for( int i = 0; i < count; i++ ) {
doc = ...;
mono = mono.and( fs.createItem( doc ) );
}
mono.block();
此代码的最后一行抛出异常。这段异步代码有什么问题?还有其他更适合多个文档的概念吗?
所有文档都使用相同的分区键,因为文档稍后也会一起查询。
编辑:启用驱动程序的调试日志后,如果发现这个有趣的片段在很长的输出中被剪掉:
[Azure Cosmos,DEBUG ,3/14 17:34:04,#00031] SessionTokenMismatchRetryPolicy not retrying because StatusCode or SubStatusCode not found.
[Azure Cosmos,DEBUG ,3/14 17:34:04,#00031] received response to cancelled request: {"request":{},"response":{"type":{},"value":{}}}
[Azure Cosmos,DEBUG ,3/14 17:34:04,#00031] Operation will NOT be retried. Current attempt {}, Exception:
[Azure Cosmos,WARN ,3/14 17:34:04,#00031] Operation will NOT be retried. Write operations which failed due to transient transport errors can not be retried safely when sending the request to the service because they arent idempotent. Current attempt {}, Exception:
[Azure Cosmos,DEBUG ,3/14 17:34:04,#00024] {}
[Azure Cosmos,DEBUG ,3/14 17:34:04,#00024] {}
[Azure Cosmos,DEBUG ,3/14 17:34:04,#00024] {}
[Azure Cosmos,DEBUG ,3/14 17:34:04,#00024] {}
[Azure Cosmos,DEBUG ,3/14 17:34:04,#00024] {}
[Azure Cosmos,DEBUG ,3/14 17:34:04,#00024] {}
[Azure Cosmos,DEBUG ,3/14 17:34:04,#00024] {}
[Azure Cosmos,DEBUG ,3/14 17:34:04,#00024] {}
[Azure Cosmos,DEBUG ,3/14 17:34:04,#00024] {}
[Azure Cosmos,DEBUG ,3/14 17:34:04,#00031] Operation will NOT be retried. Exception:
[Azure Cosmos,DEBUG ,3/14 17:34:04,#00031] {"ClassName":"GoneException","userAgent":"azsdk-java-cosmos/4.12.0 Windows10/10.0 JRE/11.0.7","statusCode":410,"resourceAddress":"rntbd://10.10.10.16:10253/apps/DocDbApp/services/DocDbServer15/partitions/a4cb495b-38c8-11e6-8106-8cdcd42c33be/replicas/1p/","i
nnerErrorMessage":"AsyncRntbdRequestRecord({\"args\":{\"transportRequestId\":102,\"activityId\":\"13ddd623-84e3-11eb-a42d-d5052d2cf638\",\"origin\":\"rntbd://10.10.10.16:10253\",\"replicaPath\":\"/apps/DocDbApp/services/DocDbServer15/partitions/a4cb495b-38c8-11e6-8106-8cdcd42c33be/replicas/1p\",\"ti
meCreated\":\"2021-03-14T16:33:59.072819500Z\",\"lifetime\":\"PT5.0601317S\"},\"requestLength\":333849,\"responseLength\":-1,\"status\":{\"done\":false,\"cancelled\":false,\"completedExceptionally\":false},\"timeline\":[{\"eventName\":\"created\",\"startTimeUTC\":\"2021-03-14T16:33:59.072819500Z\",\
"durationInMicroSec\":995},{\"eventName\":\"queued\",\"startTimeUTC\":\"2021-03-14T16:33:59.073815300Z\",\"durationInMicroSec\":0},{\"eventName\":\"channelAcquisitionStarted\",\"startTimeUTC\":\"2021-03-14T16:33:59.073815300Z\",\"durationInMicroSec\":997},{\"eventName\":\"pipelined\",\"startTimeUTC\
":\"2021-03-14T16:33:59.074812500Z\",\"durationInMicroSec\":1255947},{\"eventName\":\"transitTime\",\"startTimeUTC\":\"2021-03-14T16:34:00.330760Z\",\"durationInMicroSec\":3802608},{\"eventName\":\"received\",\"startTimeUTC\":null,\"durationInMicroSec\":0},{\"eventName\":\"completed\",\"startTimeUTC
\":null,\"durationInMicroSec\":0}]})","causeInfo":null,"responseHeaders":"{}","requestHeaders":"[Accept=application/json, x-ms-date=Sun, 14 Mar 2021 16:33:59 GMT, x-ms-documentdb-collection-rid=woU8APC+j8k=, x-ms-client-retry-attempt-count=0, Prefer=return=minimal, x-ms-documentdb-partitionkey=[\"/t
est/doc/large.pdf\"], x-ms-remaining-time-in-ms-on-client=60000, Content-Type=application/json]"}
[Azure Cosmos,TRACE ,3/14 17:34:04,#00031] at com.azure.cosmos.implementation.directconnectivity.rntbd.RntbdRequestRecord.expire(RntbdRequestRecord.java:229)
[Azure Cosmos,TRACE ,3/14 17:34:04,#00031] at io.netty.util.concurrent.DefaultEventExecutor.run(DefaultEventExecutor.java:66)
[Azure Cosmos,TRACE ,3/14 17:34:04,#00031] at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
[Azure Cosmos,TRACE ,3/14 17:34:04,#00031] at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
[Azure Cosmos,TRACE ,3/14 17:34:04,#00031] at java.base/java.lang.Thread.run(Thread.java:834)
Edit2:根本原因似乎是超时。 Cosmsos DB 的默认超时时间为 5 秒。大约 5-6 秒后出现错误。超时似乎是根据项目创建时间计算的。因为项目的创建速度要快得多,因为项目的传输在某些时候会超过超时时间。看来进度被忽略了。
尝试删除容器并重试