Hi,

I've tested my code on:
Windows XP Service Pack 2
java 1.5.0_06
Tomcat 5.5

memcached-2.0.jar
spy-2.4.jar


I've also a local memcahed for Win32 downloaded at http://jehiah.cz/projects/memcached-win32/ (memcached 1.2.1)

that's my taglib

public int doStartTag() throws JspException {
 String line;
 try {
String hostcache = pageContext.getServletContext().getInitParameter("hostmemcached");
   memcachedClient = MemcachedUtilityStatic.getIstance(hostcache);
   ...
   Object myObj = null;
   Future<Object> f = memcachedClient.asyncGet(_key.toString());
   try {
     myObj = f.get(100, TimeUnit.MILLISECONDS);
     contentCached = (String)myObj;
     if (contentCached == null){
       // sorry, you're content is not cached,
       // PLEASE LOAD IT DIRECTLY
       .......
       System.out.println("[memcachedWSAsync] content NOT cached!");
     }else{
       System.out.println("[memcachedWSAsync] content cached!");
     }
    }catch(TimeoutException e) {
     // Since we don't need this, go ahead and cancel the operation.  This
     // is not strictly necessary, but it'll save some work on the server.
     f.cancel(true);
     // Do other timeout related stuff
     // PLEASE LOAD IT DIRECTLY
     .....
    }
 }catch (Throwable t) {
   System.out.println("\n DISASTER!!!\n");
   t.printStackTrace();
 }
 return SKIP_BODY;
}

Test 1.
assertion enabled, memcached server up. That's all ok. The first time the
content is not cached, but the other yes.

-------------------
Test 2.
assertion enabled, memcached server goes down. If I call the page using the taglib
I found this message on catalina.out

"Connessione in corso interrotta forzatamente dall'host remoto" sounds like
"Connection blocked forced by remote host"

2008-03-14 09:14:55.109 INFO net.spy.memcached.MemcachedConnection: IOException handling null, reconnecting java.io.IOException: Connessione in corso interrotta forzatamente dall'host remoto
       at sun.nio.ch.SocketDispatcher.write0(Native Method)
       at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:33)
       at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:104)
       at sun.nio.ch.IOUtil.write(IOUtil.java:75)
       at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:302)
at net.spy.memcached.protocol.TCPMemcachedNodeImpl.writeSome(TCPMemcachedNodeImpl.java:355) at net.spy.memcached.MemcachedConnection.handleWrites(MemcachedConnection.java:283) at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:255) at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:180)
       at net.spy.memcached.MemcachedClient.run(MemcachedClient.java:730)
2008-03-14 09:14:55.140 WARN net.spy.memcached.MemcachedConnection: Closing, and reopening {QA sa=/127.0.0.1:11211, #Ro ps=1, #Wops=0, #iq=0, [EMAIL PROTECTED], topWop=null, toWrite=51, interes
ted=4}, attempt 0.
2008-03-14 09:14:55.140 WARN net.spy.memcached.protocol.ascii.AsciiMemcachedNodeImpl: Discarding partially completed op
: [EMAIL PROTECTED]
[memcachedWSAsync] content NOT cached!
Exception in thread "Memcached IO over {MemcachedConnection to /127.0.0.1:11211}" java.nio.channels.CancelledKeyExceptio
n
       at sun.nio.ch.SelectionKeyImpl.ensureValid(SelectionKeyImpl.java:55)
       at sun.nio.ch.SelectionKeyImpl.readyOps(SelectionKeyImpl.java:69)
       at java.nio.channels.SelectionKey.isReadable(SelectionKey.java:271)
at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:262) at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:180)
       at net.spy.memcached.MemcachedClient.run(MemcachedClient.java:730)

[memcachedWSAsync] DISASTER!!!

java.lang.AssertionError: IO Thread is not running.
       at net.spy.memcached.MemcachedClient.addOp(MemcachedClient.java:195)
at net.spy.memcached.MemcachedClient.asyncStore(MemcachedClient.java:237)
       at net.spy.memcached.MemcachedClient.set(MemcachedClient.java:296)
