NutzCN Logo
问答 nutzwk redis事物 redis.clients.jedis.exceptions.JedisDataException: ERR EXEC without MULTI
发布于 2316天前 作者 qq_0fa9ea23 3377 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk
public Result frozeSmsAccount(String unit_id, SmsTypeEnum smsTypeEnum, int size) {
        boolean flag = true;
        List<Object> result = null;
        Sms_account_product accountProduct = null;
        int runNumber = 0;
        redisService.watch("accountProduct:" + unit_id + ":" + smsTypeEnum.getValue()); // 标记 短信 账户余额的键值
        while(flag){
            try {
                String accountStr = redisService.get("accountProduct:" + unit_id + ":" + smsTypeEnum.getValue());
                accountProduct = JSON.parseObject(accountStr, Sms_account_product.class);
                if(Lang.isEmpty(accountProduct)){
                    log.errorf("当前账号为空,单位:%s,冻结条数:%s",unit_id,size);
                    redisService.unwatch(); // 解除标记
                    return Result.error(String.format("当前账号为空,单位:%s,冻结条数:%s",unit_id,size));
                }
                int sms_remaining = Lang.isEmpty(accountProduct.getSms_remaining()) ? 0 : accountProduct.getSms_remaining();
                int sms_frozen_num = Lang.isEmpty(accountProduct.getSms_frozen_num()) ? 0 : accountProduct.getSms_frozen_num();
                redisService.set("accpro:sms_remaining:"+unit_id,String.valueOf(sms_remaining));
                redisService.set("accpro:sms_frozen_num"+unit_id,String.valueOf(sms_frozen_num));
                log.debugf("执行账号短信余额冻结事物");
                Transaction transaction = redisService.multi();
                transaction.decrBy("accpro:sms_remaining:"+unit_id,size);// 短信剩余数量减少
                transaction.incrBy("accpro:sms_frozen_num"+unit_id,size);//短信余额数量增加
                result = transaction.exec();//执行事务
                if(result == null){ //事务提交失败,说明在执行期间数据被修改过
                    log.errorf("执行事物第%s次失败",runNumber);
                    Thread.sleep(500);
                    if(runNumber>5){
                        redisService.unwatch(); // 解除标记
                        flag = false; // 超过5次不在执行
                    }else{
                        runNumber++;
                    }
                }else{
                    //事务提交成功
                    sms_remaining = Integer.parseInt(redisService.get("accpro:sms_remaining:"+unit_id));
                    sms_frozen_num = Integer.parseInt(redisService.get("accpro:sms_frozen_num"+unit_id));
                    accountProduct.setSms_remaining(sms_remaining);
                    accountProduct.setSms_frozen_num(sms_frozen_num);
                    this.updateAccountRedisData(accountProduct);
                    log.debugf("扣费transaction事务执行结束...");
                    log.debugf("当前可用条数:%s,冻结条数:%s",sms_remaining,sms_frozen_num);
                    return Result.success();
                }
            }catch (Exception e){
                redisService.unwatch(); // 解除标记
                log.errorf("冻结条数发生系统异常,单位:%s,冻结条数:%s",unit_id,size);
                log.error(e);
                /**
                 * 其他操作?
                 */
                return Result.error(String.format("冻结条数发生异常,单位:%s,冻结条数:%s",unit_id,size));
            }
        }
        if(!flag){
            log.errorf("执行5次冻结条数失败,单位:%s,冻结条数:%s",unit_id,size);
            /**
             * 其他操作?
             */
            return Result.error(String.format("执行5次冻结条数失败,单位:%s,冻结条数:%s",unit_id,size));
        }
        return Result.error(String.format("冻结条数失败,单位:%s,冻结条数:%s",unit_id,size));
    }
