微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

来自 Cosmos DB 的带有异步请求的 GoneException 的原因是什么?

如何解决来自 Cosmos DB 的带有异步请求的 GoneException 的原因是什么?

我将 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\",\"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,{\"eventName\":\"completed\",\"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,#00031] received response to cancelled request: {"request":{},"response":{"type":{},"value":{}}}
[Azure Cosmos,#00031] Operation will NOT be retried. Current attempt {},Exception: 
[Azure Cosmos,WARN,#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 {},#00024] {}
[Azure Cosmos,#00031] Operation will NOT be retried. Exception:
[Azure Cosmos,#00031] {"ClassName":"GoneException","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,\"origin\":\"rntbd://10.10.10.16:10253\",\"ti
meCreated\":\"2021-03-14T16:33:59.072819500Z\",\"timeline\":[{\"eventName\":\"created\",\
"durationInMicroSec\":995},\"startTimeUTC\
":\"2021-03-14T16:33:59.074812500Z\",\"startTimeUTC
\":null,\"durationInMicroSec\":0}]})",x-ms-documentdb-partitionkey=[\"/t
est/doc/large.pdf\"],Content-Type=application/json]"}
[Azure Cosmos,TRACE,#00031]  at com.azure.cosmos.implementation.directconnectivity.rntbd.RntbdRequestRecord.expire(RntbdRequestRecord.java:229)
[Azure Cosmos,#00031]  at io.netty.util.concurrent.DefaultEventExecutor.run(DefaultEventExecutor.java:66)
[Azure Cosmos,#00031]  at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
[Azure Cosmos,#00031]  at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
[Azure Cosmos,#00031]  at java.base/java.lang.Thread.run(Thread.java:834)

Edit2:根本原因似乎是超时。 Cosmsos DB 的认超时时间为 5 秒。大约 5-6 秒后出现错误。超时似乎是从项目创建时间计算出来的。因为项目的创建要快得多,因为项目的传输在某些时候会超过超时。似乎忽略了进度。

解决方法

您试过this sample先生吗?

Family andersenFamilyItem=Families.getAndersenFamilyItem();
        Family wakefieldFamilyItem=Families.getWakefieldFamilyItem();
        Family johnsonFamilyItem=Families.getJohnsonFamilyItem();
        Family smithFamilyItem=Families.getSmithFamilyItem();

        //  Setup family items to create
        Flux<Family> families = Flux.just(andersenFamilyItem,wakefieldFamilyItem,johnsonFamilyItem,smithFamilyItem);

try {

            //  Combine multiple item inserts,associated success println's,and a final aggregate stats println into one Reactive stream.
            double charge = families.flatMap(family -> {
                return container.createItem(family);
            }) //Flux of item request responses
                    .flatMap(itemResponse -> {
                        logger.info("Created item with request charge of {} within duration {}",itemResponse.getRequestCharge(),itemResponse.getDuration());
                        return Mono.just(itemResponse.getRequestCharge());
                    }) //Flux of request charges
                    .reduce(0.0,(charge_n,charge_nplus1) -> charge_n + charge_nplus1
                    ) //Mono of total charge - there will be only one item in this stream
                    .block(); //Preserve the total charge and print aggregate charge/item count stats.

            logger.info("Created items with total request charge of {}\n",charge);

        } catch (Exception err) {
            if (err instanceof CosmosException) {
                //Client-specific errors
                CosmosException cerr = (CosmosException) err;
                logger.error("Read Item failed with CosmosException\n",cerr);
            } else {
                //General errors
                logger.error("Read Item failed with error\n",err);
            }
        }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。