IgniteCache:testdb - 连接不可用

时间:2017-11-28 12:03:18

标签: spring ignite

我使用以下配置创建了一个Ignite Cache:

@Bean(name = Identifiers.STANDARD_IGNITE_ITEM)
@Qualifier(Identifiers.STANDARD_IGNITE_ITEM)
public Ignite standardItemsIgniteConfiguration() {
    return Ignition.getOrStart(this.getIgniteConfiguration());
}

private IgniteConfiguration getIgniteConfiguration() {
    final CacheConfiguration<String, StandardItem> igniteCacheConfiguration = new CacheConfiguration<>(Identifiers.STANDARD_IGNITE_ITEM_CACHE);

    igniteCacheConfiguration.setName(Identifiers.STANDARD_IGNITE_ITEM_CACHE);
    igniteCacheConfiguration.setIndexedTypes(String.class, StandardItem.class);
    igniteCacheConfiguration.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
    igniteCacheConfiguration.setCopyOnRead(false);
    igniteCacheConfiguration.setCacheMode(CacheMode.PARTITIONED);
    igniteCacheConfiguration.setOnheapCacheEnabled(true);

    final IgniteConfiguration igniteConfiguration = new IgniteConfiguration();
    igniteConfiguration.setIgniteInstanceName(Identifiers.STANDARD_IGNITE_ITEM);
    igniteConfiguration.setCacheConfiguration(igniteCacheConfiguration);

    return igniteConfiguration;
}

我的Spring Service创建了点火缓存,使用IgniteDataStreamer预加载数据并提供查询以获取所有项目:

@Service
public class DataService {
    private static final Logger logger = LoggerFactory.getLogger(DataService.class.getName());

    private final IgniteCache<String, StandardItem> standardItemIgniteCache;

    public DataService(@Autowired @Qualifier(Identifiers.STANDARD_IGNITE_ITEM) Ignite standardItemIgnite) {
        logger.info("Call data service constructor");

        this.standardItemIgniteCache = standardItemIgnite.cache(Identifiers.STANDARD_IGNITE_ITEM_CACHE);
        this.standardItemIgniteCache.clear();

        try (IgniteDataStreamer<String, StandardItem> streamer = standardItemIgnite.dataStreamer(Identifiers.STANDARD_IGNITE_ITEM_CACHE)) {
            this.loadStandardItemCache(streamer);
        }
    }

    private void loadStandardItemCache(IgniteDataStreamer<String, StandardItem> streamer) {
        logger.info("Load standard items into ignite cache");

        final AtomicInteger counter = new AtomicInteger();

        Flux<StandardItem> items = new StandardItemDAO().getAllItems();

        items.doOnComplete(() -> logger.info("Loaded " + counter + " standard items into ignite cache")).subscribe(item -> {
            if (item != null) {
                counter.incrementAndGet();

                streamer.addData(item.getItemId(), item);
            }
        });
    }

    @Transactional(readOnly = true)
    public Flux<StandardItem> getAllStandardItems(Map<String, String> params) {
        logger.info("get all standard items");

        String search = SearchHelper.toSearchString(params);

        logger.info("get all standard items for search params: " + search);

        return Flux.create(sink -> new Thread(() -> {
            logger.info("lookup standard items cache");

            Iterator<Cache.Entry<String, StandardItem>> iterator = standardItemIgniteCache.iterator();

            logger.info("publish standard items from cache");

            while (iterator.hasNext()) {
                sink.next(iterator.next().getValue());
            }

            logger.info("publishing standard items from cache done");

            sink.complete();
        }).start());
    }
}

这适用于大约20分钟。在这20分钟内,每个请求和每个查询都有效。但是在大约20分钟后,每个查询都会出现以下错误:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:986) ~[spring-webmvc-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:870) ~[spring-webmvc-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) ~[javax.servlet-api-3.1.0.jar!/:3.1.0]
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855) ~[spring-webmvc-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[javax.servlet-api-3.1.0.jar!/:3.1.0]
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:841) ~[jetty-servlet-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1650) ~[jetty-servlet-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:206) ~[websocket-server-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637) ~[jetty-servlet-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:119) ~[spring-boot-actuator-2.0.0.M6.jar!/:2.0.0.M6]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637) ~[jetty-servlet-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637) ~[jetty-servlet-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:108) ~[spring-web-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637) ~[jetty-servlet-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) ~[spring-web-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637) ~[jetty-servlet-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) ~[spring-web-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637) ~[jetty-servlet-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterWithMetrics(WebMvcMetricsFilter.java:95) ~[spring-boot-actuator-2.0.0.M6.jar!/:2.0.0.M6]
        at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:72) ~[spring-boot-actuator-2.0.0.M6.jar!/:2.0.0.M6]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637) ~[jetty-servlet-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:533) ~[jetty-servlet-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) ~[jetty-server-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548) ~[jetty-security-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) ~[jetty-server-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:190) ~[jetty-server-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595) ~[jetty-server-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188) ~[jetty-server-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1253) ~[jetty-server-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168) ~[jetty-server-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473) ~[jetty-servlet-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564) ~[jetty-server-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166) ~[jetty-server-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1155) ~[jetty-server-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) ~[jetty-server-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) ~[jetty-server-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.server.Server.handle(Server.java:561) ~[jetty-server-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:334) ~[jetty-server-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251) [jetty-server-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279) [jetty-io-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:104) [jetty-io-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124) [jetty-io-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:247) [jetty-util-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:140) [jetty-util-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131) [jetty-util-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:243) [jetty-util-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:679) [jetty-util-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:597) [jetty-util-9.4.7.v20170914.jar!/:9.4.7.v20170914]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111]
