If I call the the method: CosmosDatabase.createContainerIfNotExists(x)
I receive the error message: Resource with specified id, name, or unique index already exists.
How I have to interpret this error?
The full exception stacktrace:
{"ClassName":"CosmosException","userAgent":"azsdk-java-cosmos/4.13.0 Linux/4.15.0-124-generic JRE/11.0.11","statusCode":409,"resourceAddress":"https://10.10.10.16:8081/dbs/jenkins21/colls","error":"{"code":"Conflict","message":"Message: {\"Errors\":[\"Resource with specified id, name, or unique index already exists.\"]}\r\nActivityId: f42970e5-c07b-45f9-896e-62a0aa00122a, Request URI: /apps/DocDbApp/services/DocDbMaster0/partitions/780e44f4-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, RequestStats: \r\nRequestStartTime: 2021-07-20T02:05:58.8219453Z, RequestEndTime: 2021-07-20T02:05:58.8239187Z, Number of regions attempted:1\r\nResponseTime: 2021-07-20T02:05:58.8239187Z, StoreResult: StorePhysicalAddress: rntbd://10.10.10.16:10251/apps/DocDbApp/services/DocDbMaster0/partitions/780e44f4-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, LSN: 32164, GlobalCommittedLsn: -1, PartitionKeyRangeId: , IsValid: True, StatusCode: 409, SubStatusCode: 0, RequestCharge: 0, ItemLSN: -1, SessionToken: -1#32164, UsingLocalLSN: False, TransportException: null, ResourceType: Collection, OperationType: BatchApply\r\n, SDK: Microsoft.Azure.Documents.Common/2.11.0, StatusCode: Conflict","additionalErrorInfo":null}","innerErrorMessage":"Message: {"Errors":["Resource with specified id, name, or unique index already exists."]}rnActivityId: f42970e5-c07b-45f9-896e-62a0aa00122a, Request URI: /apps/DocDbApp/services/DocDbMaster0/partitions/780e44f4-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, RequestStats: rnRequestStartTime: 2021-07-20T02:05:58.8219453Z, RequestEndTime: 2021-07-20T02:05:58.8239187Z, Number of regions attempted:1rnResponseTime: 2021-07-20T02:05:58.8239187Z, StoreResult: StorePhysicalAddress: rntbd://10.10.10.16:10251/apps/DocDbApp/services/DocDbMaster0/partitions/780e44f4-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, LSN: 32164, GlobalCommittedLsn: -1, PartitionKeyRangeId: , IsValid: True, StatusCode: 409, SubStatusCode: 0, RequestCharge: 0, ItemLSN: -1, SessionToken: -1#32164, UsingLocalLSN: False, TransportException: null, ResourceType: Collection, OperationType: BatchApplyrn, SDK: Microsoft.Azure.Documents.Common/2.11.0, StatusCode: Conflict","causeInfo":null,"responseHeaders":"{Transfer-Encoding=chunked, x-ms-last-state-change-utc=Wed, 14 Jul 2021 20:52:01.947 GMT, x-ms-current-replica-set-size=1, Server=Microsoft-HTTPAPI/2.0, x-ms-request-duration-ms=1.132, x-ms-session-token=0:-1#32164, Access-Control-Allow-Origin=, lsn=32164, x-ms-schemaversion=1.11, x-ms-transport-request-id=41722, x-ms-number-of-read-regions=0, x-ms-current-write-quorum=1, x-ms-cosmos-quorum-acked-llsn=32164, x-ms-quorum-acked-lsn=32164, Date=Tue, 20 Jul 2021 02:05:58 GMT, x-ms-activity-id=f42970e5-c07b-45f9-896e-62a0aa00122a, x-ms-xp-role=0, x-ms-global-Committed-lsn=-1, Access-Control-Allow-Credentials=true, x-ms-cosmos-llsn=32164, x-ms-gatewayversion=version=2.11.0, x-ms-serviceversion=version=2.11.0.0, Content-Type=application/json}","requestHeaders":"[Accept=application/json, x-ms-date=Tue, 20 Jul 2021 02:05:58 GMT, Content-Type=application/json]","cosmosDiagnostics":{"userAgent":"azsdk-java-cosmos/4.13.0 Linux/4.15.0-124-generic JRE/11.0.11","requestLatencyInMs":368,"requestStartTimeUTC":"2021-07-20T02:05:58.681410Z","requestEndTimeUTC":"2021-07-20T02:05:59.050232Z","connectionMode":"GATEWAY","responseStatisticsList":[],"supplementalResponseStatisticsList":[],"addressResolutionStatistics":{},"regionsContacted":["https://10.10.10.16:8081/"],"retryContext":{"retryCount":0,"statusAndSubStatusCodes":null,"retryLatency":0},"metadataDiagnosticsContext":{"metadataDiagnosticList":null},"serializationDiagnosticsContext":{"serializationDiagnosticsList":[{"serializationType":"CONTAINER_SERIALIZATION","startTimeUTC":"2021-07-20T02:05:58.681516Z","endTimeUTC":"2021-07-20T02:05:58.681552Z","durationInMicroSec":36}]},"gatewayStatistics":{"sessionToken":null,"operationType":"Create","statusCode":409,"subStatusCode":0,"requestCharge":null,"requestTimeline":[{"eventName":"connectionCreated","startTimeUTC":"2021-07-20T02:05:58.681681Z","durationInMicroSec":117},{"eventName":"connectionConfigured","startTimeUTC":"2021-07-20T02:05:58.681798Z","durationInMicroSec":22},{"eventName":"requestSent","startTimeUTC":"2021-07-20T02:05:58.681820Z","durationInMicroSec":170},{"eventName":"transitTime","startTimeUTC":"2021-07-20T02:05:58.681990Z","durationInMicroSec":367906},{"eventName":"received","startTimeUTC":"2021-07-20T02:05:59.049896Z","durationInMicroSec":150}]},"systemInformation":{"usedMemory":"71893 KB","availableMemory":"452395 KB","systemCpuLoad":"(2021-07-20T02:05:31.477916Z 48.1%), (2021-07-20T02:05:36.477915Z 34.6%), (2021-07-20T02:05:41.477923Z 37.8%), (2021-07-20T02:05:46.477917Z 42.1%), (2021-07-20T02:05:51.477942Z 61.4%), (2021-07-20T02:05:56.477908Z 57.0%)"},"clientCfgs":{"id":0,"numberOfClients":1,"connCfg":{"rntbd":"(cto:PT5S, rto:PT5S, icto:PT0S, ieto:PT1H, mcpe:130, mrpc:30, cer:false)","gw":"(cps:1000, rto:PT5S, icto:null, p:false)","other":"(ed: true, cs: false)"},"consistencyCfg":"(consistency: null, mm: true, prgns: [])"}}} at com.azure.cosmos.BridgeInternal.createCosmosException(BridgeInternal.java:463) at com.azure.cosmos.implementation.RxGatewayStoreModel.validateOrThrow(RxGatewayStoreModel.java:365) at com.azure.cosmos.implementation.RxGatewayStoreModel.lambda$toDocumentServiceResponse$0(RxGatewayStoreModel.java:294) at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:106) at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onNext(FluxSwitchIfEmpty.java:73) at reactor.core.publisher.FluxPeek$PeekSubscriber.onNext(FluxPeek.java:199) at reactor.core.publisher.FluxHandle$HandleSubscriber.onNext(FluxHandle.java:118) at reactor.core.publisher.FluxMap$MapConditionalSubscriber.onNext(FluxMap.java:220) at reactor.core.publisher.FluxDoFinally$DoFinallySubscriber.onNext(FluxDoFinally.java:130) at reactor.core.publisher.FluxHandleFuseable$HandleFuseableSubscriber.onNext(FluxHandleFuseable.java:184) at reactor.core.publisher.FluxContextWrite$ContextWriteSubscriber.onNext(FluxContextWrite.java:107) at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1815) at reactor.core.publisher.MonoCollectList$MonoCollectListSubscriber.onComplete(MonoCollectList.java:128) at reactor.core.publisher.FluxPeek$PeekSubscriber.onComplete(FluxPeek.java:259) at reactor.core.publisher.FluxMap$MapSubscriber.onComplete(FluxMap.java:142) at reactor.netty.channel.FluxReceive.onInboundComplete(FluxReceive.java:389) at reactor.netty.channel.ChannelOperations.onInboundComplete(ChannelOperations.java:396) at reactor.netty.channel.ChannelOperations.terminate(ChannelOperations.java:452) at reactor.netty.http.client.HttpClientOperations.onInboundNext(HttpClientOperations.java:684) at reactor.netty.channel.ChannelOperationsHandler.channelRead(ChannelOperationsHandler.java:94) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296) at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1533) at io.netty.handler.ssl.SslHandler.decodeNonJdkCompatible(SslHandler.java:1294) at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1331) at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:508) at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:447) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:795) at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe$1.run(AbstractEpollChannel.java:388) at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164) at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472) at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:384) at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
Advertisement
Answer
I work around the problem with a try catch block and repeat the operation if this error occur. Debug code show that the container exists after the exception occur.
Our application is multi threading with lazy initialization. Can be that 2 threads try to create the needed container at the same time. The error is difficult to reproduce.
Its sounds this method is not atomic on the database like the method name suggested and also does not handle it in the driver. The very bad API documentation does not says any over thread behavior. With such API documentation it is not possible to write stable software. It required a try and error.