jihuayu commented on issue #1402:
URL: 
https://github.com/apache/incubator-kvrocks/issues/1402#issuecomment-1575519968

   SCAN commond is frequently used in Redis clients.It's important to ensure 
SCAN commond is correct for Redis toolchains to work with Kvrocks. 
   Therefore, I believe this issue needs to be resolved.
   
   After carefully reading the Redis documentation, I found that cursors have 
the following features:
   
   1. The cursor is a 64-bit unsigned integer, with 0 meaning the end of the 
iteration. 
   2. There is no state server side, the full state is captured by the cursor
   3. During the iteration process, a given element may be returned multiple 
times.
   4. As long as the number of elements is not constantly increasing, the 
iteration will eventually end.
   5. Use a corrupted cursor is undefined behavior.
   
   
   Therefore, I think we can use a **ring array** to store the key names for 
the most recently used cursors.
   
   When SCAN end_cursor is "keyname1" we push {key:keyname1,cursor:1276} to 
cursor-ring.
   Next SCAN use cursor 1276, we foreach cursor-ring from the newest item, and 
get the it's key "keyname1". I call this process cursor translation.
   Then we can use "keyname1" to seek rocksdb iterator.
   
   If client call many SCAN command, cursor-ring will be filled and the oldest 
cursor will be discarded.
   Now the if client SCAN use a corrupted cursor(the cursor don't in 
cursor-ring), we will return element from begin.
   
   Based on the above design, we will have the following additional costs.
   
   1. Less than 2KB of memory is used to store the cursor ring.
   2. Each SCAN request requires one cursor translation and one cursor mapping 
save. (Note: Ensuring thread safety is required for cursor mapping save) 
   
   Because SCAN command is a slow command, so the additional cursor translation 
has a minimal impact.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to