Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to successfully execute JedisCluster.ftCreate(...) method in Redis Cluster environment #3592

Closed
YaraslauBarysenka opened this issue Oct 19, 2023 · 9 comments
Labels
Milestone

Comments

@YaraslauBarysenka
Copy link

YaraslauBarysenka commented Oct 19, 2023

Expected behavior

Index is created using JedisCluster.ftCreate(...) method in Redis Cluster environment.

Actual behavior

JedisExeption occurs in during index creation in Redis Cluster environment using JedisCluster.
Jedis sends FT.CREATE commands to all Cluster Nodes (3 Masters and 3 Replicas) instead of corresponds single Master Node (IndexName`s hash slot value should be related to this Master Node). As result, 5 commands are failed and only 1 command is successed under Jedis hood.

Example of failed FT.CREATE commands: (error) MOVED 15755 127.0.0.1:7002

Steps to reproduce:

Try to create any Index using JedisCluster like this:
`

     // code example to reproduce the issue
     String IP = "127.0.0.1";

     Set<HostAndPort> nodes = Set.of(
            new HostAndPort(IP, 7000),
            new HostAndPort(IP, 7001),
            new HostAndPort(IP, 7002)
    );
    
    JedisCluster jedis = new JedisCluster(nodes);

    jedis.ftCreate("user-index",
            FTCreateParams.createParams()
                    .on(IndexDataType.JSON)
                    .addPrefix("user:"),
            TextField.of("$.name").as("name"),
            TagField.of("$.city").as("city"),
            NumericField.of("$.age").as("age")
    );

`

Redis / Jedis Configuration

Redis cluster: 3 Masters and 3 Replicas.

Jedis version:

5.0.1

Redis version:

6.2.7

Java version:

17

@C-o-s-m-o-S
Copy link

I have the same issue.

@sazzad16
Copy link
Collaborator

sazzad16 commented Oct 19, 2023

You're using RediSearch Light (assuming from the behavior). This is not the default.

Do the following after creating JedisCluster object.

JedisCluster.setBroadcastAndRoundRobinConfig(new JedisBroadcastAndRoundRobinConfig() {
    @Override public RediSearchMode getRediSearchModeInCluster() { return RediSearchMode.LIGHT; }
});

@YaraslauBarysenka
Copy link
Author

YaraslauBarysenka commented Oct 19, 2023

Thanks @sazzad16 for the quick response.
RediSearchMode.LIGHT setting is not solve the issue. In this case JedisCluster tryes to execute one FT.CREATE command but on random Redis Node and I got an exception:

redis.clients.jedis.exceptions.JedisClusterOperationException: Cluster retry deadline exceeded.
	at redis.clients.jedis.executors.ClusterCommandExecutor.executeCommand(ClusterCommandExecutor.java:124)
	at redis.clients.jedis.UnifiedJedis.executeCommand(UnifiedJedis.java:244)
	at redis.clients.jedis.UnifiedJedis.checkAndBroadcastCommand(UnifiedJedis.java:260)
	at redis.clients.jedis.UnifiedJedis.ftDropIndex(UnifiedJedis.java:3656)
	at com.allot.common.data.redis.dao.test.TestRedis.main(TestRedis.java:204)

Jedis should calculate a proper slot based on IndexName value and execure FT.CREATE command on proper Master Node, not randomly.

I prepared a workaround to solve it locally:
image

Jedis`s implementation of ftCreate method:
image

Jedis should calcuate slot value here, but actually slot value is -1 now:
image

@sazzad16 Please take a look.

@sazzad16
Copy link
Collaborator

@YaraslauBarysenka Could you please check with latest 5.1.0-snapshot?

@sazzad16 sazzad16 added the bug label Oct 19, 2023
@YaraslauBarysenka
Copy link
Author

YaraslauBarysenka commented Oct 19, 2023

@sazzad16

  1. Where can I retrieve the latest 5.1.0-snapshot?
  2. Looks like we dont use RediSearch LIGHT. How to check it? Please suggest some article to read anout it.

@sazzad16
Copy link
Collaborator

@YaraslauBarysenka
Copy link
Author

Looks like it works only since Jedis 5.1.0-snapshot, but is required to set RediSearchMode.LIGHT, otherwise Jedis executes FT.CREATE commands on all Redis Cluster Nodes (all Masters and all Replicas) under the hood and from my point of view it is an issue as well.

@sazzad16 , do we have any cases/opportunitinies where we need (or Redis/RedisSearch allow to do it?) to create the same index on all Redis Cluster Nodes? I don't think so.

@sazzad16
Copy link
Collaborator

@YaraslauBarysenka The default behavior is defined by Redis management.

(Apologies for late reply.)

@sazzad16
Copy link
Collaborator

Resolved by #3593

@sazzad16 sazzad16 added this to the 5.1.0 milestone Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants