Skip to content

Rlock Exception in cluster mode #480

Closed
@yuvalamar

Description

@yuvalamar

Hi
I am using redis 3.0.6 (4 node cluster ) and redisson version 2.2.5.
Sometimes when I try lock a key I get the following exceptions:
my code :
String key = String.valueOf("425011000000151"); RLock lc = client.getLock(key); lc.lock(lockTime,TimeUnit.MILLISECONDS); System.out.println("Got key: " + key); lc.unlock();
org.redisson.client.RedisException: ERR Error running script (call to f_93cfc048f82624d1670a310aa0ad58918c0824a5): @user_script:1: WRONGTYPE Operation against a key holding the wrong kind of value . channel: [id: 0x6280a1db, /10.135.50.64:59377 => /10.10.25.183:7002] command: CommandData [promise=DefaultPromise@79d4be49(incomplete), command=(EVAL), params=[if (redis.call('exists', KEYS[1]) == 0) then redis.call('publish', KEYS[2], ARGV[1]); return 1; end;if (redis.call('hexists', KEYS[1], ARGV[3]) == 0) then return nil;end; local counter = redis.call('hincrby', KEYS[1], ARGV[3], -1); if (counter > 0) then redis.call('pexpire', KEYS[1], ARGV[2]); return 0; else redis.call('del', KEYS[1]); redis.call('publish', KEYS[2], ARGV[1]); return 1; end; return nil;, 2, 425011000000151, redisson_lock__channel__{425011000000151}, 0, 30000, 15f636a8-4b5b-4351-9f55-14ade7a2cbd4:359], codec=org.redisson.client.codec.LongCodec@13a20a95]
at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:190)
at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:105)
at io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:370)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:244)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
at java.lang.Thread.run(Thread.java:744)

Activity

mrniko

mrniko commented on Apr 26, 2016

@mrniko
Member

Hi!

Do you use same Redisson version across your system?

mrniko

mrniko commented on Apr 26, 2016

@mrniko
Member

Name conflict with different object could cause this bug too. RLock uses Redis map structure in internals, so if you're trying to use lock with name matches with different object you'll get the same error. Here is the code snippet causes this problem:

        String key = String.valueOf("425011000000151");
        redisson.getBucket(key).set("123");

        RLock lc = redisson.getLock(key); 
        lc.lock(1000,TimeUnit.MILLISECONDS);
yuvalamar

yuvalamar commented on Apr 26, 2016

@yuvalamar
Author

yes the version is 2.2.5

mrniko

mrniko commented on Apr 26, 2016

@mrniko
Member

take a look to my last comment too

yuvalamar

yuvalamar commented on Apr 26, 2016

@yuvalamar
Author

How can I solve this problem?
Should I create new object just for the key?

mrniko

mrniko commented on Apr 26, 2016

@mrniko
Member

I think it's better to find out the place in your system where the another object with same key is created

yuvalamar

yuvalamar commented on Apr 26, 2016

@yuvalamar
Author

Thank you !

mrniko

mrniko commented on Apr 26, 2016

@mrniko
Member

@yuvalamar You're welcome!

ijaychang

ijaychang commented on Aug 15, 2017

@ijaychang

org.redisson.client.RedisException: ERR Error running script (call to f_93cfc048f82624d1670a310aa0ad58918c0824a5): @user_script:1: WRONGTYPE Operation against a key holding the wrong kind of value . channel: [id: 0x2e6767d8, L:/192.168.59.96:62805 - R:/192.168.59.2:6379] command: CommandData [promise=org.redisson.misc.RedissonPromise@22aaca86[Not completed], command=(EVAL), params=[if (redis.call('exists', KEYS[1]) == 0) then redis.call('publish', KEYS[2], ARGV[1]); return 1; end;..., 2, UNIQUE_COUNTER_NORMAL_TRANSFER_SN_LOCK, redisson_lock__channel:{UNIQUE_COUNTER_NORMAL_TRANSFER_SN_LOCK}, 0, 30000, bab9b821-99f3-4ea2-be3a-5579e3b0bd0c:212], codec=org.redisson.client.codec.LongCodec@7dd1507c] I have the same problem,bug I found there is no another object with same key I use

rawatvinod4164

rawatvinod4164 commented on Jan 21, 2020

@rawatvinod4164

I think it's better to find out the place in your system where the another object with same key is created

How Does it solves the problem?

mrniko

mrniko commented on Jan 21, 2020

@mrniko
Member

How Does it solves the problem?

WRONGTYPE Operation against a key holding the wrong kind of value tells that another object by the same key is stored but with different type.

rawatvinod4164

rawatvinod4164 commented on Jan 21, 2020

@rawatvinod4164

I have some value in redis against the provided key. So now when I am executing below code I am getting the error.

RLock rlock = redissonClient.getLock("key");
rlock.lock(); -->Here
System.out.println(redissonClient.getBucket("key").get());
rlock.unlock();

I am getting the error on this line.
So does it means I cannot take lock on keys which already has values inside it?

mrniko

mrniko commented on Jan 21, 2020

@mrniko
Member

lock name should be different you can suffix it: keyName + ":lock"

rawatvinod4164

rawatvinod4164 commented on Jan 21, 2020

@rawatvinod4164

Okay so it takes lock name as unique key which is not present in redis cluster.
Thanks for the same :)

1 remaining item

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mrniko@yuvalamar@ijaychang@rawatvinod4164

        Issue actions

          Rlock Exception in cluster mode · Issue #480 · redisson/redisson