我正在开发一个基于Java的spring-data-couchbase应用程序,它连接到多个存储桶来完成它的工作 . 我们看到在尝试使用堆栈跟踪从桶中检索文档时抛出TimeoutExceptions,如下所示:

10-17-2016 14:28:10 (WebContainer : 9) ERROR [com.cars.ss.cp.resources.ProfileResource] - [RESOURCE] [ERROR] Service com.sun.proxy.$Proxy195.getConsumerProfileSummaryVersion throws org.springframework.dao.QueryTimeoutException.
org.springframework.dao.QueryTimeoutException: java.util.concurrent.TimeoutException; nested exception is java.lang.RuntimeException: java.util.concurrent.TimeoutException
    at org.springframework.data.couchbase.core.CouchbaseExceptionTranslator.translateExceptionIfPossible(CouchbaseExceptionTranslator.java:122)
    at org.springframework.data.couchbase.core.CouchbaseTemplate.execute(CouchbaseTemplate.java:500)
    at org.springframework.data.couchbase.core.CouchbaseTemplate.exists(CouchbaseTemplate.java:464)
    at org.springframework.data.couchbase.repository.support.SimpleCouchbaseRepository.exists(SimpleCouchbaseRepository.java:110)
    at sun.reflect.GeneratedMethodAccessor241.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
    at java.lang.reflect.Method.invoke(Method.java:613)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:503)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:488)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:460)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.data.couchbase.repository.support.ViewPostProcessor$ViewInterceptor.invoke(ViewPostProcessor.java:87)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
    at com.sun.proxy.$Proxy148.exists(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor240.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
    at java.lang.reflect.Method.invoke(Method.java:613)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
    at com.sun.proxy.$Proxy174.exists(Unknown Source)
    at com.cars.ss.cp.service.impl.ProfilePhotoService.findByConsumerId(ProfilePhotoService.java:43)
    at com.cars.ss.cp.dao.impl.ConsumerAccountDAO.findConsumerAccountByPartyId(ConsumerAccountDAO.java:77)
    at sun.reflect.GeneratedMethodAccessor287.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
    at java.lang.reflect.Method.invoke(Method.java:613)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
    at com.sun.proxy.$Proxy186.findConsumerAccountByPartyId(Unknown Source)
    at com.cars.ss.cp.service.impl.ProfileService.getBOConsumerProfileVersion(ProfileService.java:235)
    at com.cars.ss.cp.service.impl.ProfileService.getProfileSummaryByPersonPartyId(ProfileService.java:489)
    at com.cars.ss.cp.service.impl.ProfileService.getProfileSummaryByConsumerId(ProfileService.java:479)
    at sun.reflect.GeneratedMethodAccessor286.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
    at java.lang.reflect.Method.invoke(Method.java:613)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at com.sun.proxy.$Proxy195.getProfileSummaryByConsumerId(Unknown Source)
    at com.cars.ss.cp.resources.ProfileResource.getSummaryReadByConsumerId(ProfileResource.java:362)
    at com.cars.ss.cp.resources.ProfileResource.getConsumerProfileSummaryVersion(ProfileResource.java:320)
    at com.cars.ss.cp.resources.ProfileResource.getConsumerProfile(ProfileResource.java:252)
    at sun.reflect.GeneratedMethodAccessor261.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
    at java.lang.reflect.Method.invoke(Method.java:613)
    at org.apache.wink.server.internal.handlers.InvokeMethodHandler.handleRequest(InvokeMethodHandler.java:63)
    ...
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1225)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:775)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:457)
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1032)
    at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:908)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:459)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:526)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:312)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:283)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture$1.run(AsyncChannelFuture.java:205)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1815)
Caused by: java.lang.RuntimeException: java.util.concurrent.TimeoutException
    at com.couchbase.client.java.util.Blocking.blockForSingle(Blocking.java:75)
    at com.couchbase.client.java.CouchbaseBucket.exists(CouchbaseBucket.java:159)
    at com.couchbase.client.java.CouchbaseBucket.exists(CouchbaseBucket.java:154)
    at org.springframework.data.couchbase.core.CouchbaseTemplate$5.doInBucket(CouchbaseTemplate.java:467)
    at org.springframework.data.couchbase.core.CouchbaseTemplate$5.doInBucket(CouchbaseTemplate.java:464)
    at org.springframework.data.couchbase.core.CouchbaseTemplate.execute(CouchbaseTemplate.java:497)
    ... 120 more
