尝试在Couchbase中“查找”文档时,即使使用分页的

时间:2018-12-26 08:19:46

标签: java spring-data couchbase

我们正在尝试使用Spring-Data的宠物桶中的Cat切片。

对于此类查询,我们有特殊的索引:

Couchbase

代码如下:

CREATE INDEX cats_by_ownerId_and_name_idx ON `pets`(ownerId ASC, name) WHERE _class = 'com.example.Cat'

Slice<Cat> slice; Pageable pageable = PageRequest.of(0, 1000, Sort.by("id").ascending()); do { log.debug("Getting slice No. {} of cats from DB", sliceCounter++); slice = catsRepository.findAllByOwnerIdAndName("123", "Oscar", pageable); ... } while (slice.hasNext()); 的总数为数十万时,上述代码可以正常工作。 (例如,对于50K猫可以正常使用。)

但是,如果我们有10万个Cat,则在循环的第一次迭代中就可以得到TimeoutException:

Cat

我们尝试对索引的构建方式进行更改(as was mentioned here,但没有任何效果。

修改

将Spring-Data方法更改为以下方法之一也无济于事:

Getting slice No. 0 of cats from DB
c.l.i.s.c.AsyncConfiguration   java.util.concurrent.TimeoutException: {"b":"pets","r":"127.0.0.1:8093","s":"n1ql","c":"1E8CB73B19B0255D/FFFFFFFFF24214C9","t":7500000,"i":"55f1afdb-5757-4b4b-8321-fc9a7003e3a8","l":"127.0.0.1:56365"}; nested exception is java.lang.RuntimeException: java.util.concurrent.TimeoutException: {"b":"pets","r":"127.0.0.1:8093","s":"n1ql","c":"1E8CB73B19B0255D/FFFFFFFFF24214C9","t":7500000,"i":"55f1afdb-5757-4b4b-8321-fc9a7003e3a8","l":"127.0.0.1:56365"}

org.springframework.dao.QueryTimeoutException: java.util.concurrent.TimeoutException: {"b":"pets","r":"127.0.0.1:8093","s":"n1ql","c":"1E8CB73B19B0255D/FFFFFFFFF24214C9","t":7500000,"i":"55f1afdb-5757-4b4b-8321-fc9a7003e3a8","l":"127.0.0.1:56365"}; nested exception is java.lang.RuntimeException: java.util.concurrent.TimeoutException: {"b":"pets","r":"127.0.0.1:8093","s":"n1ql","c":"1E8CB73B19B0255D/FFFFFFFFF24214C9","t":7500000,"i":"55f1afdb-5757-4b4b-8321-fc9a7003e3a8","l":"127.0.0.1:56365"}
at org.springframework.data.couchbase.core.CouchbaseExceptionTranslator.translateExceptionIfPossible(CouchbaseExceptionTranslator.java:122) ~[spring-data-couchbase-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.data.couchbase.core.CouchbaseTemplate.execute(CouchbaseTemplate.java:544) ~[spring-data-couchbase-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.data.couchbase.core.CouchbaseTemplate.queryN1QL(CouchbaseTemplate.java:498) ~[spring-data-couchbase-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.data.couchbase.core.CouchbaseTemplate.findByN1QL(CouchbaseTemplate.java:433) ~[spring-data-couchbase-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.data.couchbase.repository.query.AbstractN1qlBasedQuery.executeSliced(AbstractN1qlBasedQuery.java:189) ~[spring-data-couchbase-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.data.couchbase.repository.query.AbstractN1qlBasedQuery.executeDependingOnType(AbstractN1qlBasedQuery.java:129) ~[spring-data-couchbase-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.data.couchbase.repository.query.AbstractN1qlBasedQuery.execute(AbstractN1qlBasedQuery.java:106) ~[spring-data-couchbase-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:590) ~[spring-data-commons-2.0.9.RELEASE.jar:2.0.9.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:578) ~[spring-data-commons-2.0.9.RELEASE.jar:2.0.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59) ~[spring-data-commons-2.0.9.RELEASE.jar:2.0.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.data.couchbase.repository.support.ViewPostProcessor$ViewInterceptor.invoke(ViewPostProcessor.java:87) ~[spring-data-couchbase-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61) ~[spring-data-commons-2.0.9.RELEASE.jar:2.0.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at com.sun.proxy.$Proxy138.findAllByProjectIdAndBuiltWithIndex(Unknown Source) ~[na:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343) ~[spring-aop-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:206) ~[spring-aop-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at com.sun.proxy.$Proxy139.findAllByOwnerIdAndName(Unknown Source) ~[na:na]
Caused by: java.lang.RuntimeException: java.util.concurrent.TimeoutException: {"b":"pets","r":"127.0.0.1:8093","s":"n1ql","c":"1E8CB73B19B0255D/FFFFFFFFF24214C9","t":7500000,"i":"55f1afdb-5757-4b4b-8321-fc9a7003e3a8","l":"127.0.0.1:56365"}
at rx.exceptions.Exceptions.propagate(Exceptions.java:57) ~[rxjava-1.3.8.jar:1.3.8]
at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:463) ~[rxjava-1.3.8.jar:1.3.8]
at rx.observables.BlockingObservable.single(BlockingObservable.java:340) ~[rxjava-1.3.8.jar:1.3.8]
at com.couchbase.client.java.CouchbaseBucket.query(CouchbaseBucket.java:634) ~[java-client-2.7.1.jar:na]
at com.couchbase.client.java.CouchbaseBucket.query(CouchbaseBucket.java:556) ~[java-client-2.7.1.jar:na]
at org.springframework.data.couchbase.core.CouchbaseTemplate$8.doInBucket(CouchbaseTemplate.java:501) ~[spring-data-couchbase-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.data.couchbase.core.CouchbaseTemplate$8.doInBucket(CouchbaseTemplate.java:498) ~[spring-data-couchbase-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.data.couchbase.core.CouchbaseTemplate.execute(CouchbaseTemplate.java:541) ~[spring-data-couchbase-3.0.9.RELEASE.jar:3.0.9.RELEASE]
... 38 common frames omitted
Caused by: java.util.concurrent.TimeoutException: {"b":"pets","r":"127.0.0.1:8093","s":"n1ql","c":"1E8CB73B19B0255D/FFFFFFFFF24214C9","t":7500000,"i":"55f1afdb-5757-4b4b-8321-fc9a7003e3a8","l":"127.0.0.1:56365"}
at com.couchbase.client.java.bucket.api.Utils$1.call(Utils.java:131) ~[java-client-2.7.1.jar:na]
at com.couchbase.client.java.bucket.api.Utils$1.call(Utils.java:127) ~[java-client-2.7.1.jar:na]
at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$4.onError(OperatorOnErrorResumeNextViaFunction.java:140) ~[rxjava-1.3.8.jar:1.3.8]
at rx.internal.operators.OnSubscribeTimeoutTimedWithFallback$TimeoutMainSubscriber.onTimeout(OnSubscribeTimeoutTimedWithFallback.java:166) ~[rxjava-1.3.8.jar:1.3.8]
at rx.internal.operators.OnSubscribeTimeoutTimedWithFallback$TimeoutMainSubscriber$TimeoutTask.call(OnSubscribeTimeoutTimedWithFallback.java:191) ~[rxjava-1.3.8.jar:1.3.8]
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) ~[rxjava-1.3.8.jar:1.3.8]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[na:1.8.0_161]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_161]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) ~[na:1.8.0_161]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) ~[na:1.8.0_161]
... 3 common frames omitted

1 个答案:

答案 0 :(得分:0)

当我们从创建Sort.by("id")对象中删除Pageable时,问题就解决了。

从那开始:

Pageable pageable = PageRequest.of(0, 1000, Sort.by("id"));

对此:

Pageable pageable = PageRequest.of(0, 1000);