at it.kataweb.memcached.memcachedWSAsync.doStartTag(memcachedWSAsync.java:191) at org.apache.jsp.index_jsp._jspx_meth_mm_memcachedWS_0(index_jsp.java:97)
       at org.apache.jsp.index_jsp._jspService(index_jsp.java:65)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
       at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java
:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
       at java.lang.Thread.run(Thread.java:595)

If the memcached server goes up the content is never cached, I continue to find the java.lang.AssertionError

-------------------
Test 3.
assertion disabled, memcached server goes down. If I call the page n times in the catalina.out
I found:

2008-03-14 09:27:01.812 INFO net.spy.memcached.MemcachedConnection: IOException handling null, reconnecting java.io.IOException: Connessione in corso interrotta forzatamente dall'host remoto
       at sun.nio.ch.SocketDispatcher.write0(Native Method)
       at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:33)
       at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:104)
       at sun.nio.ch.IOUtil.write(IOUtil.java:75)
       at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:302)
at net.spy.memcached.protocol.TCPMemcachedNodeImpl.writeSome(TCPMemcachedNodeImpl.java:355) at net.spy.memcached.MemcachedConnection.handleWrites(MemcachedConnection.java:283) at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:255) at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:180)
       at net.spy.memcached.MemcachedClient.run(MemcachedClient.java:730)
2008-03-14 09:27:01.828 WARN net.spy.memcached.MemcachedConnection: Closing, and reopening {QA sa=/127.0.0.1:11211, #Ro ps=1, #Wops=0, #iq=0, [EMAIL PROTECTED], topWop=null, toWrite=51, interest
ed=4}, attempt 0.
2008-03-14 09:27:01.828 WARN net.spy.memcached.protocol.ascii.AsciiMemcachedNodeImpl: Discarding partially completed op
: [EMAIL PROTECTED]
Exception in thread "Memcached IO over {MemcachedConnection to /127.0.0.1:11211}" [memcachedWSAsync] 1. url http://data. kataweb.it/kpm2cinx/content/335435 using key: WS_a3f715ef7a3c51387b5b050776add94f_memcached NOT cached!
java.nio.channels.CancelledKeyException
       at sun.nio.ch.SelectionKeyImpl.ensureValid(SelectionKeyImpl.java:55)
       at sun.nio.ch.SelectionKeyImpl.readyOps(SelectionKeyImpl.java:69)
       at java.nio.channels.SelectionKey.isReadable(SelectionKey.java:271)
at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:262) at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:180)
       at net.spy.memcached.MemcachedClient.run(MemcachedClient.java:730)
[memcachedWSAsync] content NOT cached!
[memcachedWSAsync] content NOT cached!
[memcachedWSAsync] content NOT cached!
[memcachedWSAsync] content NOT cached!

If the memcached server goes up the content is never cached, I continue to find (contentCached == null) In this case, with no accertions enabled, the exception seems to be captured before
arriving to the taglib (no "DISASTER!!!" string found on catalina.out)


Thank you very much,

Massimo


Dustin Sallings ha scritto:

On Mar 13, 2008, at 9:37, Massimo Marazza wrote:

Suppose memcached server is up. No problem found when I start the context and I request the page, but if I stop the memcache server then I start it and I request the page, the MemcachedClient object is not able to cache
contents.
If I use a different approach in the tag lib, that is create a new MemcachedClient object
 public int doStartTag() throws JspException {
      try {
String hostcache = pageContext.getServletContext().getInitParameter("hostmemcached"); memcachedClient = new MemcachedClient(AddrUtil.getAddresses(hostcache));
           ......
}

and if I do a memcached server stop and start, after the restart the MemcachedClient is able to cache objects.
For me that's strange...
Maybe the right approach when the memcache server goes down is to restart the web container (Tomcat)?

It sounds like you're describing a bug, but it's not something I've seen before. I sometimes forget to start my memcached instances before starting my tests and they still pass after I start the server.

What version are you running, and on what OS? Are there any errors being written anywhere? Perhaps an assertion fired (are you running with assertions enabled?).

--
Dustin Sallings

Reply via email to