Caused by: java.util.concurrent.TimeoutException
    ... 126 more

我使用多个桶配置了我的Couchbase配置类,如下所示:

@EnableCouchbaseRepositories(basePackages = { "com.cars.ss.cp.nosql.repository" })
@Configuration
public class CouchbaseConfiguration extends AbstractCouchbaseConfiguration {
    private static Logger logger = Logger.getLogger(CouchbaseConfiguration.class);
    private static final long TIMEOUT_IN_SECONDS = 10;

    @Autowired
    @Qualifier("propertyService")
    private PropertyService propertyService;

    @Bean(name = { "defaultBucket" })
    public Bucket defaultBucket() throws Exception {
        return couchbaseCluster().openBucket(getBucketName());
    }

    @Override
    protected List<String> getBootstrapHosts() {
        String rawPropertyValue = this.propertyService.getPropertyValue(COUCHBASE_HOSTS);

        if (StringUtils.isNotBlank(rawPropertyValue)) {
            StringTokenizer st = new StringTokenizer(rawPropertyValue, ",");
            List<String> returnValue = new ArrayList<>(st.countTokens());

            while (st.hasMoreTokens()) {
                returnValue.add(st.nextToken().trim());
            }

            return returnValue;
        }

        logger.error("Unable to process the couchbaseHosts property. Property value: " + rawPropertyValue);
        return Collections.emptyList();
    }

    @Override
    protected String getBucketName() {
        return this.propertyService.getPropertyValue(COUCHBASE_BUCKET);
    }

    @Override
    protected String getBucketPassword() {
        return null;
    }

    @Override
    protected CouchbaseEnvironment getEnvironment() {
        return DefaultCouchbaseEnvironment.builder().connectTimeout(TimeUnit.SECONDS.toMillis(TIMEOUT_IN_SECONDS)).kvTimeout(TimeUnit.SECONDS.toMillis(TIMEOUT_IN_SECONDS)).build();
    }

    @Bean
    public Bucket consumerProfileBucket() throws Exception {
        return couchbaseCluster().openBucket(this.propertyService.getPropertyValue(CONSUMER_PROFILE_BUCKET), this.propertyService.getPropertyValue(CONSUMER_PROFILE_BUCKET_PASSWORD));
    }

    @Bean
    public CouchbaseTemplate consumerProfileTemplate() throws Exception {
        CouchbaseTemplate template = new CouchbaseTemplate(couchbaseClusterInfo(), consumerProfileBucket(), mappingCouchbaseConverter(), translationService());
        template.setDefaultConsistency(getDefaultConsistency());
        return template;
    }

    @Override
    protected void configureRepositoryOperationsMapping(RepositoryOperationsMapping baseMapping) {
        try {
            baseMapping.mapEntity(OwnedVehicle.class, consumerProfileTemplate());
            baseMapping.mapEntity(ProfilePhoto.class, consumerProfileTemplate());
        } catch (Exception e) {
            logger.error("Errors encountered during configuration. Exception: " + e);
        }
    }
}

我原来没有覆盖“getEnvironment”方法 . 基于我在网上看到的一些建议,我重写了该方法,并将连接超时和键值超时增加到10秒,看看这是否有帮助,但事实并非如此 . 当我将超时从默认值增加到10秒时,文档检索的超时时间恰好为10秒 . 对于尝试使用文档密钥检索的文档,发生TimeoutException .

该应用程序具有以下规格:

  • Java版本:1.7
  • spring-data-couchbase版本:2.1.1.RELEASE
  • java-client版本:2.2.5
  • IBM WebSphere版本:8.5

在我配置东西的方式中是否有一些明显缺少的东西?有什么其他的想法,我可以看看来修复这个问题?

2016年10月24日 - 从javacore添加了一个线程分析图像:thread analysis image from javacore