Caused by: org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
        at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:450) ~[spring-orm-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:374) ~[spring-tx-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:474) ~[spring-tx-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:289) ~[spring-tx-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) ~[spring-tx-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689) ~[spring-aop-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at io.sc.pps.provider.ProviderService$$EnhancerBySpringCGLIB$$594ecf1c.getAllStandardItems(<generated>) ~[classes!/:na]
        at io.sc.pps.provider.ProviderController.getAllStandardItems(ProviderController.java:39) ~[classes!/:na]
        at sun.reflect.GeneratedMethodAccessor94.invoke(Unknown Source) ~[na:na]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) ~[spring-web-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) ~[spring-web-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) ~[spring-webmvc-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:871) ~[spring-webmvc-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:777) ~[spring-webmvc-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) ~[spring-webmvc-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) ~[spring-webmvc-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978) ~[spring-webmvc-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        ... 55 common frames omitted
Caused by: org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
        at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:48) ~[hibernate-core-5.2.8.Final.jar!/:5.2.8.Final]
        at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42) ~[hibernate-core-5.2.8.Final.jar!/:5.2.8.Final]
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111) ~[hibernate-core-5.2.8.Final.jar!/:5.2.8.Final]
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97) ~[hibernate-core-5.2.8.Final.jar!/:5.2.8.Final]
        at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:102) ~[hibernate-core-5.2.8.Final.jar!/:5.2.8.Final]
        at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:129) ~[hibernate-core-5.2.8.Final.jar!/:5.2.8.Final]
        at org.hibernate.internal.SessionImpl.connection(SessionImpl.java:514) ~[hibernate-core-5.2.8.Final.jar!/:5.2.8.Final]
        at sun.reflect.GeneratedMethodAccessor79.invoke(Unknown Source) ~[na:na]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
        at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:223) ~[spring-core-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:207) ~[spring-core-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle.doGetConnection(HibernateJpaDialect.java:391) ~[spring-orm-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.springframework.orm.jpa.vendor.HibernateJpaDialect.beginTransaction(HibernateJpaDialect.java:154) ~[spring-orm-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:400) ~[spring-orm-5.0.1.RELEASE.jar!/:5.0.1.RELEASE]
        ... 75 common frames omitted
Caused by: java.sql.SQLTransientConnectionException: testdb - Connection is not available, request timed out after 30000ms.
        at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:603) ~[HikariCP-2.7.2.jar!/:na]
        at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:193) ~[HikariCP-2.7.2.jar!/:na]
        at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:149) ~[HikariCP-2.7.2.jar!/:na]
        at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-2.7.2.jar!/:na]
        at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[hibernate-core-5.2.8.Final.jar!/:5.2.8.Final]
        at org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection(NonContextualJdbcConnectionAccess.java:35) ~[hibernate-core-5.2.8.Final.jar!/:5.2.8.Final]
        at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:99) ~[hibernate-core-5.2.8.Final.jar!/:5.2.8.Final]
        ... 85 common frames omitted

是什么原因导致查询突然不再起作用,这里所谓的testdb是什么?

1 个答案:

答案 0 :(得分:1)

getAllStandardItems方法标有@Transactional注释,至少这两个原因没有意义:

  • 您没有使用Ignite事务管理器,因此Spring会在与Ignite无关的其他数据库上启动事务。但是,方法本身只能访问Ignite。
  • Ignite缓存迭代无论如何都不是事务性的,所以即使使用Ignite事务管理器注释也不会有任何区别。

显然无法访问指向数据库JpaTransactionManager的测试失败。但显然这个方法不需要它,因此您应该删除注释以使其工作。