[DEBUG] 2018-08-20 17:10:06,827 org.nutz.dao.impl.interceptor.DaoTimeInterceptor.filter(DaoTimeInterceptor.java:28) - time=7ms, sql=SELECT * FROM sms_tpl  WHERE delFlag=false AND type='0' AND check_status='1' AND unit_id='d7a9ef5cd4914287b1a3cc5438f1b919' ORDER BY create_at DESC, name DESC   LIMIT 0, 10 
[DEBUG] 2018-08-20 17:10:13,374 com.mongodb.diagnostics.logging.SLF4JLogger.debug(SLF4JLogger.java:56) - Checking status of localhost:27017
[DEBUG] 2018-08-20 17:10:13,375 com.mongodb.diagnostics.logging.SLF4JLogger.debug(SLF4JLogger.java:56) - Updating cluster description to  {type=STANDALONE, servers=[{address=localhost:27017, type=STANDALONE, roundTripTime=3.2 ms, state=CONNECTED}]
[DEBUG] 2018-08-20 17:10:16,583 org.apache.zookeeper.ClientCnxn$SendThread.readResponse(ClientCnxn.java:742) - Got ping response for sessionid: 0x16554df55b8000c after 0ms
[DEBUG] 2018-08-20 17:10:23,378 com.mongodb.diagnostics.logging.SLF4JLogger.debug(SLF4JLogger.java:56) - Checking status of localhost:27017
[DEBUG] 2018-08-20 17:10:23,379 com.mongodb.diagnostics.logging.SLF4JLogger.debug(SLF4JLogger.java:56) - Updating cluster description to  {type=STANDALONE, servers=[{address=localhost:27017, type=STANDALONE, roundTripTime=2.8 ms, state=CONNECTED}]
[DEBUG] 2018-08-20 17:10:29,916 org.apache.zookeeper.ClientCnxn$SendThread.readResponse(ClientCnxn.java:742) - Got ping response for sessionid: 0x16554df55b8000c after 1ms
[DEBUG] 2018-08-20 17:10:30,500 com.alibaba.dubbo.remoting.transport.DecodeHandler.decode(DecodeHandler.java:59) -  [DUBBO] Decode decodeable message com.alibaba.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation, dubbo version: 2.6.2, current host: 192.168.3.34
[DEBUG] 2018-08-20 17:10:30,517 com.alibaba.dubbo.remoting.transport.DecodeHandler.decode(DecodeHandler.java:59) -  [DUBBO] Decode decodeable message com.alibaba.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation, dubbo version: 2.6.2, current host: 192.168.3.34
[DEBUG] 2018-08-20 17:10:31,456 cn.wizzer.app.sms.modules.services.impl.SmsSendServiceImpl.synchronizedSendIndustrySms(SmsSendServiceImpl.java:277) - 第1步,手机号参数校验完成,已耗时:0毫秒
[DEBUG] 2018-08-20 17:10:32,783 com.alibaba.dubbo.remoting.exchange.support.header.HeartbeatHandler.received(HeartbeatHandler.java:84) -  [DUBBO] Receive heartbeat response in thread New I/O client worker #1-1, dubbo version: 2.6.2, current host: 192.168.3.34
[DEBUG] 2018-08-20 17:10:32,786 com.alibaba.dubbo.remoting.exchange.support.header.HeartBeatTask.run(HeartBeatTask.java:65) -  [DUBBO] Send heartbeat to remote channel /192.168.3.34:15149, cause: The channel has no data-transmission exceeds a heartbeat period: 60000ms, dubbo version: 2.6.2, current host: 192.168.3.34
[DEBUG] 2018-08-20 17:10:32,795 com.alibaba.dubbo.remoting.transport.DecodeHandler.decode(DecodeHandler.java:59) -  [DUBBO] Decode decodeable message com.alibaba.dubbo.rpc.protocol.dubbo.DecodeableRpcResult, dubbo version: 2.6.2, current host: 192.168.3.34
[DEBUG] 2018-08-20 17:10:32,796 cn.wizzer.app.sms.modules.services.impl.SmsSendServiceImpl.synchronizedSendIndustrySms(SmsSendServiceImpl.java:280) - 第2步,获取单位信息完成,已耗时:1339毫秒
[DEBUG] 2018-08-20 17:10:32,929 cn.wizzer.app.sms.modules.services.impl.SmsSendServiceImpl.synchronizedSendIndustrySms(SmsSendServiceImpl.java:290) - 第3步,检查短信签名和发送频率完成,已耗时:1473毫秒
[DEBUG] 2018-08-20 17:10:32,929 cn.wizzer.app.sms.modules.services.impl.SmsSendServiceImpl.checkMobileLegality(SmsSendServiceImpl.java:743) - checkMobileLegality..1
[DEBUG] 2018-08-20 17:10:32,929 cn.wizzer.app.sms.modules.services.impl.SmsSendServiceImpl.checkMobileLegality(SmsSendServiceImpl.java:755) - checkMobileLegality..3
[DEBUG] 2018-08-20 17:10:32,932 cn.wizzer.app.sms.modules.services.impl.SmsSendServiceImpl.synchronizedSendIndustrySms(SmsSendServiceImpl.java:300) - 第4步,检查手机号码合法性完成,已耗时:1476毫秒
[DEBUG] 2018-08-20 17:10:34,080 com.mongodb.diagnostics.logging.SLF4JLogger.debug(SLF4JLogger.java:56) - Checking status of localhost:27017
[DEBUG] 2018-08-20 17:10:34,082 com.mongodb.diagnostics.logging.SLF4JLogger.debug(SLF4JLogger.java:56) - Updating cluster description to  {type=STANDALONE, servers=[{address=localhost:27017, type=STANDALONE, roundTripTime=2.5 ms, state=CONNECTED}]
[DEBUG] 2018-08-20 17:10:34,145 cn.wizzer.app.sms.modules.services.impl.SmsSendServiceImpl.synchronizedSendIndustrySms(SmsSendServiceImpl.java:324) - 第5步,替换短信模板参数并检测敏感词完成,已耗时:2689毫秒
[DEBUG] 2018-08-20 17:10:34,145 cn.wizzer.app.sms.modules.services.impl.SmsSendServiceImpl.synchronizedSendIndustrySms(SmsSendServiceImpl.java:345) - 第7步,短信发送记录封装完成,已耗时:2689毫秒
[DEBUG] 2018-08-20 17:10:37,514 cn.wizzer.app.sms.modules.services.impl.SmsAccountProductServiceImpl.frozeSmsAccount(SmsAccountProductServiceImpl.java:99) - 执行账号短信余额冻结事物
[ERROR] 2018-08-20 17:10:39,637 cn.wizzer.app.sms.modules.services.impl.SmsAccountProductServiceImpl.frozeSmsAccount(SmsAccountProductServiceImpl.java:126) - 冻结条数发生系统异常,单位:d7a9ef5cd4914287b1a3cc5438f1b919,冻结条数:1
[ERROR] 2018-08-20 17:10:40,649 cn.wizzer.app.sms.modules.services.impl.SmsAccountProductServiceImpl.frozeSmsAccount(SmsAccountProductServiceImpl.java:127) - ERR EXEC without MULTI
redis.clients.jedis.exceptions.JedisDataException: ERR EXEC without MULTI
	at redis.clients.jedis.Protocol.processError(Protocol.java:127)
	at redis.clients.jedis.Protocol.process(Protocol.java:161)
	at redis.clients.jedis.Protocol.read(Protocol.java:215)
	at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)
	at redis.clients.jedis.Connection.getRawObjectMultiBulkReply(Connection.java:285)
	at redis.clients.jedis.Connection.getObjectMultiBulkReply(Connection.java:291)
	at redis.clients.jedis.Transaction.exec(Transaction.java:47)
	at cn.wizzer.app.sms.modules.services.impl.SmsAccountProductServiceImpl.frozeSmsAccount(SmsAccountProductServiceImpl.java:103)
	at cn.wizzer.app.sms.modules.services.impl.SmsAccountProductServiceImpl.changeSmsAccountBalanceChange(SmsAccountProductServiceImpl.java:246)
	at cn.wizzer.app.sms.modules.services.impl.SmsSendServiceImpl.synchronizedSendIndustrySms(SmsSendServiceImpl.java:350)
	at com.alibaba.dubbo.common.bytecode.Wrapper50.invokeMethod(Wrapper50.java)
	at com.alibaba.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:47)
	at com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:76)
	at com.alibaba.dubbo.config.invoker.DelegateProviderMetaDataInvoker.invoke(DelegateProviderMetaDataInvoker.java:52)
	at com.alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:56)
	at com.alibaba.dubbo.rpc.filter.ExceptionFilter.invoke(ExceptionFilter.java:62)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
	at com.alibaba.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:75)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
	at com.alibaba.dubbo.rpc.filter.TimeoutFilter.invoke(TimeoutFilter.java:42)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
	at com.alibaba.dubbo.rpc.protocol.dubbo.filter.TraceFilter.invoke(TraceFilter.java:78)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
	at com.alibaba.dubbo.rpc.filter.ContextFilter.invoke(ContextFilter.java:72)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
	at com.alibaba.dubbo.rpc.filter.GenericFilter.invoke(GenericFilter.java:131)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
	at com.alibaba.dubbo.rpc.filter.ClassLoaderFilter.invoke(ClassLoaderFilter.java:38)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
	at com.alibaba.dubbo.rpc.filter.EchoFilter.invoke(EchoFilter.java:38)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
	at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol$1.reply(DubboProtocol.java:103)
	at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest(HeaderExchangeHandler.java:96)
	at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:172)
	at com.alibaba.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:51)
	at com.alibaba.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:80)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
