magro / memcached-session-manager

A tomcat session manager that backups sessions in memcached and pulls them from there if asked for unknown sessions
Apache License 2.0
760 stars 348 forks source link

Support redis a backend storage #261

Open ghost opened 9 years ago

ghost commented 9 years ago

From ryang....@gmail.com on December 16, 2014 05:01:01

This is an enhancement.

We used https://github.com/jcoleman/tomcat-redis-session-manager as a redis tomcat session manager. Unfortunately we had some legacy parts using session heavily and there were racing conditions. The reason is that two ajax requests will deerialize from redis and have a copy of session, when finishing, they two will write to redis and the later one win and override the earlier one. Your session persistence strategy seems to fit our need, but look at the codes I don't know how to change it to support redis. If I understand correctly, it should be trivial to switch backend storage if designed well. Please have a look whether it is possible to support redis as an external storage.

Original issue: http://code.google.com/p/memcached-session-manager/issues/detail?id=222

ghost commented 9 years ago

From martin.grotzke on December 17, 2014 00:41:51

There was once a pull request (https://github.com/magro/memcached-session-manager/pull/18) from which I created a branch (https://github.com/magro/memcached-session-manager/tree/pluggable-storage-pull18). While working on this I ran into issues with integration tests and redis failover tests, I just couldn't get them to work. If you'd like to pick up the work on this I could see if I've everything pushed or if I have still some work in progress locally. Cheers, Martin

ghost commented 9 years ago

From ryang....@gmail.com on December 17, 2014 15:02:02

Hi,

I am interested, please help to push all related changes to a separate branch and I'll have a look.

By the way, I think the session manager shouldn't concern about the failover of the storage. In redis, you could use Redis Sentinel to manage redis nodes and failover stuff. So the session manager only need to know the sentinel nodes. Sentinel nodes will manage the rest nodes for you. That way the session manager should be simpler.

Personally I think the responsibility of session manager is just purely persistence.

Cheers, Rui

ghost commented 9 years ago

From martin.grotzke on December 17, 2014 15:45:53

Hi Rui,

great that you're interested! I'll check tomorrow when I'm back at my pc if everything's pushed.

Basically I agree with you that msm should not be concerned with the backend high availability / failover, but this implies that you need a HA backend and a driver that manages HA transparently for msm. Because I started msm with memcached, there was no such a solution. Later, when membase was available and mature, I added membase support, where in fact the driver manages HA transparently. AFAICS for redis sentinel you'd need https://github.com/hamsterready/jedis-sentinel-pool, or is there a better solution? Cheers, Martin

ghost commented 9 years ago

From martin.grotzke on December 17, 2014 15:58:44

Alternatively redis cluster + Jedis Cluster might be an option. Have you used this already, what do you think?

ghost commented 9 years ago

From ryang....@gmail.com on December 17, 2014 16:13:36

Hi,

Sorry, with redis sentinels, you may also need two sentinels nodes for redundancy. So the session manager does need to manage a node list.

Cheers, Rui

ghost commented 9 years ago

From ryang....@gmail.com on December 17, 2014 17:03:39

basically we set up two redis nodes and two sentinels nodes. we passed sentinels nodes to tomcat-redis-session-manager. And looking at its codes, it is using jedis JedisSentinelPool to manage connection pool.

Cheers, Rui

ghost commented 9 years ago

From martin.grotzke on December 18, 2014 00:47:04

Hi Rui,

I just checked it, the branch "pluggable-storage-pull18" on github is up to date. At that time I tried to setup a redis sentinel integration test based on embedded-redis but there were issues in test mode (while redis sentinel worked when testing manually), I just pushed my stuff to https://github.com/magro/embedded-redis (the main repo is newer, so my version is outdated, perhaps the new upstream stuff already improves things). Cheers, Martin

ghost commented 9 years ago

From ryang....@gmail.com on December 18, 2014 13:55:07

Hi Martin,

Thanks. I will play with it once I have the time.

Cheers, Rui

ghost commented 9 years ago

From ryang....@gmail.com on January 08, 2015 16:11:57

Hi Martin,

try to generate idea project using: mvn idea:idea

got dependency exception: Failed to execute goal on project memcached-session-manager-tc6: Could not resolve dependencies for project de.javakaffee.msm:memcached-session-manager-tc6:jar:1.6.3-SNAPSHOT: The following artifacts could not be resolved: de.javakaffee.msm:memcached-session-manager:jar:1.6.3-SNAPSHOT, de.javakaffee.msm:memcached-session-manager:jar:tests:1.6.3-SNAPSHOT: Could not transfer artifact de.javakaffee.msm:memcached-session-manager:jar:1.6.3-SNAPSHOT from/to jmemcached (http://thimbleware.com/maven): thimbleware.com: Unknown host thimbleware.com -> [Help 1] I know buildr. But I am a basic mvn user. I am guessing that I need to do local publish. any idea how I can quickly workaround this? Cheers, Rui

ghost commented 9 years ago

From martin.grotzke on January 09, 2015 00:16:20

Hi Rui,

I just removed the thimbleware.com/maven repository in pom.xml, because the artifacts are now available in maven central.

https://github.com/magro/memcached-session-manager/commit/da265b91 Cheers, Martin