Changes since 1.3.6 and patches

21 views
Skip to first unread message

Paul G. Weiss

unread,
Oct 20, 2010, 4:02:06 PM10/20/10
to memcached-se...@googlegroups.com
I've been having problems with memcached-session-manager that look like
they can be solved with the two changes since 1.3.6 (issues 60 and 62).
However, it required a couple of patches that I'd like to submit to you.

First issue 62, having to do with jvmRoute with dashes. For reasons I
won't get into I have to run a web server with memcached-session-manager
where the configured node is n1:localhost:11211, and I want the web server
to operate whether or not there is actually a memcached server there.

When the jvmRoute has a dash this still fails. The failure looks like
this:


SEVERE: An exception or error occurred in the container during the request
processing
java.lang.StringIndexOutOfBoundsException: String index out of range: -5
at java.lang.String.substring(String.java:1937)
at
de.javakaffee.web.msm.SessionIdFormat.extractMemcachedId(SessionIdFormat.java:141)
at
de.javakaffee.web.msm.MemcachedBackupSessionManager.changeSessionIdOnMemcachedFailover(MemcachedBackupSessionManager.java:618)
at
de.javakaffee.web.msm.SessionTrackerValve.changeRequestedSessionId(SessionTrackerValve.java:123)
at
de.javakaffee.web.msm.SessionTrackerValve.invoke(SessionTrackerValve.java:88)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:354)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)

the reason is that the session id looks something like this:

86589219384293462936.my-machine

and the extractMemcachedId routine gets confused when a '.' is before a
'-'. Here is my patch:


diff --git a/core/src/main/java/de/javakaffee/web/msm/SessionIdFormat.java
b/core/src/main/java/de/javakaffee/web/msm/SessionIdFormat.java
index f04f965..8254b0c 100644
--- a/core/src/main/java/de/javakaffee/web/msm/SessionIdFormat.java
+++ b/core/src/main/java/de/javakaffee/web/msm/SessionIdFormat.java
@@ -143,6 +143,8 @@ public class SessionIdFormat {
final int idxDot = sessionId.indexOf( '.' );
if ( idxDot < 0 ) {
return sessionId.substring( idxDash + 1 );
+ } else if (idxDot < idxDash) /* The dash was part of the jvmRoute
*/ {
+ return null;
} else {
return sessionId.substring( idxDash + 1, idxDot );
}
diff --git
a/core/src/test/java/de/javakaffee/web/msm/SessionIdFormatTest.java
b/core/src/test/java/de/javakaffee/web/msm/SessionIdFormatTest.java
index 8addecc..0dadcaa 100644
--- a/core/src/test/java/de/javakaffee/web/msm/SessionIdFormatTest.java
+++ b/core/src/test/java/de/javakaffee/web/msm/SessionIdFormatTest.java
@@ -57,6 +57,7 @@ public class SessionIdFormatTest {
assertEquals( "n", cut.extractMemcachedId( "foo-n" ) );
assertEquals( "n", cut.extractMemcachedId( "foo-n.jvm1" ) );
assertEquals( "n", cut.extractMemcachedId( "foo-n.j-v-m1" ) );
+ assertEquals( null, cut.extractMemcachedId( "foo.j-v-m1" ) );
}

@Test

The other issue that I have is that issue 60 allows this to be disabled.
This allows me to possibly modify my server.xml and disable it at startup
as well, by adding enabled=false to the <Manager> element. ( It turns out
to be easier for me to do this that to comment out the element entirely --
my server.xml file is generated programatically. ) It would be great if
my output didn't contain a whole bunch of these:

2010-10-20 15:36:50.048 WARN net.spy.memcached.MemcachedConnection:
Closing, and reopening {QA sa=localhost/127.0.0.1:11211, #Rops=0, #Wops=0,
#iq=0, topRop=null, topWop=null, toWrite=0, interested=0}, attempt 4.
2010-10-20 15:37:20.049 INFO net.spy.memcached.MemcachedConnection:
Reconnecting {QA sa=localhost/127.0.0.1:11211, #Rops=0, #Wops=0, #iq=0,
topRop=null, topWop=null, toWrite=0, interested=0}
2010-10-20 15:37:20.049 INFO net.spy.memcached.MemcachedConnection:
Connection state changed for sun.nio.ch.SelectionKeyImpl@2dbbec72
2010-10-20 15:37:20.050 INFO net.spy.memcached.MemcachedConnection:
Reconnecting due to failure to connect to {QA
sa=localhost/127.0.0.1:11211, #Rops=0, #Wops=0, #iq=0, topRop=null,
topWop=null, toWrite=0, interested=0}
java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at
sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:574)
at
net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:295)
at
net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:193)
at net.spy.memcached.MemcachedClient.run(MemcachedClient.java:1458)


this patch prevents the memcached client from starting when it is disabled
( I realize then that you can't enable it at runtime ). I realize you
might not like this patch -- perhaps the code can be engineered to bring
the client up or down when the enabled state changes. This works for my
purposes so I thought I share it with you.

diff --git
a/core/src/main/java/de/javakaffee/web/msm/MemcachedBackupSessionManager.java
b/core/src/main/java/de/javakaffee/web/msm/MemcachedBackupSessionManager.java
index 998dc74..bc858fe 100644
---
a/core/src/main/java/de/javakaffee/web/msm/MemcachedBackupSessionManager.java
+++
b/core/src/main/java/de/javakaffee/web/msm/MemcachedBackupSessionManager.java
@@ -331,6 +331,9 @@ public class MemcachedBackupSessionManager extends
ManagerBase implements Lifecy
protected MemcachedClient createMemcachedClient( final
List<InetSocketAddress> addresses,
final Map<InetSocketAddress, String> address2Ids,
final Statistics statistics ) {
+ if ( ! _enabled.get() ) {
+ return null;
+ }
try {
final ConnectionFactory connectionFactory =
createConnectionFactory( address2Ids, statistics );
return new MemcachedClient( connectionFactory, addresses );

Paul G. Weiss

unread,
Oct 21, 2010, 10:04:10 AM10/21/10
to memcached-se...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages