You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ignite.apache.org by "Bruno Barin (JIRA)" <ji...@apache.org> on 2017/09/18 14:33:00 UTC
[jira] [Comment Edited] (IGNITE-2786) SpringCache doesn't survive
client reconnect
[ https://issues.apache.org/jira/browse/IGNITE-2786?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16170087#comment-16170087 ]
Bruno Barin edited comment on IGNITE-2786 at 9/18/17 2:32 PM:
--------------------------------------------------------------
Hey,
Wouldn't be enough to implement CacheErrorHandler with something like this:
{code:java}
public class IgniteCacheErrorHandler implements CacheErrorHandler {
private final SpringCacheManager springCacheManager;
public IgniteCacheErrorHandler(SpringCacheManager springCacheManager) {
this.springCacheManager = springCacheManager;
}
@Override
public void handleCacheGetError(RuntimeException e, Cache cache, Object o) {
if (e instanceof IllegalStateException) {
logger.error("Failed to retrieve value from Cache, node seems to be in an inconsistent state. Restarting node.", e);
springCacheManager.restartNode();
} else {
throw e;
}
}
@Override
public void handleCachePutError(RuntimeException e, Cache cache, Object o, Object o1) {
throw e;
}
@Override
public void handleCacheEvictError(RuntimeException e, Cache cache, Object o) {
throw e;
}
@Override
public void handleCacheClearError(RuntimeException e, Cache cache) {
throw e;
}
{code}
And on SpringCacheManager add a restart method:
{code:java}
public void restartNode() {
caches.entrySet().forEach(entry -> {
caches.get(entry.getKey()).clear();
caches.remove(entry.getKey());
ignite.destroyCache(entry.getKey());
});
try {
restart();
} catch (IgniteCheckedException e) {
logger.error("Failed to restart ignite node",e);
}
}
private void restart() throws IgniteCheckedException {
stop();
start();
}
private void start() throws IgniteCheckedException {
if (cfgPath != null && cfg != null) {
throw new IllegalArgumentException("Both 'configurationPath' and 'configuration' are " +
"provided. Set only one of these properties if you need to start a Ignite node inside of " +
"SpringCacheManager. If you already have a node running, omit both of them and set" +
"'igniteInstanceName' property.");
}
if (cfgPath != null)
ignite = IgniteSpring.start(cfgPath, springCtx);
else if (cfg != null)
ignite = IgniteSpring.start(cfg, springCtx);
else
ignite = Ignition.ignite(igniteInstanceName);
}
private void stop() {
ignite.close();
}
{code}
Let me know if that would work. If so, I will open a PR
was (Author: bbarin):
Hey,
Wouldn't be enough to implement CacheErrorHandler with something like this:
{code:java}
public class IgniteCacheErrorHandler implements CacheErrorHandler {
private final SpringCacheManager springCacheManager;
public IgniteCacheErrorHandler(SpringCacheManager springCacheManager) {
this.springCacheManager = springCacheManager;
}
@Override
public void handleCacheGetError(RuntimeException e, Cache cache, Object o) {
if (e instanceof IllegalStateException) {
logger.error("Failed to retrieve value from Cache, node seems to be in an inconsistent state. Restarting node.", e);
springCacheManager.restartNode();
} else {
throw e;
}
}
@Override
public void handleCachePutError(RuntimeException e, Cache cache, Object o, Object o1) {
throw e;
}
@Override
public void handleCacheEvictError(RuntimeException e, Cache cache, Object o) {
throw e;
}
@Override
public void handleCacheClearError(RuntimeException e, Cache cache) {
throw e;
}
{code}
And on SpringCacheManager add a restart method:
{code:java}
public void restartNode() {
caches.entrySet().forEach(entry -> {
caches.get(entry.getKey()).clear();
caches.remove(entry.getKey());
ignite.destroyCache(entry.getKey());
});
try {
restart();
} catch (IgniteCheckedException e) {
logger.error("Failed to restart ignite node",e);
}
}
private void restart() throws IgniteCheckedException {
stop();
start();
}
private void start() throws IgniteCheckedException {
if (cfgPath != null && cfg != null) {
throw new IllegalArgumentException("Both 'configurationPath' and 'configuration' are " +
"provided. Set only one of these properties if you need to start a Ignite node inside of " +
"SpringCacheManager. If you already have a node running, omit both of them and set" +
"'igniteInstanceName' property.");
}
if (cfgPath != null)
ignite = IgniteSpring.start(cfgPath, springCtx);
else if (cfg != null)
ignite = IgniteSpring.start(cfg, springCtx);
else
ignite = Ignition.ignite(igniteInstanceName);
}
private void stop() {
ignite.close();
}
{code}
> SpringCache doesn't survive client reconnect
> --------------------------------------------
>
> Key: IGNITE-2786
> URL: https://issues.apache.org/jira/browse/IGNITE-2786
> Project: Ignite
> Issue Type: Improvement
> Components: cache
> Affects Versions: 1.5.0.final
> Reporter: Valentin Kulichenko
>
> After a client disconnects and reconnects with new ID, Spring caching can't be used, because existing cache instance are closed.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)