spring - how to skip redis when it crashes -
i‘m using spring-mybatis-redis framework serve web apps(redis cache layer of mybatis , jedis redis client). i'm worrying problem if redis service crashes, how make mybatis skip query in cache. when shut redis down, jedis throws runtimeexception (jedisconnectionexception) , web server not work normally. there solution tell mybatis query in db not redis?
here jedis codes:
protected object readprotocolwithcheckingbroken() { try { object result = protocol.read(inputstream); return result; } catch (jedisconnectionexception exc) { broken = true; throw exc; } } public static object read(final redisinputstream is) { return process(is); } private static object process(final redisinputstream is) { final byte b = is.readbyte(); if (b == plus_byte) { return processstatuscodereply(is); } else if (b == dollar_byte) { return processbulkreply(is); } else if (b == asterisk_byte) { return processmultibulkreply(is); } else if (b == colon_byte) { return processinteger(is); } else if (b == minus_byte) { processerror(is); return null; } else { throw new jedisconnectionexception("unknown reply: " + (char) b); } } public byte readbyte() throws jedisconnectionexception { ensurefill(); return buf[count++]; } this methods assumes there required bytes read. if cannot read anymore bytes exception thrown ascertain stream smaller expected.
private void ensurefill() throws jedisconnectionexception { if (count >= limit) { try { limit = in.read(buf); count = 0; if (limit == -1) { throw new jedisconnectionexception("unexpected end of stream."); } } catch (ioexception e) { throw new jedisconnectionexception(e); } } } and console info:
debug [http-bio-8080-exec-3] - dispatcherservlet name 'springmvc' processing request [/ssmdemo/student/select.action] debug [http-bio-8080-exec-3] - looking handler method path /student/select.action debug [http-bio-8080-exec-3] - returning handler method [public net.sf.json.jsonarray cn.itcast.ssm.controller.studentcontroller.select(int) throws java.lang.exception] debug [http-bio-8080-exec-3] - returning cached instance of singleton bean 'studentcontroller' debug [http-bio-8080-exec-3] - last-modified value [/ssmdemo/student/select.action] is: -1 debug [http-bio-8080-exec-3] - creating new sqlsession debug [http-bio-8080-exec-3] - registering transaction synchronization sqlsession [org.apache.ibatis.session.defaults.defaultsqlsession@68378de9] cn.itcast.ssm.mapper.studentmapper.getstudentlistbyid:0:2147483647:select userid, username, userage t_user userid = ?:1 debug [http-bio-8080-exec-3] - releasing transactional sqlsession [org.apache.ibatis.session.defaults.defaultsqlsession@68378de9] debug [http-bio-8080-exec-3] - transaction synchronization deregistering sqlsession [org.apache.ibatis.session.defaults.defaultsqlsession@68378de9] debug [http-bio-8080-exec-3] - transaction synchronization closing sqlsession [org.apache.ibatis.session.defaults.defaultsqlsession@68378de9] debug [http-bio-8080-exec-3] - should roll transaction cannot - no transaction available debug [http-bio-8080-exec-3] - resolving exception handler [public net.sf.json.jsonarray cn.itcast.ssm.controller.studentcontroller.select(int) throws java.lang.exception]: org.mybatis.spring.mybatissystemexception: nested exception org.apache.ibatis.exceptions.persistenceexception: ### error querying database. cause: redis.clients.jedis.exceptions.jedisconnectionexception: unexpected end of stream. ### cause: redis.clients.jedis.exceptions.jedisconnectionexception: unexpected end of stream. debug [http-bio-8080-exec-3] - resolving exception handler [public net.sf.json.jsonarray cn.itcast.ssm.controller.studentcontroller.select(int) throws java.lang.exception]: org.mybatis.spring.mybatissystemexception: nested exception org.apache.ibatis.exceptions.persistenceexception: ### error querying database. cause: redis.clients.jedis.exceptions.jedisconnectionexception: unexpected end of stream. ### cause: redis.clients.jedis.exceptions.jedisconnectionexception: unexpected end of stream. debug [http-bio-8080-exec-3] - resolving exception handler [public net.sf.json.jsonarray cn.itcast.ssm.controller.studentcontroller.select(int) throws java.lang.exception]: org.mybatis.spring.mybatissystemexception: nested exception org.apache.ibatis.exceptions.persistenceexception: ### error querying database. cause: redis.clients.jedis.exceptions.jedisconnectionexception: unexpected end of stream. ### cause: redis.clients.jedis.exceptions.jedisconnectionexception: unexpected end of stream. debug [http-bio-8080-exec-3] - not complete request org.mybatis.spring.mybatissystemexception: nested exception org.apache.ibatis.exceptions.persistenceexception: ### error querying database. cause: redis.clients.jedis.exceptions.jedisconnectionexception: unexpected end of stream. ### cause: redis.clients.jedis.exceptions.jedisconnectionexception: unexpected end of stream. @ org.mybatis.spring.mybatisexceptiontranslator.translateexceptionifpossible(mybatisexceptiontranslator.java:75) @ org.mybatis.spring.sqlsessiontemplate$sqlsessioninterceptor.invoke(sqlsessiontemplate.java:371) @ com.sun.proxy.$proxy41.selectlist(unknown source) @ org.mybatis.spring.sqlsessiontemplate.selectlist(sqlsessiontemplate.java:198) @ org.apache.ibatis.binding.mappermethod.executeformany(mappermethod.java:119) @ org.apache.ibatis.binding.mappermethod.execute(mappermethod.java:63) @ org.apache.ibatis.binding.mapperproxy.invoke(mapperproxy.java:52) @ com.sun.proxy.$proxy44.getstudentlistbyid(unknown source) @ cn.itcast.ssm.serviceimpl.studentserviceimpl.selectstudent(studentserviceimpl.java:18) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ org.springframework.aop.support.aoputils.invokejoinpointusingreflection(aoputils.java:317) @ org.springframework.aop.framework.reflectivemethodinvocation.invokejoinpoint(reflectivemethodinvocation.java:183) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:150) @ org.springframework.transaction.interceptor.transactioninterceptor.invoke(transactioninterceptor.java:110) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:172) @ org.springframework.aop.interceptor.exposeinvocationinterceptor.invoke(exposeinvocationinterceptor.java:90) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:172) @ org.springframework.aop.framework.jdkdynamicaopproxy.invoke(jdkdynamicaopproxy.java:204) @ com.sun.proxy.$proxy45.selectstudent(unknown source) @ cn.itcast.ssm.controller.studentcontroller.select(studentcontroller.java:36) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ org.springframework.web.method.support.invocablehandlermethod.invoke(invocablehandlermethod.java:219) @ org.springframework.web.method.support.invocablehandlermethod.invokeforrequest(invocablehandlermethod.java:132) @ org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod.invokeandhandle(servletinvocablehandlermethod.java:104) @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.invokehandlemethod(requestmappinghandleradapter.java:746) @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.handleinternal(requestmappinghandleradapter.java:687) @ org.springframework.web.servlet.mvc.method.abstracthandlermethodadapter.handle(abstracthandlermethodadapter.java:80) @ org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:925) @ org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:856) @ org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:915) @ org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:811) @ javax.servlet.http.httpservlet.service(httpservlet.java:624) @ org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:796) @ javax.servlet.http.httpservlet.service(httpservlet.java:731) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:303) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.springframework.web.filter.characterencodingfilter.dofilterinternal(characterencodingfilter.java:88) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.logging.log4j.core.web.log4jservletfilter.dofilter(log4jservletfilter.java:66) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:218) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:110) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:506) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:169) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:103) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:962) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:116) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:445) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1115) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:637) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:316) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(thread.java:745) caused by: org.apache.ibatis.exceptions.persistenceexception: ### error querying database. cause: redis.clients.jedis.exceptions.jedisconnectionexception: unexpected end of stream. ### cause: redis.clients.jedis.exceptions.jedisconnectionexception: unexpected end of stream. @ org.apache.ibatis.exceptions.exceptionfactory.wrapexception(exceptionfactory.java:26) @ org.apache.ibatis.session.defaults.defaultsqlsession.selectlist(defaultsqlsession.java:111) @ org.apache.ibatis.session.defaults.defaultsqlsession.selectlist(defaultsqlsession.java:102) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ org.mybatis.spring.sqlsessiontemplate$sqlsessioninterceptor.invoke(sqlsessiontemplate.java:358) ... 65 more caused by: redis.clients.jedis.exceptions.jedisconnectionexception: unexpected end of stream. @ redis.clients.util.redisinputstream.ensurefill(redisinputstream.java:199) @ redis.clients.util.redisinputstream.readbyte(redisinputstream.java:40) @ redis.clients.jedis.protocol.process(protocol.java:151) @ redis.clients.jedis.protocol.read(protocol.java:215) @ redis.clients.jedis.connection.readprotocolwithcheckingbroken(connection.java:340) @ redis.clients.jedis.connection.getbinarybulkreply(connection.java:259) @ redis.clients.jedis.binaryjedis.get(binaryjedis.java:244) @ cn.itcast.ssm.cache.rediscache.getobject(rediscache.java:89) @ org.apache.ibatis.cache.decorators.loggingcache.getobject(loggingcache.java:57) @ org.apache.ibatis.cache.decorators.transactionalcache.getobject(transactionalcache.java:54) @ org.apache.ibatis.cache.transactionalcachemanager.getobject(transactionalcachemanager.java:35) @ org.apache.ibatis.executor.cachingexecutor.query(cachingexecutor.java:88) @ org.apache.ibatis.executor.cachingexecutor.query(cachingexecutor.java:77) @ org.apache.ibatis.session.defaults.defaultsqlsession.selectlist(defaultsqlsession.java:108) ... 71 more sep 11, 2017 6:08:34 pm org.apache.catalina.core.standardwrappervalve invoke severe: servlet.service() servlet [springmvc] in context path [/ssmdemo] threw exception [request processing failed; nested exception org.mybatis.spring.mybatissystemexception: nested exception org.apache.ibatis.exceptions.persistenceexception: ### error querying database. cause: redis.clients.jedis.exceptions.jedisconnectionexception: unexpected end of stream. ### cause: redis.clients.jedis.exceptions.jedisconnectionexception: unexpected end of stream.] root cause redis.clients.jedis.exceptions.jedisconnectionexception: unexpected end of stream. @ redis.clients.util.redisinputstream.ensurefill(redisinputstream.java:199) @ redis.clients.util.redisinputstream.readbyte(redisinputstream.java:40) @ redis.clients.jedis.protocol.process(protocol.java:151) @ redis.clients.jedis.protocol.read(protocol.java:215) @ redis.clients.jedis.connection.readprotocolwithcheckingbroken(connection.java:340) @ redis.clients.jedis.connection.getbinarybulkreply(connection.java:259) @ redis.clients.jedis.binaryjedis.get(binaryjedis.java:244) @ cn.itcast.ssm.cache.rediscache.getobject(rediscache.java:89) @ org.apache.ibatis.cache.decorators.loggingcache.getobject(loggingcache.java:57) @ org.apache.ibatis.cache.decorators.transactionalcache.getobject(transactionalcache.java:54) @ org.apache.ibatis.cache.transactionalcachemanager.getobject(transactionalcachemanager.java:35) @ org.apache.ibatis.executor.cachingexecutor.query(cachingexecutor.java:88) @ org.apache.ibatis.executor.cachingexecutor.query(cachingexecutor.java:77) @ org.apache.ibatis.session.defaults.defaultsqlsession.selectlist(defaultsqlsession.java:108) @ org.apache.ibatis.session.defaults.defaultsqlsession.selectlist(defaultsqlsession.java:102) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ org.mybatis.spring.sqlsessiontemplate$sqlsessioninterceptor.invoke(sqlsessiontemplate.java:358) @ com.sun.proxy.$proxy41.selectlist(unknown source) @ org.mybatis.spring.sqlsessiontemplate.selectlist(sqlsessiontemplate.java:198) @ org.apache.ibatis.binding.mappermethod.executeformany(mappermethod.java:119) @ org.apache.ibatis.binding.mappermethod.execute(mappermethod.java:63) @ org.apache.ibatis.binding.mapperproxy.invoke(mapperproxy.java:52) @ com.sun.proxy.$proxy44.getstudentlistbyid(unknown source) @ cn.itcast.ssm.serviceimpl.studentserviceimpl.selectstudent(studentserviceimpl.java:18) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ org.springframework.aop.support.aoputils.invokejoinpointusingreflection(aoputils.java:317) @ org.springframework.aop.framework.reflectivemethodinvocation.invokejoinpoint(reflectivemethodinvocation.java:183) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:150) @ org.springframework.transaction.interceptor.transactioninterceptor.invoke(transactioninterceptor.java:110) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:172) @ org.springframework.aop.interceptor.exposeinvocationinterceptor.invoke(exposeinvocationinterceptor.java:90) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:172) @ org.springframework.aop.framework.jdkdynamicaopproxy.invoke(jdkdynamicaopproxy.java:204) @ com.sun.proxy.$proxy45.selectstudent(unknown source) @ cn.itcast.ssm.controller.studentcontroller.select(studentcontroller.java:36) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ org.springframework.web.method.support.invocablehandlermethod.invoke(invocablehandlermethod.java:219) @ org.springframework.web.method.support.invocablehandlermethod.invokeforrequest(invocablehandlermethod.java:132) @ org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod.invokeandhandle(servletinvocablehandlermethod.java:104) @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.invokehandlemethod(requestmappinghandleradapter.java:746) @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.handleinternal(requestmappinghandleradapter.java:687) @ org.springframework.web.servlet.mvc.method.abstracthandlermethodadapter.handle(abstracthandlermethodadapter.java:80) @ org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:925) @ org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:856) @ org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:915) @ org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:811) @ javax.servlet.http.httpservlet.service(httpservlet.java:624) @ org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:796) @ javax.servlet.http.httpservlet.service(httpservlet.java:731) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:303) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.springframework.web.filter.characterencodingfilter.dofilterinternal(characterencodingfilter.java:88) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.logging.log4j.core.web.log4jservletfilter.dofilter(log4jservletfilter.java:66) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:218) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:110) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:506) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:169) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:103) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:962) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:116) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:445) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1115) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:637) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:316) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(thread.java:745) the versions follows:
- spring-3.2.0
- mybatis-3.2.7
- spring-mybatis-1.2.2
- redis-4.0.1
- jedis-2.9.0
sorry poor english , in advance!
Comments
Post a Comment