ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [2/2] ignite git commit: ignite-1.5 Fixed hang on metadata update inside put in atomic cache when topology read lock is held.
Date Mon, 21 Dec 2015 13:12:02 GMT
ignite-1.5 Fixed hang on metadata update inside put in atomic cache when topology read lock
is held.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/f1e3939a
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f1e3939a
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f1e3939a

Branch: refs/heads/ignite-1537
Commit: f1e3939ad6f6233237d48b3af33196b8f959232b
Parents: bbde85c
Author: sboikov <sboikov@gridgain.com>
Authored: Mon Dec 21 16:11:45 2015 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Mon Dec 21 16:11:45 2015 +0300

----------------------------------------------------------------------
 .../cache/websession/WebSessionFilter.java      | 82 ++++++++++++--------
 1 file changed, 51 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/f1e3939a/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionFilter.java
----------------------------------------------------------------------
diff --git a/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionFilter.java
b/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionFilter.java
index 77e2dae..d060884 100644
--- a/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionFilter.java
+++ b/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionFilter.java
@@ -38,14 +38,16 @@ import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.IgniteTransactions;
-import org.apache.ignite.cache.CachePartialUpdateException;
+import org.apache.ignite.cluster.ClusterTopologyException;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.internal.util.typedef.C1;
 import org.apache.ignite.internal.util.typedef.G;
 import org.apache.ignite.internal.util.typedef.T2;
+import org.apache.ignite.internal.util.typedef.X;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteClosure;
+import org.apache.ignite.lang.IgniteFuture;
 import org.apache.ignite.startup.servlet.ServletContextListenerStartup;
 import org.apache.ignite.transactions.Transaction;
 
@@ -191,6 +193,9 @@ public class WebSessionFilter implements Filter {
     /** Transactions enabled flag. */
     private boolean txEnabled;
 
+    /** */
+    private int retries;
+
     /** {@inheritDoc} */
     @Override public void init(FilterConfig cfg) throws ServletException {
         ctx = cfg.getServletContext();
@@ -207,8 +212,6 @@ public class WebSessionFilter implements Filter {
             cfg.getInitParameter(WEB_SES_MAX_RETRIES_ON_FAIL_NAME_PARAM),
             ctx.getInitParameter(WEB_SES_MAX_RETRIES_ON_FAIL_NAME_PARAM));
 
-        int retries;
-
         try {
             retries = retriesStr != null ? Integer.parseInt(retriesStr) : DFLT_MAX_RETRIES_ON_FAIL;
         }
@@ -226,10 +229,6 @@ public class WebSessionFilter implements Filter {
 
         log = webSesIgnite.log();
 
-        if (webSesIgnite == null)
-            throw new IgniteException("Grid for web sessions caching is not started (is it
configured?): " +
-                gridName);
-
         cache = webSesIgnite.cache(cacheName);
 
         if (cache == null)
@@ -409,41 +408,62 @@ public class WebSessionFilter implements Filter {
 
         WebSession cached = new WebSession(ses, true);
 
-        try {
-            while (true) {
-                try {
-                    IgniteCache<String, WebSession> cache0;
-
-                    if (cached.getMaxInactiveInterval() > 0) {
-                        long ttl = cached.getMaxInactiveInterval() * 1000;
+        for (int i = 0; i < retries; i++) {
+            try {
+                IgniteCache<String, WebSession> cache0;
 
-                        ExpiryPolicy plc = new ModifiedExpiryPolicy(new Duration(MILLISECONDS,
ttl));
+                if (cached.getMaxInactiveInterval() > 0) {
+                    long ttl = cached.getMaxInactiveInterval() * 1000;
 
-                        cache0 = cache.withExpiryPolicy(plc);
-                    }
-                    else
-                        cache0 = cache;
+                    ExpiryPolicy plc = new ModifiedExpiryPolicy(new Duration(MILLISECONDS,
ttl));
 
-                    WebSession old = cache0.getAndPutIfAbsent(sesId, cached);
+                    cache0 = cache.withExpiryPolicy(plc);
+                }
+                else
+                    cache0 = cache;
 
-                    if (old != null) {
-                        cached = old;
+                WebSession old = cache0.getAndPutIfAbsent(sesId, cached);
 
-                        if (cached.isNew())
-                            cached = new WebSession(cached, false);
-                    }
+                if (old != null) {
+                    cached = old;
 
-                    break;
+                    if (cached.isNew())
+                        cached = new WebSession(cached, false);
                 }
-                catch (CachePartialUpdateException e) {
+
+                break;
+            }
+            catch (CacheException e) {
+                if (log.isDebugEnabled())
+                    log.debug(e.getMessage());
+
+                if (i == retries - 1)
+                    throw new IgniteException("Failed to save session: " + sesId, e);
+                else {
                     if (log.isDebugEnabled())
-                        log.debug(e.getMessage());
+                    log.debug("Failed to save session (will retry): " + sesId);
+
+                    IgniteFuture<?> retryFut = null;
+
+                    if (X.hasCause(e, ClusterTopologyException.class)) {
+                        ClusterTopologyException cause = X.cause(e, ClusterTopologyException.class);
+
+                        assert cause != null : e;
+
+                        retryFut = cause.retryReadyFuture();
+                    }
+
+                    if (retryFut != null) {
+                        try {
+                            retryFut.get();
+                        }
+                        catch (IgniteException retryErr) {
+                            throw new IgniteException("Failed to save session: " + sesId,
retryErr);
+                        }
+                    }
                 }
             }
         }
-        catch (CacheException e) {
-            throw new IgniteException("Failed to save session: " + sesId, e);
-        }
 
         return cached;
     }


Mime
View raw message