redisson icon indicating copy to clipboard operation
redisson copied to clipboard

Major Issue: iterators that uses SCAN/SSCAN/HSCAN command are not using the same node

Open jackygurui opened this issue 11 years ago • 3 comments

Since the fact that keys/Sets/Hashes in redis does not guarantee the order of the elements within, iterators should stick to the same node when iteration was first started, to avoid duplicate and/or missing items.

For example, when you have a Set "A" in master node contains:

  1. "1"
  2. "2"
  3. "3"
  4. "4"
  5. "5"
  6. "6"
  7. "7"
  8. "8"
  9. "9"
  10. "10"
  11. "11"
  12. "12" ...

a slave node could have it in a completely different ordering:

  1. "8"
  2. "2"
  3. "7"
  4. "3"
  5. "9"
  6. "1"
  7. "4"
  8. "6"
  9. "5"
  10. "10"
  11. "11"
  12. "12" ...

Obviously, the running the command SSCAN "A" 0 on master, the result is going to be different to the one from the slave. Further cursor call SSCAN "A" n, could also be different.

The problem is, under the default setting, SentinelConnectionManager uses the RoundRobinBalancer which is utilised to read from both master and slave nodes, and when you have a for loop like this:

for (String i : redisson.<String>getSet("A")) {
    System.out.println(i);
}

The output could contain duplicate/missing item(s), and the results could be different each time you run it.

jackygurui avatar Aug 25 '15 15:08 jackygurui

Hi,

It is perfectly understood the set ordering is not guaranteed, however what it does guarantee are items in a set are unique and during an iteration each item in the set is executed once and once only. 

Due to the characteristics of the way redis slaves replicates a set from their master. The only way to ensure iteration guarantee is to execute it with only one node.

PS: I really admire the work you have done in this project. It is exactly the feature that I was hopping to find when I started to use redis two years ago, and you have made my dream come true. So thank you very much.

--  Rui Gu Sent with Airmail

On 31 August 2015 at 07:35:09, Nikita Koksharov ([email protected]) wrote:

But the set ordering is not guaranteed, you should use list object in that case

— Reply to this email directly or view it on GitHub.

jackygurui avatar Sep 01 '15 09:09 jackygurui

@jackygurui now i catched your idea! will fix it

mrniko avatar Sep 01 '15 13:09 mrniko

fixed. please check

mrniko avatar Sep 04 '15 14:09 mrniko