From 5e8e0b11f5c88a0539e0cbec5078f4c0f1fa09ee Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Wed, 17 Dec 2014 17:08:13 +0100 Subject: [PATCH] 455476 MongoSessionManager sessions always expire at create + maxIdle --- .../nosql/mongodb/MongoSessionIdManager.java | 5 +++++ .../nosql/mongodb/MongoSessionManager.java | 18 +++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionIdManager.java b/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionIdManager.java index 18d44061c34..e517f8aab6e 100644 --- a/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionIdManager.java +++ b/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionIdManager.java @@ -259,6 +259,7 @@ public class MongoSessionIdManager extends AbstractSessionIdManager */ protected void purge() { + __log.debug("PURGING"); BasicDBObject invalidQuery = new BasicDBObject(); invalidQuery.put(MongoSessionManager.__ACCESSED, new BasicDBObject("$lt",System.currentTimeMillis() - _purgeInvalidAge)); @@ -432,6 +433,8 @@ public class MongoSessionIdManager extends AbstractSessionIdManager _scavengerTask = _scheduler.schedule(new Scavenger(), _scavengePeriod, TimeUnit.MILLISECONDS); } + else if (__log.isDebugEnabled()) + __log.debug("Scavenger disabled"); //if purging is enabled, setup the purge thread @@ -444,6 +447,8 @@ public class MongoSessionIdManager extends AbstractSessionIdManager } _purgerTask = _scheduler.schedule(new Purger(), _purgeDelay, TimeUnit.MILLISECONDS); } + else if (__log.isDebugEnabled()) + __log.debug("Purger disabled"); } } diff --git a/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionManager.java b/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionManager.java index 48fd1c2f00a..3daa0a0d906 100644 --- a/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionManager.java +++ b/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionManager.java @@ -42,6 +42,8 @@ import com.mongodb.BasicDBObject; import com.mongodb.DBCollection; import com.mongodb.DBObject; import com.mongodb.MongoException; +import com.mongodb.WriteConcern; +import com.mongodb.WriteResult; /** @@ -268,7 +270,7 @@ public class MongoSessionManager extends NoSqlSessionManager Long currentExpiry = (Long)o.get(__EXPIRY); if (currentMaxIdle != null && getMaxInactiveInterval() > 0 && getMaxInactiveInterval() < currentMaxIdle) sets.put(__MAX_IDLE, getMaxInactiveInterval()); - if (currentExpiry != null && expiry > 0 && expiry < currentExpiry) + if (currentExpiry != null && expiry > 0 && expiry != currentExpiry) sets.put(__EXPIRY, currentExpiry); } } @@ -302,9 +304,11 @@ public class MongoSessionManager extends NoSqlSessionManager if (!unsets.isEmpty()) update.put("$unset",unsets); - _dbSessions.update(key,update,upsert,false); - __log.debug("MongoSessionManager:save:db.sessions.update( {}, {}, true) ", key, update); + _dbSessions.update(key,update,upsert,false,WriteConcern.SAFE); + if (__log.isDebugEnabled()) + __log.debug("MongoSessionManager:save:db.sessions.update( {}, {} )", key, update); + if (activateAfterSave) session.didActivate(); @@ -421,7 +425,7 @@ public class MongoSessionManager extends NoSqlSessionManager update.put("$set",sets); } - _dbSessions.update(key,update,false,false); + _dbSessions.update(key,update,false,false,WriteConcern.SAFE); session.didActivate(); @@ -520,7 +524,7 @@ public class MongoSessionManager extends NoSqlSessionManager BasicDBObject unsets = new BasicDBObject(); unsets.put(getContextKey(),1); remove.put("$unset",unsets); - _dbSessions.update(key,remove); + _dbSessions.update(key,remove,false,false,WriteConcern.SAFE); return true; } @@ -556,7 +560,7 @@ public class MongoSessionManager extends NoSqlSessionManager update.put("$set",sets); BasicDBObject key = new BasicDBObject(__ID,idInCluster); - _dbSessions.update(key,update); + _dbSessions.update(key,update,false,false,WriteConcern.SAFE); } } @@ -573,7 +577,7 @@ public class MongoSessionManager extends NoSqlSessionManager BasicDBObject sets = new BasicDBObject(); BasicDBObject update = new BasicDBObject(__ID, newClusterId); sets.put("$set", update); - _dbSessions.update(key, sets, false, false); + _dbSessions.update(key, sets, false, false,WriteConcern.SAFE); } /*------------------------------------------------------------ */