use startEvictionTimeProc() in config set maxmemory (#10019)

This would mean that the effects of `CONFIG SET maxmemory` may not be visible once the command returns.
That could anyway happen since incremental eviction was added in redis 6.2 (see #7653)

We do this to fix one of the propagation bugs about eviction see #9890 and #10014.
This commit is contained in:
zhaozhao.zz 2022-01-04 19:08:10 +08:00 committed by GitHub
parent 87789fae0b
commit 2e1979a21e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 9 deletions

View File

@ -2252,7 +2252,7 @@ static int updateMaxmemory(const char **err) {
if (server.maxmemory < used) {
serverLog(LL_WARNING,"WARNING: the new maxmemory value set via CONFIG SET (%llu) is smaller than the current memory usage (%zu). This will result in key eviction and/or the inability to accept new write commands depending on the maxmemory-policy.", server.maxmemory, used);
}
performEvictions();
startEvictionTimeProc();
}
return 1;
}

View File

@ -466,6 +466,14 @@ static int evictionTimeProc(
return AE_NOMORE;
}
void startEvictionTimeProc(void) {
if (!isEvictionProcRunning) {
isEvictionProcRunning = 1;
aeCreateTimeEvent(server.el, 0,
evictionTimeProc, NULL, NULL);
}
}
/* Check if it's safe to perform evictions.
* Returns 1 if evictions can be performed
* Returns 0 if eviction processing should be skipped
@ -712,11 +720,7 @@ int performEvictions(void) {
* memory, don't want to spend too much time here. */
if (elapsedUs(evictionTimer) > eviction_time_limit_us) {
// We still need to free memory - start eviction timer proc
if (!isEvictionProcRunning) {
isEvictionProcRunning = 1;
aeCreateTimeEvent(server.el, 0,
evictionTimeProc, NULL, NULL);
}
startEvictionTimeProc();
break;
}
}

View File

@ -3044,7 +3044,7 @@ unsigned long LFUDecrAndReturn(robj *o);
#define EVICT_RUNNING 1
#define EVICT_FAIL 2
int performEvictions(void);
void startEvictionTimeProc(void);
/* Keys hashing / comparison functions for dict.c hash tables. */
uint64_t dictSdsHash(const void *key);

View File

@ -174,7 +174,8 @@ tags "modules" {
# Note whenever there's double notification: SET with EX issues two separate
# notifications: one for "set" and one for "expire"
# "config set" should not be here, see https://github.com/redis/redis/issues/10014
# Note that although CONFIG SET maxmemory is called in this flow (see issue #10014),
# eviction will happen and will not induce propagation of the CONFIG command (see #10019).
assert_replication_stream $repl {
{select *}
{multi}
@ -198,7 +199,6 @@ tags "modules" {
{del asdf*}
{incr notifications}
{del asdf*}
{config set maxmemory 1}
{multi}
{incr notifications}
{set asdf4 4}