Skip to content

Commit

Permalink
Fixed - expired entries eviction process is limited to 5000 per call. #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Koksharov committed Jun 2, 2022
1 parent 8f94d72 commit f116a72
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void run() {
RFuture<Integer> future = execute();
future.whenComplete((size, e) -> {
if (e != null) {
log.error("Unable to evict elements for '" + getName() + "'", e);
schedule();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ RFuture<Integer> execute() {
+ "break;"
+ "end; "
+ "end;"
+ "end;"
+ "if #expiredKeys1 > 0 then "
+ "redis.call('zrem', KEYS[5], unpack(expiredKeys1)); "
+ "redis.call('zrem', KEYS[3], unpack(expiredKeys1)); "
+ "redis.call('zrem', KEYS[2], unpack(expiredKeys1)); "
+ "redis.call('hdel', KEYS[1], unpack(expiredKeys1)); "
+ "end; "
+ "end;"
+ "for i=1, #expiredKeys1, 5000 do "
+ "redis.call('zrem', KEYS[5], unpack(expiredKeys1, i, math.min(i+4999, table.getn(expiredKeys1)))); "
+ "redis.call('zrem', KEYS[3], unpack(expiredKeys1, i, math.min(i+4999, table.getn(expiredKeys1)))); "
+ "redis.call('zrem', KEYS[2], unpack(expiredKeys1, i, math.min(i+4999, table.getn(expiredKeys1)))); "
+ "redis.call('hdel', KEYS[1], unpack(expiredKeys1, i, math.min(i+4999, table.getn(expiredKeys1)))); "
+ "end; "
+ "local expiredKeys2 = redis.call('zrangebyscore', KEYS[3], 0, ARGV[1], 'limit', 0, ARGV[2]); "
+ "for i, key in ipairs(expiredKeys2) do "
+ "local v = redis.call('hget', KEYS[1], key); "
Expand All @@ -90,12 +90,12 @@ RFuture<Integer> execute() {
+ "break;"
+ "end; "
+ "end;"
+ "end;"
+ "if #expiredKeys2 > 0 then "
+ "redis.call('zrem', KEYS[5], unpack(expiredKeys2)); "
+ "redis.call('zrem', KEYS[3], unpack(expiredKeys2)); "
+ "redis.call('zrem', KEYS[2], unpack(expiredKeys2)); "
+ "redis.call('hdel', KEYS[1], unpack(expiredKeys2)); "
+ "end;"
+ "for i=1, #expiredKeys2, 5000 do "
+ "redis.call('zrem', KEYS[5], unpack(expiredKeys2, i, math.min(i+4999, table.getn(expiredKeys2)))); "
+ "redis.call('zrem', KEYS[3], unpack(expiredKeys2, i, math.min(i+4999, table.getn(expiredKeys2)))); "
+ "redis.call('zrem', KEYS[2], unpack(expiredKeys2, i, math.min(i+4999, table.getn(expiredKeys2)))); "
+ "redis.call('hdel', KEYS[1], unpack(expiredKeys2, i, math.min(i+4999, table.getn(expiredKeys2)))); "
+ "end; "
+ "return #expiredKeys1 + #expiredKeys2;",
Arrays.<Object>asList(name, timeoutSetName, maxIdleSetName, expiredChannelName, lastAccessTimeSetName, executeTaskOnceLatchName),
Expand Down

0 comments on commit f116a72

Please sign in to comment.