[DEBUG] 2018-08-20 17:19:38,716 com.alibaba.dubbo.remoting.exchange.support.header.HeartBeatTask.run(HeartBeatTask.java:65) -  [DUBBO] Send heartbeat to remote channel /192.168.3.34:15149, cause: The channel has no data-transmission exceeds a heartbeat period: 60000ms, dubbo version: 2.6.2, current host: 192.168.3.34
[WARN ] 2018-08-20 17:19:38,716 com.alibaba.dubbo.remoting.exchange.support.header.HeartBeatTask.run(HeartBeatTask.java:70) -  [DUBBO] Close channel HeaderExchangeClient [channel=com.alibaba.dubbo.remoting.transport.netty.NettyClient [/192.168.3.34:48075 -> /192.168.3.34:15149]], because heartbeat read idle time out: 180000ms, dubbo version: 2.6.2, current host: 192.168.3.34
[INFO ] 2018-08-20 17:19:38,717 com.alibaba.dubbo.remoting.transport.netty.NettyChannel.close(NettyChannel.java:138) -  [DUBBO] Close netty channel [id: 0x45d64d27, /192.168.3.34:48075 => /192.168.3.34:15149], dubbo version: 2.6.2, current host: 192.168.3.34
[WARN ] 2018-08-20 17:19:38,717 org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1108) - Client session timed out, have not heard from server in 548801ms for sessionid 0x16554df55b8000c
[INFO ] 2018-08-20 17:19:38,718 org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1156) - Client session timed out, have not heard from server in 548801ms for sessionid 0x16554df55b8000c, closing socket connection and attempting reconnect
[DEBUG] 2018-08-20 17:19:38,718 org.apache.zookeeper.ClientCnxnSocketNIO.cleanup(ClientCnxnSocketNIO.java:210) - Ignoring exception during shutdown output
java.net.SocketException: Connection reset by peer: shutdown
	at sun.nio.ch.Net.shutdown(Native Method)
	at sun.nio.ch.SocketChannelImpl.shutdownOutput(SocketChannelImpl.java:801)
	at sun.nio.ch.SocketAdaptor.shutdownOutput(SocketAdaptor.java:407)
	at org.apache.zookeeper.ClientCnxnSocketNIO.cleanup(ClientCnxnSocketNIO.java:207)
	at org.apache.zookeeper.ClientCnxn$SendThread.cleanup(ClientCnxn.java:1246)
	at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1170)
2 回复

redisService不能使用pipeline等所有涉及多操作的方法

ok 我换Jedis 试试。

添加回复
请先登陆
回到顶部