代码之家  ›  专栏  ›  技术社区  ›  lmk

常规和Spring抽象的Ignite事务失败,IllegalstateException Post Manual Reconnect with ClientConnectDisabled为true

  •  0
  • lmk  · 技术社区  · 6 年前

    我们正在运行2.4版&using spring IgniteSpringBean , SpringTransactionManager 和; Spring Data 用于群集和事务缓存访问的存储库。

    由于我们遇到了许多与点火客户端断开连接异常相关的问题,因此我正在编写手动分段冲突解决程序(通过禁用客户端自动重新连接将clientReconnectDisabled设置为true),它将检测此情况(使用定期运行的简单缓存查询),并通过以下方式启动断开连接 IgniteSpringBean#close 然后按说明重新连接 here

    我有缓存访问方面的其他问题,如前所述解决了这些问题。 here

    但问题是,每当我尝试使用Spring事务注释方法时,它都无法创建一个带有IllegalstateException的事务,其中提到网格处于无效状态。

    我再次怀疑这与我之前(上面引用的)面对的陈旧引用的问题相同,可能需要在代码中通过更新SpringTransactionManager中的内核引用来处理它。我正在尝试修复程序,如果它有效,它将更新。

    同时,如果有人有更容易/更快的修复方法/建议,请分享相同的内容。

    以下是例外情况:

    com.***.dcm.exception.InternalServerErrorException: Error while creating the definition. Message is : Could not create Ignite transaction; nested exception is java.lang.IllegalStateException: Grid is in invalid state to perform this operation. It either not started yet or has already being or have stopped [igniteInstanceName=null, state=STOPPED]
        at com.***.dcm.topology.middleware.controller.TopologyServiceControllerHelper.createTopologyDefinition(TopologyServiceControllerHelper.java:124)
        at com.***.dcm.topology.middleware.controller.TopologyServiceController.createTopologyDefinition(TopologyServiceController.java:129)
    2018-07-24 14:11:00.519 ERROR b731ba99e9b2 --- [nio-7099-exec-1] .d.t.m.c.TopologyServiceControllerHelper : Error while creating the definition. Message is : Could not create Ignite transaction; nested exception is java.lang.IllegalStateException: Grid is in invalid state to perform this operation. It either not started yet or has already being or have stopped [igniteInstanceName=null, state=STOPPED]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
        at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
        at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1434)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:748)
    
    2 回复  |  直到 6 年前
        1
  •  2
  •   Pavel Vinokurov    6 年前

    在2.5版本中修复重新连接后关闭缓存( https://issues.apache.org/jira/browse/IGNITE-2766 )

    据我所知,您希望创建一个新的Ignite实例,并将其用于SpringTransactionManager。 我认为这不是正确的方法,因为在点火库impl缓存中有需要重新初始化的缓存实例。

    我建议使用IgniteClientDisconnectedException ReconnectFuture()。 方法,返回在重新连接发生时将完成的未来。 因此,您可以阻塞客户机,等待将来的问题得到解决,客户机开始活动。 例如:

    public void checkAndReconnect(){
        try{
            // make ignite query
        }catch(IgniteClientDisconnectedException ex){
           ex.reconnectFuture().get();
        }
    }
    

    希望有助于解决连接问题。

        2
  •  1
  •   lmk    6 年前

    我前面提到的修复方法奏效了。对于可能面临此问题的其他人,修复方法包括在重新连接后更新SpringTransactionManager中的Ignite内核引用。

    下面是所需的代码更改,

    在SpringTransactionManager.java中,

    /**
     * @author mlekshma
     * 
     * @param ignite
     */
    protected void setResourceFactory(final Ignite ignite) {
        this.ignite = ignite;
    }
    

    我正在使用SpringTransactionManager的匿名内部类对注入进行黑客攻击,因为2.4中存在点火弹簧集成问题(更多信息 here )

    /**
     * @author mlekshma
     *
     */
    @Configuration
    @EnableScheduling
    @ComponentScan("com.***.***")
    @EnableIgniteRepositories(basePackages={"com.***.***"})
    @ImportResource("classpath:ignite-client-conf.xml")
    @PropertySource("classpath:ignite-client.properties")
    @EnableTransactionManagement
    public class IgniteClientConfig {
    
        private static final Logger LOGGER = LoggerFactory.getLogger(IgniteClientConfig.class);
    
        public IgniteClientConfig() {
        }
    
        /**
         * @return
         */
        @Bean
        @DependsOn("igniteInstance")
        @Primary
        @Lazy
        public PlatformTransactionManager transactionManager() {
            final SpringTransactionManager springTransactionManager = new SpringTransactionManager() {
    
                private boolean isInitialized = false;
    
                @Override 
                public void afterPropertiesSet() throws Exception {
                    if (isInitialized) {
                        if(((IgniteKernal) getResourceFactory()).context().gateway().getState() == GridKernalState.STOPPED) {
                            IgniteKernal igniteKernal = (IgniteKernal) Ignition.ignite(getIgniteInstanceName());
                            if(igniteKernal != null) {
                                setResourceFactory(igniteKernal);
                            }
                        }
                    }
                }
    
                /**
                 * @param event
                 */
                @EventListener
                public void handleContextRefresh(final ContextRefreshedEvent event) throws Exception {
                    LOGGER.info("Setting up tx support..");
                    super.afterPropertiesSet();
                    isInitialized = true;
                }
            };
            // Use default grid client instance created..
            springTransactionManager.setTransactionConcurrency(TransactionConcurrency.PESSIMISTIC);
            return springTransactionManager;
        }
    
    }