Fix overflow on 32-bit systems when calculating idle time for eviction (#13804)

the `dictGetSignedIntegerVal` function should be used here,
because in some cases (especially on 32-bit systems) long may
be 4 bytes, and the ttl time saved in expires is a unix timestamp
(millisecond value), which is more than 4 bytes. In this case, we may
not be able to get the correct idle time, which may cause eviction
disorder, in other words, keys that should be evicted later may be
evicted earlier.
This commit is contained in:
luozongle01 2025-02-19 11:01:15 +08:00 committed by GitHub
parent c5f91abaf7
commit b045fe4e17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 1 additions and 1 deletions

View File

@ -162,7 +162,7 @@ int evictionPoolPopulate(redisDb *db, kvstore *samplekvs, struct evictionPoolEnt
idle = 255-LFUDecrAndReturn(o);
} else if (server.maxmemory_policy == MAXMEMORY_VOLATILE_TTL) {
/* In this case the sooner the expire the better. */
idle = ULLONG_MAX - (long)dictGetVal(de);
idle = ULLONG_MAX - dictGetSignedIntegerVal(de);
} else {
serverPanic("Unknown eviction policy in evictionPoolPopulate()");
}