定期与春数据基于缓存操作失败后CacheStoppedException手动与clientRecon

2019-10-30 11:56发布

我们正在运行的2.4版本和使用Spring IgniteSpringBean及弹簧数据仓库集群和缓存访问。

既然我们已经有很多的IgniteClientDisconnectedException相关的问题,我写一个手动分割解析(通过禁用自动客户端重新连接与clientReconnectDisabled设置为true),这将检测到这种情况(使用一个定期运行一个简单的缓存查询)发起断开经由IgniteSpringBean#紧密接着用下面的代码片段(非常类似于该讨论中,重新连接http://apache-ignite-users.70518.x6.nabble.com/SPI-has-already-been-started-always-创建新的配置实例换每个起动点燃龄-td7360.html ),

代码片段豆DCMIgniteSpringBean#重新连接()在XML配置参考如下:

public final void reconnect(final IgniteConfiguration specifiedIgniteConfiguration) {
  LOGGER.info("Initiating reconnect..");
  try {
    close();
    //destroy();
  } catch (Exception e) {
    LOGGER.warn("Error while disconnecting", e);
  }
  LOGGER.info("Disconnected..");
  try {
    Thread.sleep(1000);
  } catch (Exception e) {
    LOGGER.warn("Error while pausing to reconnect", e);
  }
  setConfiguration(specifiedIgniteConfiguration);
  afterSingletonsInstantiated();
  final CacheConfiguration[] cfgArray = specifiedIgniteConfiguration.getCacheConfiguration();
  LOGGER.info("Cache configuration is : {}", cfgArray);
  getOrCreateCaches(Arrays.asList(cfgArray));
  LOGGER.info("Reconnected..");
}

该XML配置bean的片段:

<bean id="igniteInstance" class="com.brocade.dcm.configuration.DCMIgniteSpringBean">
        <property name="configuration" ref="grid.cfg"/>
</bean>
<bean id="grid.cfg.provider" class="com.brocade.dcm.configuration.ClientHealthBasedReconnectWrapper">
        <lookup-method name="createIgniteConfiguration" bean="grid.cfg"/>
</bean>
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration" scope="prototype">
...
...
</bean>

通过以上我得到这个工作和看到我伸出IgniteSpringBean客户正确重新连接和启动所有缓存的井。

然而问题是,即使客户端连接和高速缓存启动所有后续调用/查询到任何的IgniteCache & IgniteRepository实例失败,CacheStoppedException(下)都变得不可用。

有人建议我能做什么来刷新这些引用。 我知道,当客户端重新连接后自动断开的引用继续正常工作,它告诉我有一种方法来刷新他们和我不是这样做。

关于如何实现这一目标的任何专家支招......感觉就像我很接近,但仍远因为我在做黑客:-(

下面是例外我得到IgniteCache#查询()&#IgniteRepository findByXXX()调用分别,

class org.apache.ignite.internal.processors.cache.CacheStoppedException: Failed to perform cache operation (cache is stopped): FabricInfoCache
    at org.apache.ignite.internal.processors.cache.GridCacheGateway.enter(GridCacheGateway.java:164)
    at org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy.onEnter(GatewayProtectedCacheProxy.java:1684)
    at org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy.query(GatewayProtectedCacheProxy.java:365)
    at com.brocade.dcm.configuration.ClientHealthBasedReconnectWrapper.monitorHealth(ClientHealthBasedReconnectWrapper.java:110)
    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.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

[Request processing failed; nested exception is java.lang.IllegalStateException: class org.apache.ignite.internal.processors.cache.CacheStoppedException: Failed to perform cache operation (cache is stopped): WebsocketCacheInfo] with root cause
class org.apache.ignite.internal.processors.cache.CacheStoppedException: Failed to perform cache operation (cache is stopped): WebsocketCacheInfo
    at org.apache.ignite.internal.processors.cache.GridCacheGateway.enter(GridCacheGateway.java:164)
    at org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy.onEnter(GatewayProtectedCacheProxy.java:1684)
    at org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy.query(GatewayProtectedCacheProxy.java:365)
    at org.apache.ignite.springdata.repository.query.IgniteRepositoryQuery.execute(IgniteRepositoryQuery.java:117)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:483)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:461)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
    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.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    at com.sun.proxy.$Proxy182.findByWebsocketSessionId(Unknown Source)
    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.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
    at com.sun.proxy.$Proxy124.findByWebsocketSessionId(Unknown Source)

感谢匿名人士

Answer 1:

我相信这应该是固定在2.5:

https://issues.apache.org/jira/browse/IGNITE-2766

请试试这个版本。



Answer 2:

对于其他人面临这样的问题,我从源代码构建和固定代码固定的问题GatewayProtectedCacheProxy#checkProxyIsValid & GridCacheContext 。

特别感谢@迈克尔分享相关的问题这有助于让这个解决方案。

基本上我看到,当点火被停止和重新启动作为内核停止与一个新的实例重新启动已送达前,有自己的内核上下文中去陈旧的包裹缓存代理引用(4 IgniteCache / IgniteRepository)。 该(春季)应用程序,这些引用(从各种注射)和其后续调用与他们失败。 此修复程序是检查是否存在现有的运行的内核实例/对同一点燃实例名称引用和如果要是用相同名称的缓存已经开始与可用,以便更新代理引用。

private GridCacheGateway<K, V> checkProxyIsValid(@Nullable GridCacheGateway<K, V> gate, boolean tryRestart) {
..
..
  if (isCacheProxy && tryRestart && gate.isStopped() &&
                context().kernalContext().gateway().getState() == GridKernalState.STOPPED) {
            IgniteKernal igniteKernal = (IgniteKernal) Ignition.ignite(context().gridConfig().getIgniteInstanceName());
            if(igniteKernal != null) {
             context().setGridKernalContext(igniteKernal.context());
            }
   }
  if (isCacheProxy && tryRestart && gate.isStopped() &&
            context().kernalContext().gateway().getState() == GridKernalState.STARTED) {
            IgniteCacheProxyImpl proxyImpl = (IgniteCacheProxyImpl) delegate;

            try {
                IgniteInternalCache<K, V> cache = context().kernalContext().cache().<K, V>publicJCache(context().name()).internalProxy();

                GridFutureAdapter<Void> fut = proxyImpl.opportunisticRestart();

                if (fut == null)
                    proxyImpl.onRestarted(cache.context(), cache.context().cache());
                else
                    new IgniteFutureImpl<>(fut).get();

                return gate();
            } catch (IgniteCheckedException ice) {
                // Opportunity didn't work out.
            }
        }

        return gate;
  }

     /**
     * NOTE : This method goes into GridCacheContext.java
     * @param ctx
     */
    public void setGridKernalContext(GridKernalContext ctx) {
        this.ctx = ctx;
    }


文章来源: Regular & Spring Data based cache operations fail with CacheStoppedException post manual reconnect with clientReconnectDisabled as true